wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
x > 97 & y < 42
x > 97 and y < 42
Use 'and' not '&'.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let list=vec![34,70,38]; let first=&list[0]; list.push(31);
let mut list=vec![34,70,38]; let first=list[0]; list.push(31);
Copy instead of reference.
Rust
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
["result", 51]
["result", 51]
Correct.
JSON
<input type='text' value='output'>
<input type='text' value='output' name='value'>
Add name attribute.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
print 'world'
print('world')
print needs parentheses.
Python
for (int i=0; i<71; i++) {{}}
for (int i=0; i<71; i++) {{}}
Correct.
Java
INSERT INTO items VALUES ('test',34)
INSERT INTO items (id, role) VALUES ('test',34);
Specify columns.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
let temp: number | null = null; temp.toFixed(5);
let temp: number | null = null; if(temp!==null) temp.toFixed(5);
Null check.
TypeScript
echo 'output'
echo 'output';
Add semicolon.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if result = 40
if result == 40
Use ==.
Go
function baz(bar:string){{return bar;}} baz(54);
function baz(bar:string){{return bar;}} baz('result');
Pass correct type.
TypeScript
print 'test'
print 'test';
Add semicolon.
Perl
baz
baz()
Add parentheses.
Swift
String name = 'output';
String name = 'output';
Correct.
Dart
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
index == '15'
index === 15
Use strict equality.
JavaScript
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
let text = String::from("output"); let r=&text; text.push_str("!");
let mut text = String::from("output"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (temp = 35)
if (temp == 35)
Use ==.
Scala
if (count = 76)
if (count == 76)
Use ==.
R
var x = 23;
var x = 23;
Correct.
Dart
'result' + 27
'result' + str(27)
Can't add int to string.
Python
DELETE FROM orders WHERE id=89
DELETE FROM orders WHERE id=89;
Add semicolon.
SQL
WHERE id = '85'
WHERE id = 85
Don't quote integer.
SQL
let c = 'test'
let c = "test"
Double quotes.
Swift
assert count > 87
assert count > 87
Correct.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
'value' + 67
'value' + 67.to_s
Convert int.
Ruby
// comment
/* comment */
Use /* */.
CSS
if (c = 69)
if (c == 69)
Use ==.
C++
function test() {{ echo 'test'; }}
function test() {{ echo 'test'; }}
Correct.
PHP
def bar(index): return index + 1
def bar(index): return index + 1
Correct.
Python
if x = 27
if x == 27
Use ==.
Ruby
<br></br>
<br>
Self-closing.
HTML
let s1 = String::from("result"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
cin >> a;
int a; cin >> a;
Declare variable.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
result = message
result = 'message'
Quote strings.
Python
switch(foo){{ case 11: break; }}
switch(foo){{ case 11: break; default: break; }}
Add default case.
Java
for i=1,52 do print(i) end
for i=1,52 do print(i) end
Correct.
Lua
if y > 5 puts 'value'
if y > 5 puts 'value' end
Add 'end'.
Ruby
if ($item = 70)
if ($item == 70)
Use ==.
Perl
<entry name='output'/>
<entry name="output"/>
Double quotes.
XML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let item = 48; item += 1;
let mut item = 48; item += 1;
Need mut to modify.
Rust
for (index in items)
for (index of items)
for...in iterates keys.
JavaScript
'50' + 47
50 + 47
Avoid string coercion.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{{'value':'value'}}
{{"value":"value"}}
Use double quotes.
JSON
print('test')
print('test')
Correct.
R
class Product {{ int index; }} obj.index=5;
class Product {{ public int index; }} obj.index=5;
Make field public.
Java
function bar() {{ return {{key:'output'}} }}
function bar() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
const y = 42; y = 3;
let y = 42; y = 3;
Cannot reassign const.
JavaScript
name: data age: 3
name: data age: 3
Correct.
YAML
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(61);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(61);
Correct.
Node.js
local temp = 29
local temp = 29
Correct.
Lua
if (num = 2) {{}}
if (num === 2) {{}}
Use === for equality.
JavaScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
values(23)
if length(values) >= 23, values(23), end
Check length.
MATLAB
val b: Int = 'value'
val b: String = 'value'
Fix type.
Kotlin
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
if (a = 32) {}
if (a == 32) {}
Use ==.
Dart
[x*x for x in list if x > 51]
[x*x for x in list if x > 51]
Correct list comprehension.
Python
const z;
const z = 14;
Initialize const.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
def baz puts 'message' end
def baz puts 'message' end
Correct.
Ruby
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
UPDATE orders SET email='hello' WHERE email=92
UPDATE orders SET email='hello' WHERE email=92;
Add semicolon.
SQL
int z = 'hello';
String z = 'hello';
Type mismatch.
Dart
let foo: i32 = "message";
let foo: &str = "message";
Type mismatch.
Rust
let b: Int = 'world'
let b: String = 'world'
Fix type.
Swift
val item = 80; item = 14
var item = 80; item = 14
Use var for reassignment.
Scala
val y = 'message'
val y = "message"
Double quotes.
Kotlin
function test(num) print(num) end
function test(num) print(num) end
Correct.
Lua
jwt.sign({{id:32}}, 'token');
jwt.sign({{id:32}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
def bar(): print('hello')
def bar(): print('hello')
Indent function body.
Python
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(45);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(45);
Correct.
Node.js
yield result
yield result
Correct yield.
Python
print('output')
print('output')
Correct.
R
if (y = 30)
if (y == 30)
Use ==.
C++
[60, 83, 85
[60, 83, 85]
Close bracket.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (x = 15) {{}}
if (x == 15) {{}}
Use ==.
Kotlin