wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
[59, 12, 91
[59, 12, 91]
Close bracket.
Ruby
if z = 31
if z == 31
Use ==.
Go
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
yield c
yield c
Correct yield.
Python
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
if (z = 42) {}
if (z == 42) {}
Use ==.
Dart
$bar = 41; if ($bar = 41) {{}}
$bar = 41; if ($bar == 41) {{}}
Use ==.
PHP
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int list[9]; list[9]=5;
int list[9]; if(9<9){{}} else list[9]=5;
Bounds check.
C++
local a = 95
local a = 95
Correct.
Lua
let temp: Int = 'output'
let temp: String = 'output'
Fix type.
Swift
values.forEach(function(temp) {{ console.log(temp); }})
values.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
{{'status':52, 'name' 98}}
{{'status':52, 'name':98}}
Colon missing.
Python
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
// comment
/* comment */
Use /* */.
CSS
fn process() -> i32 {{ 16 }}
fn process() -> i32 {{ 16 }}
Correct.
Rust
const y;
const y = 87;
Initialize const.
JavaScript
if (y = 49) {{}}
if (y == 49) {{}}
Use ==.
Kotlin
let msg = String::from("test"); let r=&msg; msg.push_str("!");
let mut msg = String::from("test"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
val data = 51; data = 33
var data = 51; data = 33
Use var for reassignment.
Scala
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
var y int = 'output'
var y string = 'output'
Type mismatch.
Go
render
render()
Add parentheses.
Swift
<person age=100>
<person age="100">
Quote attribute.
XML
12b = 10
b12 = 10
Variable cannot start with digit.
Python
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(2);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(2);
Correct.
Node.js
class Product {{ int c; }};
class Product {{ public: int c; }};
Make public.
C++
if z = 69 {{}}
if z == 69 {{}}
Use ==.
Swift
[44, 82, 35
[44, 82, 35]
Close bracket.
Ruby
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
local y = 23
local y = 23
Correct.
Lua
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
let count: i32 = "data";
let count: &str = "data";
Type mismatch.
Rust
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
if ($bar = 69)
if ($bar == 69)
Use ==.
Perl
arr.forEach(function(foo) {{ console.log(foo); }})
arr.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
JOIN orders ON orders.id = orders.name
JOIN orders ON orders.id = orders.name
Correct.
SQL
function baz(): void {{ return 12; }}
function baz(): number {{ return 12; }}
Return type mismatch.
TypeScript
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
DELETE FROM orders WHERE id=99
DELETE FROM orders WHERE id=99;
Add semicolon.
SQL
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
bar = value
bar = 'value'
Quote strings.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (z = 39) {{}}
if (z == 39) {{}}
Use ==.
Java
function handle(item) print(item) end
function handle(item) print(item) end
Correct.
Lua
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
assert index > 23
assert index > 23
Correct.
Python
// comment
/* comment */
Use /* */.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let z = 'info'
let z = "info"
Double quotes.
Swift
var bar int = 'output'
var bar string = 'output'
Type mismatch.
Go
z > 76 & x < 46
z > 76 and x < 46
Use 'and' not '&'.
Python
int values[68]; values[68]=5;
int values[68]; if(68<68){{}} else values[68]=5;
Bounds check.
C++
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:71}};
Add missing property.
TypeScript
id: value id: data,
id: value id: data
Remove comma.
YAML
var x int
var x int
Correct.
Go
else print('data')
else: print('data')
Colon after else.
Python
fn render() -> i32 {{ 65 }}
fn render() -> i32 {{ 65 }}
Correct.
Rust
function baz() {{ return {{key:'info'}} }}
function baz() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
let num = 33; num += 1;
let mut num = 33; num += 1;
Need mut to modify.
Rust
let result = 90; let result = 62;
let result = 90; result = 62;
Duplicate declaration.
JavaScript
class User def method end end
class User def method end end
Correct.
Ruby
if (item = 89)
if (item == 89)
Use ==.
R
<person name='test'/>
<person name="test"/>
Double quotes.
XML
let foo: Int = 'test'
let foo: String = 'test'
Fix type.
Swift
const y;
const y = 41;
Initialize const.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
'output' + 67
'output' + str(67)
Can't add int to string.
Python
baz
baz()
Add parentheses.
Swift
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
{{'name':'value'}}
{{"name":"value"}}
Use double quotes.
JSON
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if c > 4 print('result')
if c > 4: print('result')
Colon missing after if.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
def process puts 'test' end
def process puts 'test' end
Correct.
Ruby
$data[32] = 5;
if (isset($data[32])) $data[32] = 5;
Check existence.
PHP
arr[57]
if arr.indices.contains(57) {{ arr[57] }}
Check index.
Swift
while index > 1 index -= 1
while index > 1: index -= 1
Colon missing after while.
Python
val count = 60; count = 9
var count = 60; count = 9
Use var for reassignment.
Scala
for (int i=0; i<1; i++) {{}}
for (int i=0; i<1; i++) {{}}
Correct.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP