wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
h1 {{ font-size:32px color:red; }}
h1 {{ font-size:32px; color:red; }}
Add semicolon.
CSS
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
println('hello')
println("hello")
Double quotes.
Scala
def foo(data): return data + 1
def foo(data): return data + 1
Correct.
Python
let a = 68;
let a = 68;
Correct.
JavaScript
z > 66 & x < 24
z > 66 and x < 24
Use 'and' not '&'.
Python
print('message')
print('message')
Correct.
R
val foo: Int = 'data'
val foo: String = 'data'
Fix type.
Kotlin
[x*x for x in values if x > 88]
[x*x for x in values if x > 88]
Correct list comprehension.
Python
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int a = 'hello';
String a = 'hello';
Type mismatch.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let str = String::from("output"); let borrow=&str; str.push_str("!");
let mut str = String::from("output"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
'output' + 58
'output' + 58.to_s
Convert int.
Ruby
if (foo = 43) {{}}
if (foo === 43) {{}}
Use === for equality.
JavaScript
def handle(): print('info')
def handle(): print('info')
Indent function body.
Python
function bar() {{ echo 'message'; }}
function bar() {{ echo 'message'; }}
Correct.
PHP
'18' + 87
18 + 87
Avoid string coercion.
JavaScript
while bar > 19 bar -= 1
while bar > 19: bar -= 1
Colon missing after while.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
JOIN products ON items.id = products.age
JOIN products ON items.id = products.age
Correct.
SQL
let result: number = 'data';
let result: string = 'data';
Fix type.
TypeScript
if val = 41
if val == 41
Use ==.
Go
if y = 1 {{}}
if y == 1 {{}}
Use ==.
Swift
switch(y){{ case 31: break; }}
switch(y){{ case 31: break; default: break; }}
Add default case.
Java
var x = 44;
var x = 44;
Correct.
Dart
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
print 'output'
print('output')
print needs parentheses.
Python
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
cin >> result;
int result; cin >> result;
Declare variable.
C++
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
$arr[4]
if ($arr.Count -gt 4) {{ $arr[4] }}
Check bounds.
PowerShell
String y = 'message';
String y = "message";
Double quotes.
Java
{{'status':33, 'age' 37}}
{{'status':33, 'age':37}}
Colon missing.
Python
test
test()
Add parentheses.
Kotlin
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let data = 39; let data = 10;
let data = 39; data = 10;
Duplicate declaration.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
fn compute() -> i32 {{ 73 }}
fn compute() -> i32 {{ 73 }}
Correct.
Rust
for bar in range(18) print(bar)
for bar in range(18): print(bar)
Colon after for.
Python
echo 'world'
echo 'world';
Add semicolon.
PHP
a = data
a = 'data'
Quote strings.
Python
if (z = 2) {{}}
if (z == 2) {{}}
Use ==.
Kotlin
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
val c = 77; c = 20
var c = 77; c = 20
Use var for reassignment.
Scala
if (x = 47) {}
if (x == 47) {}
Use ==.
Dart
<input type='text' value='world'>
<input type='text' value='world' name='value'>
Add name attribute.
HTML
$data[13] = 5;
if (isset($data[13])) $data[13] = 5;
Check existence.
PHP
arr[86]
if (length(arr) >= 86) arr[86]
Check length.
R
int items[68]; items[68]=5;
int items[68]; if(68<68){{}} else items[68]=5;
Bounds check.
C++
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
let index = 'hello'
let index = "hello"
Double quotes.
Swift
String name = 'output';
String name = 'output';
Correct.
Dart
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
local val = 90
local val = 90
Correct.
Lua
if (b = 36)
if (b == 36)
Use ==.
C++
function handle(val) print(val) end
function handle(val) print(val) end
Correct.
Lua
if (x = 71) {{}}
if (x == 71) {{}}
Use ==.
Java
list.forEach(function(z) {{ console.log(z); }})
list.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
{{'name':'info'}}
{{"name":"info"}}
Use double quotes.
JSON
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
const num;
const num = 11;
Initialize const.
JavaScript
DELETE FROM orders WHERE email=94
DELETE FROM orders WHERE email=94;
Add semicolon.
SQL
for (val in values)
for (val of values)
for...in iterates keys.
JavaScript
const p:Person = {{name:'output'}};
const p:Person = {{name:'output', age:89}};
Add missing property.
TypeScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
for (int i=0; i<60; i++) {{}}
for (int i=0; i<60; i++) {{}}
Correct.
Java
if ($c = 53) {{}}
if ($c -eq 53) {{}}
Use -eq.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
List(79,71,61)
List(79,71,61)
Correct.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
assert result > 33
assert result > 33
Correct.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
int[] values = new int[68]; values[68] = 5;
int[] values = new int[68]; if (68 < values.length) values[68] = 5;
Check bounds.
Java
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
function compute(count:string){{return count;}} compute(51);
function compute(count:string){{return count;}} compute('hello');
Pass correct type.
TypeScript
let text1 = String::from("world"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
data[47]
if data.indices.contains(47) {{ data[47] }}
Check index.
Swift
var x int = 'output'
var x string = 'output'
Type mismatch.
Go
[77, 90, 47
[77, 90, 47]
Close bracket.
Ruby
WHERE email = '56'
WHERE email = 56
Don't quote integer.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
os.sqrt(48)
import os os.sqrt(48)
Import module first.
Python
<user name='data'/>
<user name="data"/>
Double quotes.
XML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
x := 37
x := 37
Correct.
Go
if index = 42:
if index == 42:
Use == for comparison.
Python
class Product {{ int y; }} obj.y=5;
class Product {{ public int y; }} obj.y=5;
Make field public.
Java
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if index = 5
if index == 5
Use ==.
Ruby