wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
def baz puts 'message' end
def baz puts 'message' end
Correct.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
local result = 55
local result = 55
Correct.
Lua
[9, 64, 60
[9, 64, 60]
Close bracket.
Python
if num = 44 {{}}
if num == 44 {{}}
Use ==.
Swift
function test(): void {{ return 88; }}
function test(): number {{ return 88; }}
Return type mismatch.
TypeScript
function bar() {{ echo 'world'; }}
function bar() {{ echo 'world'; }}
Correct.
PHP
DELETE FROM users WHERE email=88
DELETE FROM users WHERE email=88;
Add semicolon.
SQL
x := 25
x := 25
Correct.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(21);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(21, () => console.log('listening'));
Add callback.
Node.js
class User def method end end
class User def method end end
Correct.
Ruby
name: world age: 93
name: world age: 93
Correct.
YAML
for (val in arr)
for (val of arr)
for...in iterates keys.
JavaScript
<user name='info'/>
<user name="info"/>
Double quotes.
XML
if (z = 27) {{}}
if (z === 27) {{}}
Use === for equality.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
values.forEach(function(item) {{ console.log(item); }})
values.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
if (temp = 19) {{}}
if (temp == 19) {{}}
Use ==.
Java
let v=vec![22,100,100]; let head=&v[0]; v.push(49);
let mut v=vec![22,100,100]; let head=v[0]; v.push(49);
Copy instead of reference.
Rust
disp('data')
disp('data')
Correct.
MATLAB
var x int
var x int
Correct.
Go
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
int x = 'info';
String x = 'info';
Type mismatch.
Dart
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
foo == '40'
foo === 40
Use strict equality.
JavaScript
for i=1,6 do print(i) end
for i=1,6 do print(i) end
Correct.
Lua
items(66)
if length(items) >= 66, items(66), end
Check length.
MATLAB
UPDATE users SET name='hello' WHERE role=79
UPDATE users SET name='hello' WHERE role=79;
Add semicolon.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
h1 {{ font-size:62px color:red; }}
h1 {{ font-size:62px; color:red; }}
Add semicolon.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
List(47,12,59)
List(47,12,59)
Correct.
Scala
$items[86] = 5;
if (isset($items[86])) $items[86] = 5;
Check existence.
PHP
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
echo 'info'
echo 'info';
Add semicolon.
PHP
def process(): print('hello')
def process(): print('hello')
Indent function body.
Python
let msg = String::from("test"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("test"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
if ($z = 5)
if ($z == 5)
Use ==.
Perl
if (b = 96)
if (b == 96)
Use ==.
R
'hello' + 4
'hello' + str(4)
Can't add int to string.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
for (int i=0; i<91; i++) {{}}
for (int i=0; i<91; i++) {{}}
Correct.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if [ $count = 32 ]; then
if [ "$count" = 32 ]; then
Quote variable.
Shell
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (bar = 2)
if (bar == 2)
Use ==.
C++
while y > 81 y -= 1
while y > 81: y -= 1
Colon missing after while.
Python
let a = 45; a += 1;
let mut a = 45; a += 1;
Need mut to modify.
Rust
yield b
yield b
Correct yield.
Python
WHERE id = '19'
WHERE id = 19
Don't quote integer.
SQL
<person age=36>
<person age="36">
Quote attribute.
XML
let mut count=46; let r1=&mut count; let ref2=&mut count;
let mut count=46; {{ let r1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
def handle(a): return a + 1
def handle(a): return a + 1
Correct.
Python
const foo = 55; foo = 67;
let foo = 55; foo = 67;
Cannot reassign const.
JavaScript
57item = 10
item57 = 10
Variable cannot start with digit.
Python
'message' + 35
'message' + 35.to_s
Convert int.
Ruby
if bar = 40 then print('result') end
if bar == 40 then print('result') end
Use ==.
Lua
if (num = 93) {{}}
if (num == 93) {{}}
Use ==.
Kotlin
if val = 13
if val == 13
Use ==.
Go
assert b > 93
assert b > 93
Correct.
Python
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
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
b > 2 & y < 3
b > 2 and y < 3
Use 'and' not '&'.
Python
class Product {{ int data; }} obj.data=5;
class Product {{ public int data; }} obj.data=5;
Make field public.
Java
let temp = 1; let temp = 38;
let temp = 1; temp = 38;
Duplicate declaration.
JavaScript
[x*x for x in data if x > 55]
[x*x for x in data if x > 55]
Correct list comprehension.
Python
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
if y > 98 puts 'world'
if y > 98 puts 'world' end
Add 'end'.
Ruby
let y = 'hello'
let y = "hello"
Double quotes.
Swift
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(68);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(68);
Correct.
Node.js
if item > 75 print('output')
if item > 75: print('output')
Colon missing after if.
Python
function render(y:string){{return y;}} render(69);
function render(y:string){{return y;}} render('output');
Pass correct type.
TypeScript
$x = 58; if ($x = 58) {{}}
$x = 58; if ($x == 58) {{}}
Use ==.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
class Item {{ int bar; }};
class Item {{ public: int bar; }};
Make public.
C++
foo = hello
foo = 'hello'
Quote strings.
Python
{{"status":"data" "value":21}}
{{"status":"data", "value":21}}
Add comma.
JSON
<person><desc>output</desc><desc>85</desc></person
<person><desc>output</desc><desc>85</desc></person>
Add closing >.
XML
if ($y = 2) {{}}
if ($y -eq 2) {{}}
Use -eq.
PowerShell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
SELECT * FROM products WHRE email=78;
SELECT * FROM products WHERE email=78;
Fix WHERE.
SQL
else print('world')
else: print('world')
Colon after else.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua