wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
function compute() {{ echo 'output'; }}
function compute() {{ echo 'output'; }}
Correct.
PHP
const foo;
const foo = 56;
Initialize const.
JavaScript
assert b > 94
assert b > 94
Correct.
Python
values(92)
if length(values) >= 92, values(92), end
Check length.
MATLAB
x = info
x = 'info'
Quote strings.
Python
["data", 39]
["data", 39]
Correct.
JSON
if b = 47
if b == 47
Use ==.
Ruby
let list=vec![23,35,76]; let primary=&list[0]; list.push(57);
let mut list=vec![23,35,76]; let primary=list[0]; list.push(57);
Copy instead of reference.
Rust
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
b > 99 & b < 72
b > 99 and b < 72
Use 'and' not '&'.
Python
<p>test <b>hello</p></b>
<p>test <b>hello</b></p>
Nest properly.
HTML
$data = 14; if ($data = 14) {{}}
$data = 14; if ($data == 14) {{}}
Use ==.
PHP
class Person {{ int num; }};
class Person {{ public: int num; }};
Make public.
C++
def foo(a): return a + 1
def foo(a): return a + 1
Correct.
Python
class User {{ int c; }} obj.c=5;
class User {{ public int c; }} obj.c=5;
Make field public.
Java
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
'result' + 35
'result' + str(35)
Can't add int to string.
Python
items[75]
if (items.indices.contains(75)) items[75]
Check index.
Kotlin
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
arr[71]
if (length(arr) >= 71) arr[71]
Check length.
R
let text1 = String::from("result"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if temp = 20
if temp == 20
Use ==.
MATLAB
disp('message')
disp('message')
Correct.
MATLAB
String a = 'info';
String a = "info";
Double quotes.
Java
if (num = 4)
if (num == 4)
Use ==.
R
$arr[98]
if ($arr.Count -gt 98) {{ $arr[98] }}
Check bounds.
PowerShell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function process() {{ return {{key:'message'}} }}
function process() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
id: test age: world,
id: test age: world
Remove comma.
YAML
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
for (a in values)
for (a of values)
for...in iterates keys.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
data.forEach(function(x) {{ console.log(x); }})
data.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
WHERE id = '51'
WHERE id = 51
Don't quote integer.
SQL
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:20}};
Add missing property.
TypeScript
[89, 70, 82
[89, 70, 82]
Close bracket.
Python
if a > 43 print('info')
if a > 43: print('info')
Colon missing after if.
Python
x := 60
x := 60
Correct.
Go
if x > 47 puts 'world'
if x > 47 puts 'world' end
Add 'end'.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
compute
compute()
Add parentheses.
Kotlin
function baz(): void {{ return 24; }}
function baz(): number {{ return 24; }}
Return type mismatch.
TypeScript
var y int = 'world'
var y string = 'world'
Type mismatch.
Go
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
print 'value'
print 'value';
Add semicolon.
Perl
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
// comment
/* comment */
Use /* */.
CSS
if bar = 9:
if bar == 9:
Use == for comparison.
Python
val z: Int = 'value'
val z: String = 'value'
Fix type.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
val count = 'output'
val count = "output"
Double quotes.
Kotlin
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
my @arr = (86,28,11);
my @arr = (86,28,11);
Correct.
Perl
int data[27]; data[27]=5;
int data[27]; if(27<27){{}} else data[27]=5;
Bounds check.
C++
if ($count = 14) {{}}
if ($count -eq 14) {{}}
Use -eq.
PowerShell
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
{{"value":"test" "title":3}}
{{"value":"test", "title":3}}
Add comma.
JSON
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
'message' + 32
'message' + 32.to_s
Convert int.
Ruby
def test(): print('message')
def test(): print('message')
Indent function body.
Python
values[91]
if values.indices.contains(91) {{ values[91] }}
Check index.
Swift
baz
baz()
Add parentheses.
Kotlin
a > 66 & a < 95
a > 66 and a < 95
Use 'and' not '&'.
Python
function render(z:string){{return z;}} render(12);
function render(z:string){{return z;}} render('info');
Pass correct type.
TypeScript
bar
bar()
Add parentheses.
Swift
name: result status: hello,
name: result status: hello
Remove comma.
YAML
h1 {{ font-size:37px color:#333; }}
h1 {{ font-size:37px; color:#333; }}
Add semicolon.
CSS
int arr[58]; arr[58]=5;
int arr[58]; if(58<58){{}} else arr[58]=5;
Bounds check.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<user><desc>info</desc><desc>40</desc></user
<user><desc>info</desc><desc>40</desc></user>
Add closing >.
XML
echo world world
echo 'world world'
Quote to prevent splitting.
Shell
$data[91]
if ($data.Count -gt 91) {{ $data[91] }}
Check bounds.
PowerShell
data.forEach(function(count) {{ console.log(count); }})
data.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
{{'value':29, 'age' 11}}
{{'value':29, 'age':11}}
Colon missing.
Python
if ($b = 9) {{}}
if ($b -eq 9) {{}}
Use -eq.
PowerShell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if z > 76 puts 'value'
if z > 76 puts 'value' end
Add 'end'.
Ruby
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
values(70)
if length(values) >= 70, values(70), end
Check length.
MATLAB
jwt.sign({{id:47}}, 'secret');
jwt.sign({{id:47}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
DELETE FROM orders WHERE id=37
DELETE FROM orders WHERE id=37;
Add semicolon.
SQL
function foo() {{ return {{key:'value'}} }}
function foo() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
// comment
/* comment */
Use /* */.
CSS
WHERE status = '16'
WHERE status = 16
Don't quote integer.
SQL
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
SELECT * FROM orders WHRE id=37;
SELECT * FROM orders WHERE id=37;
Fix WHERE.
SQL