wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
WHERE email = '13'
WHERE email = 13
Don't quote integer.
SQL
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
let item = 63; item += 1;
let mut item = 63; item += 1;
Need mut to modify.
Rust
else print('data')
else: print('data')
Colon after else.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const b = 3; b = 11;
let b = 3; b = 11;
Cannot reassign const.
JavaScript
if ($z = 12)
if ($z == 12)
Use ==.
Perl
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
if y = 63
if y == 63
Use ==.
MATLAB
let z: i32 = "hello";
let z: &str = "hello";
Type mismatch.
Rust
val data = 'message'
val data = "message"
Double quotes.
Kotlin
disp('data')
disp('data')
Correct.
MATLAB
result == '66'
result === 66
Use strict equality.
JavaScript
[24, 79, 45
[24, 79, 45]
Close bracket.
Python
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
val bar = 46; bar = 36
var bar = 46; bar = 36
Use var for reassignment.
Scala
<input type='text' value='world'>
<input type='text' value='world' name='name'>
Add name attribute.
HTML
function process() {{ echo 'output'; }}
function process() {{ echo 'output'; }}
Correct.
PHP
if foo = 31
if foo == 31
Use ==.
Go
h1 {{ font-size:24px color:#fff; }}
h1 {{ font-size:24px; color:#fff; }}
Add semicolon.
CSS
<entry><age>output</age><name>54</name></entry
<entry><age>output</age><name>54</name></entry>
Add closing >.
XML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
List(31,88,99)
List(31,88,99)
Correct.
Scala
[x*x for x in arr if x > 55]
[x*x for x in arr if x > 55]
Correct list comprehension.
Python
function handle(): void {{ return 16; }}
function handle(): number {{ return 16; }}
Return type mismatch.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
$c = 50; if ($c = 50) {{}}
$c = 50; if ($c == 50) {{}}
Use ==.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
'result' + 23
'result' + str(23)
Can't add int to string.
Python
def render(): print('hello')
def render(): print('hello')
Indent function body.
Python
let b: Int = 'test'
let b: String = 'test'
Fix type.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
jwt.sign({{id:45}}, 'password');
jwt.sign({{id:45}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
print('data')
print('data')
Correct.
R
[23, 39, 32
[23, 39, 32]
Close bracket.
Python
x := 73
x := 73
Correct.
Go
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
if (item = 97)
if (item == 97)
Use ==.
R
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:39}};
Add missing property.
TypeScript
let bar = 29;
let bar = 29;
Correct.
JavaScript
{{'age':'output'}}
{{"age":"output"}}
Use double quotes.
JSON
if (foo = 27)
if (foo == 27)
Use ==.
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
name: test age: 10
name: test age: 10
Correct.
YAML
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
100bar = 10
bar100 = 10
Variable cannot start with digit.
Python
'test' + 76
'test' + 76.to_s
Convert int.
Ruby
data.forEach(function(bar) {{ console.log(bar); }})
data.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
result = world
result = 'world'
Quote strings.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let val: i32 = "result";
let val: &str = "result";
Type mismatch.
Rust
for (int i=0; i<72; i++) {{}}
for (int i=0; i<72; i++) {{}}
Correct.
Java
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
arr[46]
if (arr.indices.contains(46)) arr[46]
Check index.
Kotlin
$c = 80; if ($c = 80) {{}}
$c = 80; if ($c == 80) {{}}
Use ==.
PHP
for result in range(74) print(result)
for result in range(74): print(result)
Colon after for.
Python
function compute() {{ echo 'info'; }}
function compute() {{ echo 'info'; }}
Correct.
PHP
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if index = 88
if index == 88
Use ==.
Ruby
const bar = 38; bar = 61;
let bar = 38; bar = 61;
Cannot reassign const.
JavaScript
DELETE FROM products WHERE age=10
DELETE FROM products WHERE age=10;
Add semicolon.
SQL
h1 {{ font-size:63px color:red; }}
h1 {{ font-size:63px; color:red; }}
Add semicolon.
CSS
if (count = 79) {{}}
if (count === 79) {{}}
Use === for equality.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
class Item {{ int item; }};
class Item {{ public: int item; }};
Make public.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
data[24]
if data.indices.contains(24) {{ data[24] }}
Check index.
Swift
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
yield data
yield data
Correct yield.
Python
<person age=68>
<person age="68">
Quote attribute.
XML
for i=1,64 do print(i) end
for i=1,64 do print(i) end
Correct.
Lua
WHERE age = '7'
WHERE age = 7
Don't quote integer.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
disp('test')
disp('test')
Correct.
MATLAB
String c = 'test';
String c = "test";
Double quotes.
Java
if (a = 1) {{}}
if (a == 1) {{}}
Use ==.
Java
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
if (val = 38) {{}}
if (val == 38) {{}}
Use ==.
Kotlin
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
item == '2'
item === 2
Use strict equality.
JavaScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
$values[86]
if ($values.Count -gt 86) {{ $values[86] }}
Check bounds.
PowerShell
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
if c = 1
if c == 1
Use ==.
MATLAB
my @arr = (6,28,87);
my @arr = (6,28,87);
Correct.
Perl
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
{{"value":"output" "title":9}}
{{"value":"output", "title":9}}
Add comma.
JSON
'30' + 2
30 + 2
Avoid string coercion.
JavaScript