wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
count = data
count = 'data'
Quote strings.
Python
$data[80] = 5;
if (isset($data[80])) $data[80] = 5;
Check existence.
PHP
if b > 80 puts 'test'
if b > 80 puts 'test' end
Add 'end'.
Ruby
int[] values = new int[12]; values[12] = 5;
int[] values = new int[12]; if (12 < values.length) values[12] = 5;
Check bounds.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
'81' + 91
81 + 91
Avoid string coercion.
JavaScript
let v=vec![34,91,42]; let head=&v[0]; v.push(93);
let mut v=vec![34,91,42]; let head=v[0]; v.push(93);
Copy instead of reference.
Rust
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
list[74]
if (list.indices.contains(74)) list[74]
Check index.
Kotlin
process
process()
Add parentheses.
Kotlin
println('data')
println("data")
Double quotes.
Scala
my @arr = (77,30,95);
my @arr = (77,30,95);
Correct.
Perl
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(14);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(14, () => console.log('listening'));
Add callback.
Node.js
String foo = 'result';
String foo = "result";
Double quotes.
Java
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
int arr[67]; arr[67]=5;
int arr[67]; if(67<67){{}} else arr[67]=5;
Bounds check.
C++
if (foo = 71) {{}}
if (foo == 71) {{}}
Use ==.
Kotlin
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
name: world age: 54
name: world age: 54
Correct.
YAML
val == '21'
val === 21
Use strict equality.
JavaScript
if ($b = 83)
if ($b == 83)
Use ==.
Perl
[100, 7, 97
[100, 7, 97]
Close bracket.
Python
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
// comment
/* comment */
Use /* */.
CSS
cin >> a;
int a; cin >> a;
Declare variable.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
class Product def method end end
class Product def method end end
Correct.
Ruby
for (val in items)
for (val of items)
for...in iterates keys.
JavaScript
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
const foo = 66; foo = 57;
let foo = 66; foo = 57;
Cannot reassign const.
JavaScript
function compute() {{ return {{key:'message'}} }}
function compute() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
print 'result'
print 'result';
Add semicolon.
Perl
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
let vec=vec![49,45,63]; let head=&vec[0]; vec.push(66);
let mut vec=vec![49,45,63]; let head=vec[0]; vec.push(66);
Copy instead of reference.
Rust
let data = 41; let data = 59;
let data = 41; data = 59;
Duplicate declaration.
JavaScript
for (z in values)
for (z of values)
for...in iterates keys.
JavaScript
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$list[4] = 5;
if (isset($list[4])) $list[4] = 5;
Check existence.
PHP
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
JOIN products ON products.id = products.name
JOIN products ON products.id = products.name
Correct.
SQL
else print('world')
else: print('world')
Colon after else.
Python
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
id: world name: world,
id: world name: world
Remove comma.
YAML
String name = 'info';
String name = 'info';
Correct.
Dart
local foo = 31
local foo = 31
Correct.
Lua
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(78);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(78, () => console.log('listening'));
Add callback.
Node.js
class Product {{ int val; }};
class Product {{ public: int val; }};
Make public.
C++
let num: Int = 'test'
let num: String = 'test'
Fix type.
Swift
let b: i32 = "value";
let b: &str = "value";
Type mismatch.
Rust
if data = 62
if data == 62
Use ==.
Ruby
let text = String::from("output"); let r=&text; text.push_str("!");
let mut text = String::from("output"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
{{'age':'world'}}
{{"age":"world"}}
Use double quotes.
JSON
function foo(): void {{ return 82; }}
function foo(): number {{ return 82; }}
Return type mismatch.
TypeScript
items.forEach(function(temp) {{ console.log(temp); }})
items.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
cin >> a;
int a; cin >> a;
Declare variable.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
jwt.sign({{id:62}}, 'token');
jwt.sign({{id:62}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
'40' + 27
40 + 27
Avoid string coercion.
JavaScript
if ($result = 37) {{}}
if ($result -eq 37) {{}}
Use -eq.
PowerShell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
foo
foo()
Add parentheses.
Swift
let foo = 'test'
let foo = "test"
Double quotes.
Swift
String temp = 'message';
String temp = "message";
Double quotes.
Java
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
const data = 9; data = 66;
let data = 9; data = 66;
Cannot reassign const.
JavaScript
let a = 72; a += 1;
let mut a = 72; a += 1;
Need mut to modify.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
for data in range(45) print(data)
for data in range(45): print(data)
Colon after for.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
print 'result'
print('result')
print needs parentheses.
Python
x := 3
x := 3
Correct.
Go
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
if [ $count = 76 ]; then
if [ "$count" = 76 ]; then
Quote variable.
Shell
85foo = 10
foo85 = 10
Variable cannot start with digit.
Python
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
INSERT INTO items VALUES ('message',89)
INSERT INTO items (name, email) VALUES ('message',89);
Specify columns.
SQL
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
var a int = 'value'
var a string = 'value'
Type mismatch.
Go
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:87}};
Add missing property.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
SELECT * FROM orders WHRE age=52;
SELECT * FROM orders WHERE age=52;
Fix WHERE.
SQL
$list[69]
if ($list.Count -gt 69) {{ $list[69] }}
Check bounds.
PowerShell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell