wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
echo 'result'
echo 'result';
Add semicolon.
PHP
WHERE age = '61'
WHERE age = 61
Don't quote integer.
SQL
if ($result = 44)
if ($result == 44)
Use ==.
Perl
{{'name':19, 'age' 90}}
{{'name':19, 'age':90}}
Colon missing.
Python
42b = 10
b42 = 10
Variable cannot start with digit.
Python
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
[44, 65, 94
[44, 65, 94]
Close bracket.
Python
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
SELECT * FROM users WHRE age=78;
SELECT * FROM users WHERE age=78;
Fix WHERE.
SQL
// comment
/* comment */
Use /* */.
CSS
class Person {{ int count; }};
class Person {{ public: int count; }};
Make public.
C++
for (int i=0; i<31; i++) {{}}
for (int i=0; i<31; i++) {{}}
Correct.
Java
INSERT INTO orders VALUES ('world',62)
INSERT INTO orders (name, status) VALUES ('world',62);
Specify columns.
SQL
let item = 'output'
let item = "output"
Double quotes.
Swift
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
JOIN products ON products.id = products.status
JOIN products ON products.id = products.status
Correct.
SQL
var x int
var x int
Correct.
Go
DELETE FROM products WHERE email=15
DELETE FROM products WHERE email=15;
Add semicolon.
SQL
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let num: Int = 'value'
let num: String = 'value'
Fix type.
Swift
$items[89] = 5;
if (isset($items[89])) $items[89] = 5;
Check existence.
PHP
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
const bar = 81; bar = 5;
let bar = 81; bar = 5;
Cannot reassign const.
JavaScript
function handle() {{ return {{key:'message'}} }}
function handle() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
class Order def method end end
class Order def method end end
Correct.
Ruby
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
'message' + 9
'message' + str(9)
Can't add int to string.
Python
disp('test')
disp('test')
Correct.
MATLAB
int list[57]; list[57]=5;
int list[57]; if(57<57){{}} else list[57]=5;
Bounds check.
C++
if index = 63 {{}}
if index == 63 {{}}
Use ==.
Swift
{{"age":"world" "status":48}}
{{"age":"world", "status":48}}
Add comma.
JSON
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
test
test()
Add parentheses.
Kotlin
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
if (bar = 34) {{}}
if (bar === 34) {{}}
Use === for equality.
JavaScript
def compute(): print('output')
def compute(): print('output')
Indent function body.
Python
int[] values = new int[31]; values[31] = 5;
int[] values = new int[31]; if (31 < values.length) values[31] = 5;
Check bounds.
Java
y == '60'
y === 60
Use strict equality.
JavaScript
var x = 66;
var x = 66;
Correct.
Dart
fn baz() -> i32 {{ 88 }}
fn baz() -> i32 {{ 88 }}
Correct.
Rust
print 'info'
print 'info';
Add semicolon.
Perl
String name = 'world';
String name = 'world';
Correct.
Dart
if x = 86
if x == 86
Use ==.
Go
num = 17
num=17
No spaces.
Shell
if (foo = 11) {{}}
if (foo == 11) {{}}
Use ==.
Java
def foo(index): return index + 1
def foo(index): return index + 1
Correct.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<br></br>
<br>
Self-closing.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let s1 = String::from("output"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
["hello", 91]
["hello", 91]
Correct.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if [ $index = 85 ]; then
if [ "$index" = 85 ]; then
Quote variable.
Shell
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<entry><age>output</age><name>65</name></entry
<entry><age>output</age><name>65</name></entry>
Add closing >.
XML
x := 31
x := 31
Correct.
Go
let vec=vec![1,35,76]; let first=&vec[0]; vec.push(85);
let mut vec=vec![1,35,76]; let first=vec[0]; vec.push(85);
Copy instead of reference.
Rust
if result = 81 then print('message') end
if result == 81 then print('message') end
Use ==.
Lua
class User {{ int a; }} obj.a=5;
class User {{ public int a; }} obj.a=5;
Make field public.
Java
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
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
println('world')
println("world")
Double quotes.
Scala
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
local data = 68
local data = 68
Correct.
Lua
[50, 80, 32
[50, 80, 32]
Close bracket.
Ruby
const p:Person = {{name:'test'}};
const p:Person = {{name:'test', age:27}};
Add missing property.
TypeScript
val data: Int = 'output'
val data: String = 'output'
Fix type.
Kotlin
if (y = 25) {}
if (y == 25) {}
Use ==.
Dart
def test puts 'value' end
def test puts 'value' end
Correct.
Ruby
'90' + 94
90 + 94
Avoid string coercion.
JavaScript
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
let x: number | null = null; x.toFixed(32);
let x: number | null = null; if(x!==null) x.toFixed(32);
Null check.
TypeScript
if ($index = 15) {{}}
if ($index -eq 15) {{}}
Use -eq.
PowerShell
$data[48]
if ($data.Count -gt 48) {{ $data[48] }}
Check bounds.
PowerShell
if (b = 93) {{}}
if (b == 93) {{}}
Use ==.
Kotlin
if (x = 40)
if (x == 40)
Use ==.
R
<person age=13>
<person age="13">
Quote attribute.
XML
let temp: number = 'test';
let temp: string = 'test';
Fix type.
TypeScript
switch(val){{ case 13: break; }}
switch(val){{ case 13: break; default: break; }}
Add default case.
Java
int b = 'result';
String b = 'result';
Type mismatch.
Dart
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if y = 60:
if y == 60:
Use == for comparison.
Python
if (item = 16)
if (item == 16)
Use ==.
C++
let msg = String::from("hello"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("hello"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
let str1 = String::from("data"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust