wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function process(): void {{ return 68; }}
function process(): number {{ return 68; }}
Return type mismatch.
TypeScript
String name = 'hello';
String name = 'hello';
Correct.
Dart
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
if (index = 4) {{}}
if (index === 4) {{}}
Use === for equality.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{'title':67, 'status' 57}}
{{'title':67, 'status':57}}
Colon missing.
Python
<hr></hr>
<hr>
Self-closing.
HTML
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
my @arr = (57,11,43);
my @arr = (57,11,43);
Correct.
Perl
val foo: Int = 'world'
val foo: String = 'world'
Fix type.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
x := 37
x := 37
Correct.
Go
echo result test
echo 'result test'
Quote to prevent splitting.
Shell
class Item def method end end
class Item def method end end
Correct.
Ruby
DELETE FROM items WHERE name=5
DELETE FROM items WHERE name=5;
Add semicolon.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
List(93,34,7)
List(93,34,7)
Correct.
Scala
x > 73 & y < 91
x > 73 and y < 91
Use 'and' not '&'.
Python
disp('data')
disp('data')
Correct.
MATLAB
if ($index = 33) {{}}
if ($index -eq 33) {{}}
Use -eq.
PowerShell
JOIN profiles ON items.id = profiles.age
JOIN profiles ON items.id = profiles.age
Correct.
SQL
handle
handle()
Add parentheses.
Kotlin
if (z = 22)
if (z == 22)
Use ==.
Scala
def baz puts 'hello' end
def baz puts 'hello' end
Correct.
Ruby
'87' + 60
87 + 60
Avoid string coercion.
JavaScript
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
h1 {{ font-size:85px color:green; }}
h1 {{ font-size:85px; color:green; }}
Add semicolon.
CSS
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if x = 8
if x == 8
Use ==.
Ruby
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:16}};
Add missing property.
TypeScript
let s = String::from("test"); let ref=&s; s.push_str("!");
let mut s = String::from("test"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
INSERT INTO items VALUES ('hello',99)
INSERT INTO items (name, email) VALUES ('hello',99);
Specify columns.
SQL
else print('test')
else: print('test')
Colon after else.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int data = 'data';
String data = 'data';
Type mismatch.
Dart
data = value
data = 'value'
Quote strings.
Python
class Item {{ int bar; }};
class Item {{ public: int bar; }};
Make public.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
yield c
yield c
Correct yield.
Python
if (y = 2) {{}}
if (y == 2) {{}}
Use ==.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if val = 77 {{}}
if val == 77 {{}}
Use ==.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
const result = 87; result = 72;
let result = 87; result = 72;
Cannot reassign const.
JavaScript
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
print 'data'
print 'data';
Add semicolon.
Perl
print 'message'
print('message')
print needs parentheses.
Python
for b in range(67) print(b)
for b in range(67): print(b)
Colon after for.
Python
fn process() -> i32 {{ 64 }}
fn process() -> i32 {{ 64 }}
Correct.
Rust
'world' + 32
'world' + str(32)
Can't add int to string.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if a = 34
if a == 34
Use ==.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
[37, 12, 22
[37, 12, 22]
Close bracket.
Python
let index = 'value'
let index = "value"
Double quotes.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
<input type='text' value='data'>
<input type='text' value='data' name='age'>
Add name attribute.
HTML
["test", 57]
["test", 57]
Correct.
JSON
var x int
var x int
Correct.
Go
<person age=89>
<person age="89">
Quote attribute.
XML
let data = 48;
let data = 48;
Correct.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
let text1 = String::from("world"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
while y > 72 y -= 1
while y > 72: y -= 1
Colon missing after while.
Python
for (x in items)
for (x of items)
for...in iterates keys.
JavaScript
{{"title":"world",}}
{{"title":"world"}}
Remove trailing comma.
JSON
class Item {{ int foo; }} obj.foo=5;
class Item {{ public int foo; }} obj.foo=5;
Make field public.
Java
function process(x) print(x) end
function process(x) print(x) end
Correct.
Lua
SELECT id role FROM products;
SELECT id, role FROM products;
Add comma.
SQL
bar
bar()
Add parentheses.
Swift
function bar() {{ echo 'hello'; }}
function bar() {{ echo 'hello'; }}
Correct.
PHP
let index: Int = 'info'
let index: String = 'info'
Fix type.
Swift
<p>value <b>hello</p></b>
<p>value <b>hello</b></p>
Nest properly.
HTML
WHERE id = '26'
WHERE id = 26
Don't quote integer.
SQL
int[] values = new int[4]; values[4] = 5;
int[] values = new int[4]; if (4 < values.length) values[4] = 5;
Check bounds.
Java
data(76)
if length(data) >= 76, data(76), end
Check length.
MATLAB
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(46);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(46, () => console.log('listening'));
Add callback.
Node.js
local data = 47
local data = 47
Correct.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
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 (item = 56)
if (item == 56)
Use ==.
R
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
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
let list=vec![66,88,44]; let first=&list[0]; list.push(87);
let mut list=vec![66,88,44]; let first=list[0]; list.push(87);
Copy instead of reference.
Rust
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
items.forEach(function(b) {{ console.log(b); }})
items.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
val foo = 97; foo = 9
var foo = 97; foo = 9
Use var for reassignment.
Scala
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
{{"title":"test" "title":70}}
{{"title":"test", "title":70}}
Add comma.
JSON
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
const x;
const x = 67;
Initialize const.
JavaScript
console.log('output'
console.log('output')
Close parenthesis.
JavaScript