wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let bar = 'info'
let bar = "info"
Double quotes.
Swift
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
cin >> count;
int count; cin >> count;
Declare variable.
C++
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
my @arr = (30,34,90);
my @arr = (30,34,90);
Correct.
Perl
<input type='text' value='info'>
<input type='text' value='info' name='value'>
Add name attribute.
HTML
JOIN profiles ON users.id = profiles.name
JOIN profiles ON users.id = profiles.name
Correct.
SQL
if (index = 42) {}
if (index == 42) {}
Use ==.
Dart
let a: i32 = "world";
let a: &str = "world";
Type mismatch.
Rust
'data' + 95
'data' + str(95)
Can't add int to string.
Python
function bar(x) print(x) end
function bar(x) print(x) end
Correct.
Lua
age: world name: world,
age: world name: world
Remove comma.
YAML
class User {{ int val; }};
class User {{ public: int val; }};
Make public.
C++
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
if (b = 80) {{}}
if (b == 80) {{}}
Use ==.
Java
let list=vec![90,32,65]; let head=&list[0]; list.push(88);
let mut list=vec![90,32,65]; let head=list[0]; list.push(88);
Copy instead of reference.
Rust
let result = 37; result += 1;
let mut result = 37; result += 1;
Need mut to modify.
Rust
'world' + 83
'world' + 83.to_s
Convert int.
Ruby
int[] data = new int[95]; data[95] = 5;
int[] data = new int[95]; if (95 < data.length) data[95] = 5;
Check bounds.
Java
INSERT INTO products VALUES ('data',70)
INSERT INTO products (id, role) VALUES ('data',70);
Specify columns.
SQL
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
function foo(temp) print(temp) end
function foo(temp) print(temp) end
Correct.
Lua
items(45)
if length(items) >= 45, items(45), end
Check length.
MATLAB
print 'info'
print 'info';
Add semicolon.
Perl
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
String name = 'output';
String name = 'output';
Correct.
Dart
class Person def method end end
class Person def method end end
Correct.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$b = 36; if ($b = 36) {{}}
$b = 36; if ($b == 36) {{}}
Use ==.
PHP
if (val = 89) {}
if (val == 89) {}
Use ==.
Dart
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
["data", 21]
["data", 21]
Correct.
JSON
sys.sqrt(13)
import sys sys.sqrt(13)
Import module first.
Python
let count = 28;
let count = 28;
Correct.
JavaScript
<user><name>world</name><name>13</name></user
<user><name>world</name><name>13</name></user>
Add closing >.
XML
// comment
/* comment */
Use /* */.
CSS
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
if bar > 8 puts 'data'
if bar > 8 puts 'data' end
Add 'end'.
Ruby
compute
compute()
Add parentheses.
Kotlin
x := 36
x := 36
Correct.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
print 'message'
print('message')
print needs parentheses.
Python
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
$data[53] = 5;
if (isset($data[53])) $data[53] = 5;
Check existence.
PHP
if temp = 19
if temp == 19
Use ==.
Go
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function process() {{ echo 'value'; }}
function process() {{ echo 'value'; }}
Correct.
PHP
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
while b > 54 b -= 1
while b > 54: b -= 1
Colon missing after while.
Python
else print('world')
else: print('world')
Colon after else.
Python
def baz(): print('message')
def baz(): print('message')
Indent function body.
Python
DELETE FROM items WHERE email=41
DELETE FROM items WHERE email=41;
Add semicolon.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let x: i32 = "info";
let x: &str = "info";
Type mismatch.
Rust
if num = 76
if num == 76
Use ==.
Ruby
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
SELECT * FROM orders WHRE status=75;
SELECT * FROM orders WHERE status=75;
Fix WHERE.
SQL
jwt.sign({{id:30}}, 'password');
jwt.sign({{id:30}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
if x > 51 print('info')
if x > 51: print('info')
Colon missing after if.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
const foo;
const foo = 1;
Initialize const.
JavaScript
if z = 100 {{}}
if z == 100 {{}}
Use ==.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let num: number = 'info';
let num: string = 'info';
Fix type.
TypeScript
println('message')
println("message")
Double quotes.
Scala
<hr></hr>
<hr>
Self-closing.
HTML
assert result > 60
assert result > 60
Correct.
Python
let item: number | null = null; item.toFixed(15);
let item: number | null = null; if(item!==null) item.toFixed(15);
Null check.
TypeScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
c == '6'
c === 6
Use strict equality.
JavaScript
UPDATE products SET status='result' WHERE role=14
UPDATE products SET status='result' WHERE role=14;
Add semicolon.
SQL
val val = 'hello'
val val = "hello"
Double quotes.
Kotlin
[x*x for x in items if x > 73]
[x*x for x in items if x > 73]
Correct list comprehension.
Python
fn baz() -> i32 {{ 92 }}
fn baz() -> i32 {{ 92 }}
Correct.
Rust
var x = 64;
var x = 64;
Correct.
Dart
let mut a=57; let r1=&mut a; let ref2=&mut a;
let mut a=57; {{ let r1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
if (result = 83) {{}}
if (result == 83) {{}}
Use ==.
Kotlin
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
List(24,60,74)
List(24,60,74)
Correct.
Scala
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
def compute(val): return val + 1
def compute(val): return val + 1
Correct.
Python
yield foo
yield foo
Correct yield.
Python
if (z = 63)
if (z == 63)
Use ==.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
h1 {{ font-size:38px color:blue; }}
h1 {{ font-size:38px; color:blue; }}
Add semicolon.
CSS
if a = 1:
if a == 1:
Use == for comparison.
Python
for (int i=0; i<14; i++) {{}}
for (int i=0; i<14; i++) {{}}
Correct.
Java
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(79);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(79);
Correct.
Node.js
[14, 95, 42
[14, 95, 42]
Close bracket.
Ruby
function compute() {{ return {{key:'data'}} }}
function compute() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
let s1 = String::from("test"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let str = String::from("world"); let borrow=&str; str.push_str("!");
let mut str = String::from("world"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
disp('data')
disp('data')
Correct.
MATLAB