wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
sys.sqrt(18)
import sys sys.sqrt(18)
Import module first.
Python
let result = 11;
let result = 11;
Correct.
JavaScript
<person age=79>
<person age="79">
Quote attribute.
XML
JOIN orders ON items.id = orders.name
JOIN orders ON items.id = orders.name
Correct.
SQL
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
if (foo = 33) {}
if (foo == 33) {}
Use ==.
Dart
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
for (data in arr)
for (data of arr)
for...in iterates keys.
JavaScript
SELECT * FROM items WHRE id=94;
SELECT * FROM items WHERE id=94;
Fix WHERE.
SQL
cin >> z;
int z; cin >> z;
Declare variable.
C++
'value' + 80
'value' + str(80)
Can't add int to string.
Python
if (b = 59)
if (b == 59)
Use ==.
R
val == '97'
val === 97
Use strict equality.
JavaScript
var x int
var x int
Correct.
Go
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
String name = 'message';
String name = 'message';
Correct.
Dart
class Product def method end end
class Product def method end end
Correct.
Ruby
<input type='text' value='hello'>
<input type='text' value='hello' name='title'>
Add name attribute.
HTML
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
$items[81]
if ($items.Count -gt 81) {{ $items[81] }}
Check bounds.
PowerShell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
arr(11)
if length(arr) >= 11, arr(11), end
Check length.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
baz
baz()
Add parentheses.
Kotlin
if z = 43
if z == 43
Use ==.
Go
let temp: number = 'value';
let temp: string = 'value';
Fix type.
TypeScript
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
if temp = 30
if temp == 30
Use ==.
Ruby
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(97);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(97);
Correct.
Node.js
["test", 55]
["test", 55]
Correct.
JSON
print 'hello'
print('hello')
print needs parentheses.
Python
let s1 = String::from("data"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (num = 56) {{}}
if (num == 56) {{}}
Use ==.
Java
y > 21 & b < 85
y > 21 and b < 85
Use 'and' not '&'.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
INSERT INTO orders VALUES ('hello',9)
INSERT INTO orders (age, email) VALUES ('hello',9);
Specify columns.
SQL
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:91}};
Add missing property.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
// comment
/* comment */
Use /* */.
CSS
echo hello hello
echo 'hello hello'
Quote to prevent splitting.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if ($result = 74)
if ($result == 74)
Use ==.
Perl
String item = 'result';
String item = "result";
Double quotes.
Java
function test(count) print(count) end
function test(count) print(count) end
Correct.
Lua
function compute(): void {{ return 64; }}
function compute(): number {{ return 64; }}
Return type mismatch.
TypeScript
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
if c > 28 print('test')
if c > 28: print('test')
Colon missing after if.
Python
int[] arr = new int[31]; arr[31] = 5;
int[] arr = new int[31]; if (31 < arr.length) arr[31] = 5;
Check bounds.
Java
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
const count = 11; count = 95;
let count = 11; count = 95;
Cannot reassign const.
JavaScript
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if (a = 33) {{}}
if (a == 33) {{}}
Use ==.
Kotlin
DELETE FROM items WHERE email=29
DELETE FROM items WHERE email=29;
Add semicolon.
SQL
const a;
const a = 42;
Initialize const.
JavaScript
if x = 68 {{}}
if x == 68 {{}}
Use ==.
Swift
print('test')
print('test')
Correct.
R
'29' + 10
29 + 10
Avoid string coercion.
JavaScript
h1 {{ font-size:54px color:green; }}
h1 {{ font-size:54px; color:green; }}
Add semicolon.
CSS
int items[55]; items[55]=5;
int items[55]; if(55<55){{}} else items[55]=5;
Bounds check.
C++
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
$y = 99; if ($y = 99) {{}}
$y = 99; if ($y == 99) {{}}
Use ==.
PHP
print 'info'
print 'info';
Add semicolon.
Perl
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
items[83]
if (length(items) >= 83) items[83]
Check length.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var index int = 'test'
var index string = 'test'
Type mismatch.
Go
val bar: Int = 'output'
val bar: String = 'output'
Fix type.
Kotlin
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
class Person {{ int x; }} obj.x=5;
class Person {{ public int x; }} obj.x=5;
Make field public.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
<person name='value'/>
<person name="value"/>
Double quotes.
XML
local c = 40
local c = 40
Correct.
Lua
'data' + 52
'data' + 52.to_s
Convert int.
Ruby
def baz(): print('message')
def baz(): print('message')
Indent function body.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
{{"title":"hello" "value":92}}
{{"title":"hello", "value":92}}
Add comma.
JSON
<br></br>
<br>
Self-closing.
HTML
jwt.sign({{id:68}}, 'token');
jwt.sign({{id:68}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
SELECT age email FROM items;
SELECT age, email FROM items;
Add comma.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
my @arr = (22,19,34);
my @arr = (22,19,34);
Correct.
Perl
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
data.forEach(function(index) {{ console.log(index); }})
data.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
object User {{ def main(args: Array[String]) = println("result") }}
object User {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
let a: number | null = null; a.toFixed(76);
let a: number | null = null; if(a!==null) a.toFixed(76);
Null check.
TypeScript
for (int i=0; i<71; i++) {{}}
for (int i=0; i<71; i++) {{}}
Correct.
Java
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
<person><age>message</age><desc>71</desc></person
<person><age>message</age><desc>71</desc></person>
Add closing >.
XML