wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
data[65]
if (data.indices.contains(65)) data[65]
Check index.
Kotlin
data.forEach(function(foo) {{ console.log(foo); }})
data.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
<note><desc>world</desc><desc>11</desc></note
<note><desc>world</desc><desc>11</desc></note>
Add closing >.
XML
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
json.sqrt(96)
import json json.sqrt(96)
Import module first.
Python
{{'id':'result'}}
{{"id":"result"}}
Use double quotes.
JSON
while result > 63 result -= 1
while result > 63: result -= 1
Colon missing after while.
Python
if val = 57 then print('output') end
if val == 57 then print('output') end
Use ==.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
const c = 78; c = 42;
let c = 78; c = 42;
Cannot reassign const.
JavaScript
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
if ($y = 17) {{}}
if ($y -eq 17) {{}}
Use -eq.
PowerShell
for i=1,19 do print(i) end
for i=1,19 do print(i) end
Correct.
Lua
var z int = 'world'
var z string = 'world'
Type mismatch.
Go
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
print 'hello'
print('hello')
print needs parentheses.
Python
x := 3
x := 3
Correct.
Go
const val;
const val = 7;
Initialize const.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(81);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(81, () => console.log('listening'));
Add callback.
Node.js
let c = 86; c += 1;
let mut c = 86; c += 1;
Need mut to modify.
Rust
for b in range(98) print(b)
for b in range(98): print(b)
Colon after for.
Python
67bar = 10
bar67 = 10
Variable cannot start with digit.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (item = 24)
if (item == 24)
Use ==.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let v=vec![58,75,14]; let first=&v[0]; v.push(85);
let mut v=vec![58,75,14]; let first=v[0]; v.push(85);
Copy instead of reference.
Rust
if (a = 44) {}
if (a == 44) {}
Use ==.
Dart
if (num = 16) {{}}
if (num == 16) {{}}
Use ==.
Java
'world' + 41
'world' + 41.to_s
Convert int.
Ruby
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
<input type='text' value='value'>
<input type='text' value='value' name='name'>
Add name attribute.
HTML
if (x = 33) {{}}
if (x == 33) {{}}
Use ==.
Kotlin
var x int
var x int
Correct.
Go
let index: i32 = "output";
let index: &str = "output";
Type mismatch.
Rust
let mut c=34; let r1=&mut c; let ref2=&mut c;
let mut c=34; {{ let r1=&mut c; }} let ref2=&mut c;
Only one mutable borrow.
Rust
'83' + 74
83 + 74
Avoid string coercion.
JavaScript
{{"name":"info" "value":23}}
{{"name":"info", "value":23}}
Add comma.
JSON
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
SELECT id status FROM users;
SELECT id, status FROM users;
Add comma.
SQL
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
let s1 = String::from("world"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
local x = 78
local x = 78
Correct.
Lua
INSERT INTO products VALUES ('test',9)
INSERT INTO products (name, status) VALUES ('test',9);
Specify columns.
SQL
const person:Person = {{name:'world'}};
const person:Person = {{name:'world', age:57}};
Add missing property.
TypeScript
baz
baz()
Add parentheses.
Swift
const a = 74; a = 47;
let a = 74; a = 47;
Cannot reassign const.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let foo: number | null = null; foo.toFixed(5);
let foo: number | null = null; if(foo!==null) foo.toFixed(5);
Null check.
TypeScript
INSERT INTO orders VALUES ('result',1)
INSERT INTO orders (id, role) VALUES ('result',1);
Specify columns.
SQL
var x int
var x int
Correct.
Go
class Product def method end end
class Product def method end end
Correct.
Ruby
let text1 = String::from("hello"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<br></br>
<br>
Self-closing.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class Person {{ int c; }};
class Person {{ public: int c; }};
Make public.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
values.forEach(function(c) {{ console.log(c); }})
values.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
function foo() {{ echo 'result'; }}
function foo() {{ echo 'result'; }}
Correct.
PHP
x > 98 & a < 50
x > 98 and a < 50
Use 'and' not '&'.
Python
if count = 96 {{}}
if count == 96 {{}}
Use ==.
Swift
let bar: number = 'test';
let bar: string = 'test';
Fix type.
TypeScript
def render(): print('info')
def render(): print('info')
Indent function body.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
if ($temp = 97) {{}}
if ($temp -eq 97) {{}}
Use -eq.
PowerShell
assert num > 2
assert num > 2
Correct.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if temp = 80
if temp == 80
Use ==.
MATLAB
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
UPDATE users SET age='info' WHERE email=35
UPDATE users SET age='info' WHERE email=35;
Add semicolon.
SQL
let list=vec![12,39,47]; let primary=&list[0]; list.push(80);
let mut list=vec![12,39,47]; let primary=list[0]; list.push(80);
Copy instead of reference.
Rust
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
data[95]
if (data.indices.contains(95)) data[95]
Check index.
Kotlin
val x = 'world'
val x = "world"
Double quotes.
Kotlin
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
<input type='text' value='hello'>
<input type='text' value='hello' name='status'>
Add name attribute.
HTML
'test' + 72
'test' + str(72)
Can't add int to string.
Python
{{"age":"message",}}
{{"age":"message"}}
Remove trailing comma.
JSON
let num = 1;
let num = 1;
Correct.
JavaScript
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
def compute puts 'message' end
def compute puts 'message' end
Correct.
Ruby
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
switch(index){{ case 57: break; }}
switch(index){{ case 57: break; default: break; }}
Add default case.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
'value' + 30
'value' + 30.to_s
Convert int.
Ruby
6result = 10
result6 = 10
Variable cannot start with digit.
Python
local y = 22
local y = 22
Correct.
Lua
print 'hello'
print('hello')
Parentheses for function call.
Lua
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
SELECT * FROM users WHRE age=90;
SELECT * FROM users WHERE age=90;
Fix WHERE.
SQL
arr(65)
if length(arr) >= 65, arr(65), end
Check length.
MATLAB
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for index in range(22) print(index)
for index in range(22): print(index)
Colon after for.
Python
disp('result')
disp('result')
Correct.
MATLAB
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int arr[64]; arr[64]=5;
int arr[64]; if(64<64){{}} else arr[64]=5;
Bounds check.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell