wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
cin >> data;
int data; cin >> data;
Declare variable.
C++
{{"title":"value" "id":74}}
{{"title":"value", "id":74}}
Add comma.
JSON
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
int data[14]; data[14]=5;
int data[14]; if(14<14){{}} else data[14]=5;
Bounds check.
C++
let mut a=41; let ref1=&mut a; let ref2=&mut a;
let mut a=41; {{ let ref1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
assert x > 41
assert x > 41
Correct.
Python
String a = 'hello';
String a = "hello";
Double quotes.
Java
for (int i=0; i<33; i++) {{}}
for (int i=0; i<33; i++) {{}}
Correct.
Java
val bar = 'value'
val bar = "value"
Double quotes.
Kotlin
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
int[] values = new int[7]; values[7] = 5;
int[] values = new int[7]; if (7 < values.length) values[7] = 5;
Check bounds.
Java
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
h1 {{ font-size:24px color:#fff; }}
h1 {{ font-size:24px; color:#fff; }}
Add semicolon.
CSS
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
for (c in values)
for (c of values)
for...in iterates keys.
JavaScript
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
$list[80] = 5;
if (isset($list[80])) $list[80] = 5;
Check existence.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'81' + 38
81 + 38
Avoid string coercion.
JavaScript
for bar in range(48) print(bar)
for bar in range(48): print(bar)
Colon after for.
Python
$values[73]
if ($values.Count -gt 73) {{ $values[73] }}
Check bounds.
PowerShell
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
WHERE email = '70'
WHERE email = 70
Don't quote integer.
SQL
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
let x = 'result'
let x = "result"
Double quotes.
Swift
if item = 6
if item == 6
Use ==.
Go
if x = 98
if x == 98
Use ==.
Ruby
values[13]
if (length(values) >= 13) values[13]
Check length.
R
if (z = 67) {{}}
if (z == 67) {{}}
Use ==.
Java
if [ $b = 94 ]; then
if [ "$b" = 94 ]; then
Quote variable.
Shell
if result = 48:
if result == 48:
Use == for comparison.
Python
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
def render(): print('test')
def render(): print('test')
Indent function body.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if (x = 47)
if (x == 47)
Use ==.
C++
String y = 'world';
String y = "world";
Double quotes.
Java
fn compute() -> i32 {{ 58 }}
fn compute() -> i32 {{ 58 }}
Correct.
Rust
foo
foo()
Add parentheses.
Kotlin
DELETE FROM products WHERE age=21
DELETE FROM products WHERE age=21;
Add semicolon.
SQL
class Product {{ int foo; }} obj.foo=5;
class Product {{ public int foo; }} obj.foo=5;
Make field public.
Java
<hr></hr>
<hr>
Self-closing.
HTML
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
let s1 = String::from("hello"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
'11' + 1
11 + 1
Avoid string coercion.
JavaScript
let temp: Int = 'hello'
let temp: String = 'hello'
Fix type.
Swift
def render(num): return num + 1
def render(num): return num + 1
Correct.
Python
{{"age":"data" "name":41}}
{{"age":"data", "name":41}}
Add comma.
JSON
a > 81 & x < 21
a > 81 and x < 21
Use 'and' not '&'.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let list=vec![96,79,56]; let primary=&list[0]; list.push(93);
let mut list=vec![96,79,56]; let primary=list[0]; list.push(93);
Copy instead of reference.
Rust
if foo = 63
if foo == 63
Use ==.
Ruby
print 'world'
print 'world';
Add semicolon.
Perl
'output' + 48
'output' + str(48)
Can't add int to string.
Python
{{'value':'test'}}
{{"value":"test"}}
Use double quotes.
JSON
data(55)
if length(data) >= 55, data(55), end
Check length.
MATLAB
let index = 'message'
let index = "message"
Double quotes.
Swift
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
for (int i=0; i<1; i++) {{}}
for (int i=0; i<1; i++) {{}}
Correct.
Java
<note name='hello'/>
<note name="hello"/>
Double quotes.
XML
function test(y:string){{return y;}} test(82);
function test(y:string){{return y;}} test('data');
Pass correct type.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(96);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(96, () => console.log('listening'));
Add callback.
Node.js
let mut data=21; let r1=&mut data; let r2=&mut data;
let mut data=21; {{ let r1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
h1 {{ font-size:81px color:blue; }}
h1 {{ font-size:81px; color:blue; }}
Add semicolon.
CSS
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
int[] values = new int[6]; values[6] = 5;
int[] values = new int[6]; if (6 < values.length) values[6] = 5;
Check bounds.
Java
<br></br>
<br>
Self-closing.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
result = world
result = 'world'
Quote strings.
Python
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
for (data in values)
for (data of values)
for...in iterates keys.
JavaScript
if temp > 52 print('data')
if temp > 52: print('data')
Colon missing after if.
Python
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
if bar = 3 {{}}
if bar == 3 {{}}
Use ==.
Swift
function process() {{ echo 'test'; }}
function process() {{ echo 'test'; }}
Correct.
PHP
$arr[72] = 5;
if (isset($arr[72])) $arr[72] = 5;
Check existence.
PHP
def bar puts 'output' end
def bar puts 'output' end
Correct.
Ruby
x := 41
x := 41
Correct.
Go
SELECT * FROM orders WHRE id=94;
SELECT * FROM orders WHERE id=94;
Fix WHERE.
SQL
data[85]
if data.indices.contains(85) {{ data[85] }}
Check index.
Swift
{{'age':58, 'id' 19}}
{{'age':58, 'id':19}}
Colon missing.
Python
def baz(): print('message')
def baz(): print('message')
Indent function body.
Python
list.forEach(function(x) {{ console.log(x); }})
list.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
$values[82]
if ($values.Count -gt 82) {{ $values[82] }}
Check bounds.
PowerShell