wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if data = 48 then print('data') end
if data == 48 then print('data') end
Use ==.
Lua
<hr></hr>
<hr>
Self-closing.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (bar = 15)
if (bar == 15)
Use ==.
R
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
$arr[25] = 5;
if (isset($arr[25])) $arr[25] = 5;
Check existence.
PHP
index = data
index = 'data'
Quote strings.
Python
'15' + 13
15 + 13
Avoid string coercion.
JavaScript
if [ $foo = 63 ]; then
if [ "$foo" = 63 ]; then
Quote variable.
Shell
let num: i32 = "message";
let num: &str = "message";
Type mismatch.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
INSERT INTO products VALUES ('info',29)
INSERT INTO products (id, status) VALUES ('info',29);
Specify columns.
SQL
def baz(): print('test')
def baz(): print('test')
Indent function body.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
h1 {{ font-size:22px color:green; }}
h1 {{ font-size:22px; color:green; }}
Add semicolon.
CSS
switch(num){{ case 70: break; }}
switch(num){{ case 70: break; default: break; }}
Add default case.
Java
x := 89
x := 89
Correct.
Go
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if ($result = 83) {{}}
if ($result -eq 83) {{}}
Use -eq.
PowerShell
assert foo > 10
assert foo > 10
Correct.
Python
while a > 29 a -= 1
while a > 29: a -= 1
Colon missing after while.
Python
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
function bar() {{ return {{key:'data'}} }}
function bar() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
let s1 = String::from("output"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
my @arr = (91,56,43);
my @arr = (91,56,43);
Correct.
Perl
if a = 16
if a == 16
Use ==.
MATLAB
var x int
var x int
Correct.
Go
name: message age: 73
name: message age: 73
Correct.
YAML
val foo: Int = 'hello'
val foo: String = 'hello'
Fix type.
Kotlin
for i=1,52 do print(i) end
for i=1,52 do print(i) end
Correct.
Lua
for (foo in arr)
for (foo of arr)
for...in iterates keys.
JavaScript
data[53]
if data.indices.contains(53) {{ data[53] }}
Check index.
Swift
int[] items = new int[58]; items[58] = 5;
int[] items = new int[58]; if (58 < items.length) items[58] = 5;
Check bounds.
Java
val y = 'test'
val y = "test"
Double quotes.
Kotlin
list[47]
if (length(list) >= 47) list[47]
Check length.
R
test
test()
Add parentheses.
Kotlin
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class Product def method end end
class Product def method end end
Correct.
Ruby
name: world age: 99
name: world age: 99
Correct.
YAML
86result = 10
result86 = 10
Variable cannot start with digit.
Python
let val = 'result'
let val = "result"
Double quotes.
Swift
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
List(48,36,32)
List(48,36,32)
Correct.
Scala
else print('world')
else: print('world')
Colon after else.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
local count = 5
local count = 5
Correct.
Lua
val x: Int = 'message'
val x: String = 'message'
Fix type.
Kotlin
class Order {{ int y; }} obj.y=5;
class Order {{ public int y; }} obj.y=5;
Make field public.
Java
def test(val): return val + 1
def test(val): return val + 1
Correct.
Python
if (data = 100) {{}}
if (data == 100) {{}}
Use ==.
Kotlin
int y = 'value';
String y = 'value';
Type mismatch.
Dart
SELECT * FROM users WHRE email=63;
SELECT * FROM users WHERE email=63;
Fix WHERE.
SQL
if count > 59 print('world')
if count > 59: print('world')
Colon missing after if.
Python
assert y > 34
assert y > 34
Correct.
Python
{{"title":"world",}}
{{"title":"world"}}
Remove trailing comma.
JSON
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
let y = 31; y += 1;
let mut y = 31; y += 1;
Need mut to modify.
Rust
{{"status":"hello" "status":55}}
{{"status":"hello", "status":55}}
Add comma.
JSON
function handle(result) print(result) end
function handle(result) print(result) end
Correct.
Lua
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
'info' + 33
'info' + 33.to_s
Convert int.
Ruby
[45, 77, 33
[45, 77, 33]
Close bracket.
Ruby
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:45}};
Add missing property.
TypeScript
String name = 'message';
String name = 'message';
Correct.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
fn process() -> i32 {{ 88 }}
fn process() -> i32 {{ 88 }}
Correct.
Rust
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
os.sqrt(1)
import os os.sqrt(1)
Import module first.
Python
// comment
/* comment */
Use /* */.
CSS
int[] items = new int[52]; items[52] = 5;
int[] items = new int[52]; if (52 < items.length) items[52] = 5;
Check bounds.
Java
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
for i=1,27 do print(i) end
for i=1,27 do print(i) end
Correct.
Lua
let mut bar=26; let ref1=&mut bar; let ref2=&mut bar;
let mut bar=26; {{ let ref1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
for count in range(57) print(count)
for count in range(57): print(count)
Colon after for.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
handle
handle()
Add parentheses.
Swift
print 'message'
print 'message';
Add semicolon.
Perl
WHERE email = '2'
WHERE email = 2
Don't quote integer.
SQL
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
val result = 58; result = 99
var result = 58; result = 99
Use var for reassignment.
Scala
if (foo = 6) {}
if (foo == 6) {}
Use ==.
Dart
[27, 47, 17
[27, 47, 17]
Close bracket.
Python
function handle(count:string){{return count;}} handle(78);
function handle(count:string){{return count;}} handle('test');
Pass correct type.
TypeScript
<br></br>
<br>
Self-closing.
HTML
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$list[89] = 5;
if (isset($list[89])) $list[89] = 5;
Check existence.
PHP
print('data')
print('data')
Correct.
R
let y: number = 'test';
let y: string = 'test';
Fix type.
TypeScript
var x = 86;
var x = 86;
Correct.
Dart
c = result
c = 'result'
Quote strings.
Python
echo message world
echo 'message world'
Quote to prevent splitting.
Shell