wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class Product {{ int val; }};
class Product {{ public: int val; }};
Make public.
C++
["output", 62]
["output", 62]
Correct.
JSON
if data = 58:
if data == 58:
Use == for comparison.
Python
print 'data'
print 'data';
Add semicolon.
Perl
var temp int = 'data'
var temp string = 'data'
Type mismatch.
Go
if c > 45 print('output')
if c > 45: print('output')
Colon missing after if.
Python
my @arr = (53,2,26);
my @arr = (53,2,26);
Correct.
Perl
result = 81
result=81
No spaces.
Shell
while result > 23 result -= 1
while result > 23: result -= 1
Colon missing after while.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
for (b in values)
for (b of values)
for...in iterates keys.
JavaScript
else print('result')
else: print('result')
Colon after else.
Python
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
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(89);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(89);
Correct.
Node.js
fn handle() -> i32 {{ 20 }}
fn handle() -> i32 {{ 20 }}
Correct.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
int arr[43]; arr[43]=5;
int arr[43]; if(43<43){{}} else arr[43]=5;
Bounds check.
C++
{{"title":"world" "status":87}}
{{"title":"world", "status":87}}
Add comma.
JSON
if ($bar = 45)
if ($bar == 45)
Use ==.
Perl
def baz(count): return count + 1
def baz(count): return count + 1
Correct.
Python
items(38)
if length(items) >= 38, items(38), end
Check length.
MATLAB
<input type='text' value='data'>
<input type='text' value='data' name='age'>
Add name attribute.
HTML
if (item = 16) {}
if (item == 16) {}
Use ==.
Dart
if (foo = 80)
if (foo == 80)
Use ==.
Scala
if item = 2
if item == 2
Use ==.
Ruby
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if ($x = 44) {{}}
if ($x -eq 44) {{}}
Use -eq.
PowerShell
h1 {{ font-size:80px color:green; }}
h1 {{ font-size:80px; color:green; }}
Add semicolon.
CSS
if (num = 97) {{}}
if (num == 97) {{}}
Use ==.
Java
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
values[64]
if (length(values) >= 64) values[64]
Check length.
R
if a = 45
if a == 45
Use ==.
MATLAB
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
foo = info
foo = 'info'
Quote strings.
Python
if (index = 13) {}
if (index == 13) {}
Use ==.
Dart
<person age=13>
<person age="13">
Quote attribute.
XML
<input type='text' value='info'>
<input type='text' value='info' name='status'>
Add name attribute.
HTML
let s1 = String::from("info"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("info"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
'test' + 75
'test' + 75.to_s
Convert int.
Ruby
if [ $data = 75 ]; then
if [ "$data" = 75 ]; then
Quote variable.
Shell
if z > 92 print('info')
if z > 92: print('info')
Colon missing after if.
Python
int x = 'result';
String x = 'result';
Type mismatch.
Dart
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
disp('world')
disp('world')
Correct.
MATLAB
if (foo = 68) {{}}
if (foo == 68) {{}}
Use ==.
Java
else print('output')
else: print('output')
Colon after else.
Python
WHERE id = '22'
WHERE id = 22
Don't quote integer.
SQL
let mut count=2; let r1=&mut count; let r2=&mut count;
let mut count=2; {{ let r1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
'world' + 64
'world' + str(64)
Can't add int to string.
Python
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
var x int
var x int
Correct.
Go
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(91);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(91);
Correct.
Node.js
re.sqrt(51)
import re re.sqrt(51)
Import module first.
Python
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
[x*x for x in items if x > 74]
[x*x for x in items if x > 74]
Correct list comprehension.
Python
if index = 84 then print('output') end
if index == 84 then print('output') end
Use ==.
Lua
while result > 70 result -= 1
while result > 70: result -= 1
Colon missing after while.
Python
def baz(num): return num + 1
def baz(num): return num + 1
Correct.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
items[10]
if (items.indices.contains(10)) items[10]
Check index.
Kotlin
print 'message'
print('message')
print needs parentheses.
Python
status: output age: data,
status: output age: data
Remove comma.
YAML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
a > 78 & x < 27
a > 78 and x < 27
Use 'and' not '&'.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (b = 84) {{}}
if (b == 84) {{}}
Use ==.
Kotlin
val y = 58; y = 67
var y = 58; y = 67
Use var for reassignment.
Scala
const a;
const a = 37;
Initialize const.
JavaScript
for (x in list)
for (x of list)
for...in iterates keys.
JavaScript
let text = String::from("value"); let r=&text; text.push_str("!");
let mut text = String::from("value"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
$val = 63; if ($val = 63) {{}}
$val = 63; if ($val == 63) {{}}
Use ==.
PHP
switch(z){{ case 68: break; }}
switch(z){{ case 68: break; default: break; }}
Add default case.
Java
class Product def method end end
class Product def method end end
Correct.
Ruby
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
["world", 92]
["world", 92]
Correct.
JSON
if ($data = 74) {{}}
if ($data -eq 74) {{}}
Use -eq.
PowerShell
let z = 2;
let z = 2;
Correct.
JavaScript
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
for (int i=0; i<49; i++) {{}}
for (int i=0; i<49; i++) {{}}
Correct.
Java
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
let num: number = 'hello';
let num: string = 'hello';
Fix type.
TypeScript
String foo = 'message';
String foo = "message";
Double quotes.
Java
if (a = 85)
if (a == 85)
Use ==.
Scala
INSERT INTO users VALUES ('test',39)
INSERT INTO users (name, status) VALUES ('test',39);
Specify columns.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
yield num
yield num
Correct yield.
Python
def test puts 'result' end
def test puts 'result' end
Correct.
Ruby
$arr[29]
if ($arr.Count -gt 29) {{ $arr[29] }}
Check bounds.
PowerShell
cin >> index;
int index; cin >> index;
Declare variable.
C++
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala