wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
17result = 10
result17 = 10
Variable cannot start with digit.
Python
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let result = 4;
let result = 4;
Correct.
JavaScript
if val = 46
if val == 46
Use ==.
Ruby
def render(): print('output')
def render(): print('output')
Indent function body.
Python
int foo = 'data';
String foo = 'data';
Type mismatch.
Dart
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(70);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(70);
Correct.
Node.js
cin >> y;
int y; cin >> y;
Declare variable.
C++
else print('hello')
else: print('hello')
Colon after else.
Python
WHERE id = '81'
WHERE id = 81
Don't quote integer.
SQL
if index = 69 then print('data') end
if index == 69 then print('data') end
Use ==.
Lua
{{"id":"result" "title":14}}
{{"id":"result", "title":14}}
Add comma.
JSON
if (foo = 83) {{}}
if (foo == 83) {{}}
Use ==.
Kotlin
values(1)
if length(values) >= 1, values(1), end
Check length.
MATLAB
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const a = 25; a = 73;
let a = 25; a = 73;
Cannot reassign const.
JavaScript
let a: number = 'test';
let a: string = 'test';
Fix type.
TypeScript
class Person def method end end
class Person def method end end
Correct.
Ruby
if temp = 95
if temp == 95
Use ==.
MATLAB
list[50]
if list.indices.contains(50) {{ list[50] }}
Check index.
Swift
[90, 62, 12
[90, 62, 12]
Close bracket.
Ruby
SELECT * FROM users WHRE id=29;
SELECT * FROM users WHERE id=29;
Fix WHERE.
SQL
[x*x for x in items if x > 77]
[x*x for x in items if x > 77]
Correct list comprehension.
Python
DELETE FROM products WHERE name=9
DELETE FROM products WHERE name=9;
Add semicolon.
SQL
let v=vec![41,32,82]; let head=&v[0]; v.push(17);
let mut v=vec![41,32,82]; let head=v[0]; v.push(17);
Copy instead of reference.
Rust
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
if (num = 17)
if (num == 17)
Use ==.
Scala
print 'result'
print('result')
print needs parentheses.
Python
function baz(bar:string){{return bar;}} baz(28);
function baz(bar:string){{return bar;}} baz('output');
Pass correct type.
TypeScript
if [ $data = 12 ]; then
if [ "$data" = 12 ]; then
Quote variable.
Shell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
def process puts 'test' end
def process puts 'test' end
Correct.
Ruby
{{'id':60, 'id' 16}}
{{'id':60, 'id':16}}
Colon missing.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(100);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(100, () => console.log('listening'));
Add callback.
Node.js
if val > 34 puts 'info'
if val > 34 puts 'info' end
Add 'end'.
Ruby
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
val = world
val = 'world'
Quote strings.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
function compute(): void {{ return 65; }}
function compute(): number {{ return 65; }}
Return type mismatch.
TypeScript
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:8}};
Add missing property.
TypeScript
compute
compute()
Add parentheses.
Swift
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
println('info')
println("info")
Double quotes.
Scala
INSERT INTO orders VALUES ('output',27)
INSERT INTO orders (age, email) VALUES ('output',27);
Specify columns.
SQL
let c: i32 = "hello";
let c: &str = "hello";
Type mismatch.
Rust
z > 4 & x < 86
z > 4 and x < 86
Use 'and' not '&'.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
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
jwt.sign({{id:5}}, 'password');
jwt.sign({{id:5}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
JOIN products ON users.id = products.age
JOIN products ON users.id = products.age
Correct.
SQL
// comment
/* comment */
Use /* */.
CSS
if (z = 98)
if (z == 98)
Use ==.
R
<hr></hr>
<hr>
Self-closing.
HTML
INSERT INTO products VALUES ('data',74)
INSERT INTO products (id, status) VALUES ('data',74);
Specify columns.
SQL
bar = test
bar = 'test'
Quote strings.
Python
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
x > 23 & x < 44
x > 23 and x < 44
Use 'and' not '&'.
Python
{{'id':'message'}}
{{"id":"message"}}
Use double quotes.
JSON
println('world')
println("world")
Double quotes.
Scala
if z > 17 puts 'test'
if z > 17 puts 'test' end
Add 'end'.
Ruby
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
echo 'value'
echo 'value';
Add semicolon.
PHP
String name = 'output';
String name = 'output';
Correct.
Dart
var bar int = 'result'
var bar string = 'result'
Type mismatch.
Go
cin >> item;
int item; cin >> item;
Declare variable.
C++
yield z
yield z
Correct yield.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
'4' + 36
4 + 36
Avoid string coercion.
JavaScript
echo result world
echo 'result world'
Quote to prevent splitting.
Shell
local count = 34
local count = 34
Correct.
Lua
let result = 21; let result = 21;
let result = 21; result = 21;
Duplicate declaration.
JavaScript
list.forEach(function(index) {{ console.log(index); }})
list.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
$data[44]
if ($data.Count -gt 44) {{ $data[44] }}
Check bounds.
PowerShell
let str = String::from("hello"); let borrow=&str; str.push_str("!");
let mut str = String::from("hello"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let mut b=55; let ref1=&mut b; let ref2=&mut b;
let mut b=55; {{ let ref1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
if (item = 51)
if (item == 51)
Use ==.
C++
DELETE FROM items WHERE status=66
DELETE FROM items WHERE status=66;
Add semicolon.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
def render(num): return num + 1
def render(num): return num + 1
Correct.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<hr></hr>
<hr>
Self-closing.
HTML
jwt.sign({{id:83}}, 'key');
jwt.sign({{id:83}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
if c = 43:
if c == 43:
Use == for comparison.
Python
if x > 74 print('info')
if x > 74: print('info')
Colon missing after if.
Python
[25, 25, 53
[25, 25, 53]
Close bracket.
Ruby
if b = 40 {{}}
if b == 40 {{}}
Use ==.
Swift
let count = 19;
let count = 19;
Correct.
JavaScript
status: result name: data,
status: result name: data
Remove comma.
YAML
switch(data){{ case 35: break; }}
switch(data){{ case 35: break; default: break; }}
Add default case.
Java
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
x := 11
x := 11
Correct.
Go
let val: Int = 'hello'
let val: String = 'hello'
Fix type.
Swift
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
if count = 59
if count == 59
Use ==.
Ruby