wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if data > 6 puts 'info'
if data > 6 puts 'info' end
Add 'end'.
Ruby
<user name='output'/>
<user name="output"/>
Double quotes.
XML
if (count = 20) {}
if (count == 20) {}
Use ==.
Dart
let item: i32 = "world";
let item: &str = "world";
Type mismatch.
Rust
$items[81]
if ($items.Count -gt 81) {{ $items[81] }}
Check bounds.
PowerShell
String name = 'value';
String name = 'value';
Correct.
Dart
int x = 'message';
String x = 'message';
Type mismatch.
Dart
if y > 43 print('hello')
if y > 43: print('hello')
Colon missing after if.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
31temp = 10
temp31 = 10
Variable cannot start with digit.
Python
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
if (item = 23) {{}}
if (item === 23) {{}}
Use === for equality.
JavaScript
print 'result'
print 'result';
Add semicolon.
Perl
if a = 29:
if a == 29:
Use == for comparison.
Python
WHERE id = '8'
WHERE id = 8
Don't quote integer.
SQL
for z in range(76) print(z)
for z in range(76): print(z)
Colon after for.
Python
let text = String::from("message"); let ref=&text; text.push_str("!");
let mut text = String::from("message"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
arr.forEach(function(c) {{ console.log(c); }})
arr.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
cin >> z;
int z; cin >> z;
Declare variable.
C++
DELETE FROM items WHERE email=95
DELETE FROM items WHERE email=95;
Add semicolon.
SQL
my @arr = (15,81,34);
my @arr = (15,81,34);
Correct.
Perl
title: test id: world,
title: test id: world
Remove comma.
YAML
foo = world
foo = 'world'
Quote strings.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
switch(bar){{ case 97: break; }}
switch(bar){{ case 97: break; default: break; }}
Add default case.
Java
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
String x = 'output';
String x = "output";
Double quotes.
Java
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if ($num = 26) {{}}
if ($num -eq 26) {{}}
Use -eq.
PowerShell
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
h1 {{ font-size:8px color:green; }}
h1 {{ font-size:8px; color:green; }}
Add semicolon.
CSS
{{'age':2, 'name' 36}}
{{'age':2, 'name':36}}
Colon missing.
Python
var a int = 'hello'
var a string = 'hello'
Type mismatch.
Go
if result = 87
if result == 87
Use ==.
Go
else print('test')
else: print('test')
Colon after else.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<br></br>
<br>
Self-closing.
HTML
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:21}};
Add missing property.
TypeScript
int[] items = new int[74]; items[74] = 5;
int[] items = new int[74]; if (74 < items.length) items[74] = 5;
Check bounds.
Java
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
class Person {{ int result; }} obj.result=5;
class Person {{ public int result; }} obj.result=5;
Make field public.
Java
println('test')
println("test")
Double quotes.
Scala
var x = 25;
var x = 25;
Correct.
Dart
yield z
yield z
Correct yield.
Python
const temp;
const temp = 2;
Initialize const.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
while index > 41 index -= 1
while index > 41: index -= 1
Colon missing after while.
Python
baz
baz()
Add parentheses.
Swift
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
[x*x for x in arr if x > 35]
[x*x for x in arr if x > 35]
Correct list comprehension.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
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
y > 58 & y < 51
y > 58 and y < 51
Use 'and' not '&'.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
assert x > 12
assert x > 12
Correct.
Python
name: output status: hello,
name: output status: hello
Remove comma.
YAML
<p>world <b>test</p></b>
<p>world <b>test</b></p>
Nest properly.
HTML
{{"status":"world",}}
{{"status":"world"}}
Remove trailing comma.
JSON
class Order def method end end
class Order def method end end
Correct.
Ruby
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
x = world
x = 'world'
Quote strings.
Python
[55, 22, 49
[55, 22, 49]
Close bracket.
Ruby
if b = 12 {{}}
if b == 12 {{}}
Use ==.
Swift
int count = 'world';
String count = 'world';
Type mismatch.
Dart
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (val = 99)
if (val == 99)
Use ==.
R
let index = 'result'
let index = "result"
Double quotes.
Swift
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
if result = 8:
if result == 8:
Use == for comparison.
Python
print 'world'
print('world')
print needs parentheses.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
test
test()
Add parentheses.
Swift
WHERE name = '97'
WHERE name = 97
Don't quote integer.
SQL
if [ $item = 17 ]; then
if [ "$item" = 17 ]; then
Quote variable.
Shell
for (int i=0; i<50; i++) {{}}
for (int i=0; i<50; i++) {{}}
Correct.
Java
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
$arr[27]
if ($arr.Count -gt 27) {{ $arr[27] }}
Check bounds.
PowerShell
let mut count=100; let ref1=&mut count; let ref2=&mut count;
let mut count=100; {{ let ref1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
{{'value':48, 'value' 99}}
{{'value':48, 'value':99}}
Colon missing.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(93);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(93, () => console.log('listening'));
Add callback.
Node.js
$items[52] = 5;
if (isset($items[52])) $items[52] = 5;
Check existence.
PHP
def handle(num): return num + 1
def handle(num): return num + 1
Correct.
Python
for (val in items)
for (val of items)
for...in iterates keys.
JavaScript
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
const val = 22; val = 44;
let val = 22; val = 44;
Cannot reassign const.
JavaScript
if y = 66
if y == 66
Use ==.
Go
object Person {{ def main(args: Array[String]) = println("data") }}
object Person {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
cin >> val;
int val; cin >> val;
Declare variable.
C++
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let c: number | null = null; c.toFixed(1);
let c: number | null = null; if(c!==null) c.toFixed(1);
Null check.
TypeScript
yield count
yield count
Correct yield.
Python