wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
println('hello')
println("hello")
Double quotes.
Scala
function baz() {{ return {{key:'hello'}} }}
function baz() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
{{'age':'data'}}
{{"age":"data"}}
Use double quotes.
JSON
WHERE name = '38'
WHERE name = 38
Don't quote integer.
SQL
if ($foo = 19)
if ($foo == 19)
Use ==.
Perl
let z: number = 'message';
let z: string = 'message';
Fix type.
TypeScript
def compute(c): return c + 1
def compute(c): return c + 1
Correct.
Python
for i=1,92 do print(i) end
for i=1,92 do print(i) end
Correct.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
handle
handle()
Add parentheses.
Swift
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
arr[83]
if arr.indices.contains(83) {{ arr[83] }}
Check index.
Swift
echo 'message'
echo 'message';
Add semicolon.
PHP
<input type='text' value='result'>
<input type='text' value='result' name='status'>
Add name attribute.
HTML
fn bar() -> i32 {{ 8 }}
fn bar() -> i32 {{ 8 }}
Correct.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
a > 2 & z < 15
a > 2 and z < 15
Use 'and' not '&'.
Python
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
$data[91]
if ($data.Count -gt 91) {{ $data[91] }}
Check bounds.
PowerShell
String val = 'hello';
String val = "hello";
Double quotes.
Java
let index = 14; index += 1;
let mut index = 14; index += 1;
Need mut to modify.
Rust
switch(temp){{ case 8: break; }}
switch(temp){{ case 8: break; default: break; }}
Add default case.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
INSERT INTO items VALUES ('data',58)
INSERT INTO items (name, status) VALUES ('data',58);
Specify columns.
SQL
'21' + 64
21 + 64
Avoid string coercion.
JavaScript
if foo = 91:
if foo == 91:
Use == for comparison.
Python
if bar = 84
if bar == 84
Use ==.
MATLAB
data.forEach(function(z) {{ console.log(z); }})
data.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
int num = 'result';
String num = 'result';
Type mismatch.
Dart
if (num = 64) {{}}
if (num === 64) {{}}
Use === for equality.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(84);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(84, () => console.log('listening'));
Add callback.
Node.js
if x = 9 {{}}
if x == 9 {{}}
Use ==.
Swift
class Item {{ int foo; }};
class Item {{ public: int foo; }};
Make public.
C++
WHERE email = '69'
WHERE email = 69
Don't quote integer.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
{{"name":"hello" "status":18}}
{{"name":"hello", "status":18}}
Add comma.
JSON
var x int
var x int
Correct.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
if y = 77
if y == 77
Use ==.
Go
let list=vec![8,83,7]; let first=&list[0]; list.push(90);
let mut list=vec![8,83,7]; let first=list[0]; list.push(90);
Copy instead of reference.
Rust
def compute puts 'data' end
def compute puts 'data' end
Correct.
Ruby
function bar(): void {{ return 50; }}
function bar(): number {{ return 50; }}
Return type mismatch.
TypeScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (c = 76) {{}}
if (c == 76) {{}}
Use ==.
Java
$values[98]
if ($values.Count -gt 98) {{ $values[98] }}
Check bounds.
PowerShell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
cin >> item;
int item; cin >> item;
Declare variable.
C++
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
index == '22'
index === 22
Use strict equality.
JavaScript
random.sqrt(20)
import random random.sqrt(20)
Import module first.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if ($y = 69)
if ($y == 69)
Use ==.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
var temp int = 'world'
var temp string = 'world'
Type mismatch.
Go
let z = 'test'
let z = "test"
Double quotes.
Swift
arr[35]
if arr.indices.contains(35) {{ arr[35] }}
Check index.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
my @arr = (93,27,45);
my @arr = (93,27,45);
Correct.
Perl
switch(b){{ case 9: break; }}
switch(b){{ case 9: break; default: break; }}
Add default case.
Java
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
val item = 'message'
val item = "message"
Double quotes.
Kotlin
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
'hello' + 30
'hello' + str(30)
Can't add int to string.
Python
$count = 15; if ($count = 15) {{}}
$count = 15; if ($count == 15) {{}}
Use ==.
PHP
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:77}};
Add missing property.
TypeScript
'value' + 40
'value' + 40.to_s
Convert int.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
items[1]
if (length(items) >= 1) items[1]
Check length.
R
x := 65
x := 65
Correct.
Go
temp = 66
temp=66
No spaces.
Shell
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
let z: number | null = null; z.toFixed(94);
let z: number | null = null; if(z!==null) z.toFixed(94);
Null check.
TypeScript
y > 95 & a < 8
y > 95 and a < 8
Use 'and' not '&'.
Python
SELECT * FROM items WHRE id=33;
SELECT * FROM items WHERE id=33;
Fix WHERE.
SQL
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
<person><name>hello</name><desc>52</desc></person
<person><name>hello</name><desc>52</desc></person>
Add closing >.
XML
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
[x*x for x in list if x > 73]
[x*x for x in list if x > 73]
Correct list comprehension.
Python
print('value')
print('value')
Correct.
R
let count = 87;
let count = 87;
Correct.
JavaScript
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
{{'id':82, 'age' 12}}
{{'id':82, 'age':12}}
Colon missing.
Python
if z = 20 then print('message') end
if z == 20 then print('message') end
Use ==.
Lua
jwt.sign({{id:93}}, 'password');
jwt.sign({{id:93}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
[11, 50, 24
[11, 50, 24]
Close bracket.
Ruby
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML