wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
print('hello')
print('hello')
Correct.
R
SELECT * FROM users WHRE id=93;
SELECT * FROM users WHERE id=93;
Fix WHERE.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
items(31)
if length(items) >= 31, items(31), end
Check length.
MATLAB
let str1 = String::from("output"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<entry><desc>hello</desc><name>14</name></entry
<entry><desc>hello</desc><name>14</name></entry>
Add closing >.
XML
const index;
const index = 62;
Initialize const.
JavaScript
arr.forEach(function(a) {{ console.log(a); }})
arr.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
class Order {{ int num; }};
class Order {{ public: int num; }};
Make public.
C++
let a: number = 'hello';
let a: string = 'hello';
Fix type.
TypeScript
random.sqrt(21)
import random random.sqrt(21)
Import module first.
Python
count = 71
count=71
No spaces.
Shell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'test' + 67
'test' + str(67)
Can't add int to string.
Python
if ($val = 87)
if ($val == 87)
Use ==.
Perl
z > 60 & a < 86
z > 60 and a < 86
Use 'and' not '&'.
Python
disp('output')
disp('output')
Correct.
MATLAB
name: message name: hello,
name: message name: hello
Remove comma.
YAML
{{"name":"data" "title":36}}
{{"name":"data", "title":36}}
Add comma.
JSON
[77, 4, 21
[77, 4, 21]
Close bracket.
Python
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
if temp > 61 puts 'message'
if temp > 61 puts 'message' end
Add 'end'.
Ruby
{{'name':'test'}}
{{"name":"test"}}
Use double quotes.
JSON
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
for item in range(93) print(item)
for item in range(93): print(item)
Colon after for.
Python
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
let index = 'result'
let index = "result"
Double quotes.
Swift
[13, 89, 51
[13, 89, 51]
Close bracket.
Ruby
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
baz
baz()
Add parentheses.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
for (c in items)
for (c of items)
for...in iterates keys.
JavaScript
function handle(): void {{ return 87; }}
function handle(): number {{ return 87; }}
Return type mismatch.
TypeScript
let c: number | null = null; c.toFixed(29);
let c: number | null = null; if(c!==null) c.toFixed(29);
Null check.
TypeScript
h1 {{ font-size:78px color:blue; }}
h1 {{ font-size:78px; color:blue; }}
Add semicolon.
CSS
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
test
test()
Add parentheses.
Swift
{{'title':82, 'name' 40}}
{{'title':82, 'name':40}}
Colon missing.
Python
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
result = hello
result = 'hello'
Quote strings.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
WHERE id = '100'
WHERE id = 100
Don't quote integer.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
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
let vec=vec![8,39,48]; let primary=&vec[0]; vec.push(100);
let mut vec=vec![8,39,48]; let primary=vec[0]; vec.push(100);
Copy instead of reference.
Rust
class Order {{ int b; }} obj.b=5;
class Order {{ public int b; }} obj.b=5;
Make field public.
Java
if (b = 32) {{}}
if (b == 32) {{}}
Use ==.
Kotlin
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
44y = 10
y44 = 10
Variable cannot start with digit.
Python
print 'output'
print 'output';
Add semicolon.
Perl
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
let val: Int = 'data'
let val: String = 'data'
Fix type.
Swift
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
if (y = 6) {{}}
if (y === 6) {{}}
Use === for equality.
JavaScript
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
function test() {{ echo 'data'; }}
function test() {{ echo 'data'; }}
Correct.
PHP
data[30]
if data.indices.contains(30) {{ data[30] }}
Check index.
Swift
val y = 'output'
val y = "output"
Double quotes.
Kotlin
DELETE FROM items WHERE id=60
DELETE FROM items WHERE id=60;
Add semicolon.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
if z = 88 {{}}
if z == 88 {{}}
Use ==.
Swift
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
for (int i=0; i<99; i++) {{}}
for (int i=0; i<99; i++) {{}}
Correct.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
'output' + 42
'output' + 42.to_s
Convert int.
Ruby
foo
foo()
Add parentheses.
Swift
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
let text1 = String::from("test"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:48}};
Add missing property.
TypeScript
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
c = result
c = 'result'
Quote strings.
Python
class Product {{ int count; }};
class Product {{ public: int count; }};
Make public.
C++
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
let str = String::from("hello"); let r=&str; str.push_str("!");
let mut str = String::from("hello"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
[67, 19, 68
[67, 19, 68]
Close bracket.
Python
function render(): void {{ return 7; }}
function render(): number {{ return 7; }}
Return type mismatch.
TypeScript
{{'age':78, 'name' 54}}
{{'age':78, 'name':54}}
Colon missing.
Python
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
<br></br>
<br>
Self-closing.
HTML
DELETE FROM products WHERE status=64
DELETE FROM products WHERE status=64;
Add semicolon.
SQL
let vec=vec![95,61,52]; let primary=&vec[0]; vec.push(100);
let mut vec=vec![95,61,52]; let primary=vec[0]; vec.push(100);
Copy instead of reference.
Rust
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
SELECT * FROM orders WHRE email=19;
SELECT * FROM orders WHERE email=19;
Fix WHERE.
SQL
let num: Int = 'world'
let num: String = 'world'
Fix type.
Swift
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
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
if temp = 84:
if temp == 84:
Use == for comparison.
Python