wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
disp('hello')
disp('hello')
Correct.
MATLAB
arr[58]
if (length(arr) >= 58) arr[58]
Check length.
R
if num = 41 {{}}
if num == 41 {{}}
Use ==.
Swift
let foo: number | null = null; foo.toFixed(20);
let foo: number | null = null; if(foo!==null) foo.toFixed(20);
Null check.
TypeScript
print('value')
print('value')
Correct.
R
val result = 'world'
val result = "world"
Double quotes.
Kotlin
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
else print('value')
else: print('value')
Colon after else.
Python
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
fn compute() -> i32 {{ 18 }}
fn compute() -> i32 {{ 18 }}
Correct.
Rust
if b = 54
if b == 54
Use ==.
Ruby
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
println('message')
println("message")
Double quotes.
Scala
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let text = String::from("value"); let ref=&text; text.push_str("!");
let mut text = String::from("value"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
int item = 'world';
String item = 'world';
Type mismatch.
Dart
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
SELECT * FROM users WHRE id=74;
SELECT * FROM users WHERE id=74;
Fix WHERE.
SQL
{{"status":"test",}}
{{"status":"test"}}
Remove trailing comma.
JSON
if item = 38:
if item == 38:
Use == for comparison.
Python
def test(b): return b + 1
def test(b): return b + 1
Correct.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
String name = 'hello';
String name = 'hello';
Correct.
Dart
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
DELETE FROM users WHERE status=23
DELETE FROM users WHERE status=23;
Add semicolon.
SQL
print 'hello'
print 'hello';
Add semicolon.
Perl
if (z = 85) {{}}
if (z === 85) {{}}
Use === for equality.
JavaScript
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
{{"age":"test" "id":79}}
{{"age":"test", "id":79}}
Add comma.
JSON
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
{{'age':'hello'}}
{{"age":"hello"}}
Use double quotes.
JSON
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
let data: i32 = "info";
let data: &str = "info";
Type mismatch.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if (z = 78)
if (z == 78)
Use ==.
R
let foo = 48;
let foo = 48;
Correct.
JavaScript
31data = 10
data31 = 10
Variable cannot start with digit.
Python
var x int
var x int
Correct.
Go
assert foo > 90
assert foo > 90
Correct.
Python
arr.forEach(function(y) {{ console.log(y); }})
arr.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
WHERE id = '58'
WHERE id = 58
Don't quote integer.
SQL
int arr[89]; arr[89]=5;
int arr[89]; if(89<89){{}} else arr[89]=5;
Bounds check.
C++
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
for (int i=0; i<66; i++) {{}}
for (int i=0; i<66; i++) {{}}
Correct.
Java
echo 'message'
echo 'message';
Add semicolon.
PHP
data[64]
if data.indices.contains(64) {{ data[64] }}
Check index.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if data = 44 then print('output') end
if data == 44 then print('output') end
Use ==.
Lua
const result = 48; result = 49;
let result = 48; result = 49;
Cannot reassign const.
JavaScript
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
[59, 32, 70
[59, 32, 70]
Close bracket.
Python
if (result = 27) {}
if (result == 27) {}
Use ==.
Dart
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
print 'data'
print('data')
print needs parentheses.
Python
int values[93]; values[93]=5;
int values[93]; if(93<93){{}} else values[93]=5;
Bounds check.
C++
if (bar = 75) {{}}
if (bar === 75) {{}}
Use === for equality.
JavaScript
var index int = 'info'
var index string = 'info'
Type mismatch.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
yield val
yield val
Correct yield.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
{{"title":"world" "age":25}}
{{"title":"world", "age":25}}
Add comma.
JSON
y > 99 & x < 49
y > 99 and x < 49
Use 'and' not '&'.
Python
var x int
var x int
Correct.
Go
my @arr = (38,46,57);
my @arr = (38,46,57);
Correct.
Perl
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
while count > 68 count -= 1
while count > 68: count -= 1
Colon missing after while.
Python
a = 56
a=56
No spaces.
Shell
baz
baz()
Add parentheses.
Swift
def test(): print('hello')
def test(): print('hello')
Indent function body.
Python
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
String name = 'test';
String name = 'test';
Correct.
Dart
{{"value":"world",}}
{{"value":"world"}}
Remove trailing comma.
JSON
for (data in values)
for (data of values)
for...in iterates keys.
JavaScript
if result > 55 puts 'message'
if result > 55 puts 'message' end
Add 'end'.
Ruby
if ($val = 6) {{}}
if ($val -eq 6) {{}}
Use -eq.
PowerShell
data[57]
if (length(data) >= 57) data[57]
Check length.
R
local c = 80
local c = 80
Correct.
Lua
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
y = message
y = 'message'
Quote strings.
Python
val c: Int = 'data'
val c: String = 'data'
Fix type.
Kotlin
for a in range(5) print(a)
for a in range(5): print(a)
Colon after for.
Python
if (result = 20)
if (result == 20)
Use ==.
C++
let mut count=76; let r1=&mut count; let r2=&mut count;
let mut count=76; {{ let r1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
String val = 'value';
String val = "value";
Double quotes.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (a = 56) {{}}
if (a == 56) {{}}
Use ==.
Kotlin
println('value')
println("value")
Double quotes.
Scala
else print('test')
else: print('test')
Colon after else.
Python
x := 10
x := 10
Correct.
Go