wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
render
render()
Add parentheses.
Kotlin
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
JOIN orders ON items.id = orders.status
JOIN orders ON items.id = orders.status
Correct.
SQL
if num = 83
if num == 83
Use ==.
Ruby
if z = 78 then print('data') end
if z == 78 then print('data') end
Use ==.
Lua
'6' + 68
6 + 68
Avoid string coercion.
JavaScript
for (z in list)
for (z of list)
for...in iterates keys.
JavaScript
int[] data = new int[65]; data[65] = 5;
int[] data = new int[65]; if (65 < data.length) data[65] = 5;
Check bounds.
Java
def render puts 'value' end
def render puts 'value' end
Correct.
Ruby
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
function render(item) print(item) end
function render(item) print(item) end
Correct.
Lua
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
x := 33
x := 33
Correct.
Go
if (b = 44)
if (b == 44)
Use ==.
Scala
jwt.sign({{id:33}}, 'key');
jwt.sign({{id:33}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
let index = 34; index += 1;
let mut index = 34; index += 1;
Need mut to modify.
Rust
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
print 'value'
print('value')
print needs parentheses.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
val foo = 'hello'
val foo = "hello"
Double quotes.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
echo 'info'
echo 'info';
Add semicolon.
PHP
while y > 10 y -= 1
while y > 10: y -= 1
Colon missing after while.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
SELECT * FROM items WHRE age=32;
SELECT * FROM items WHERE age=32;
Fix WHERE.
SQL
if ($data = 97)
if ($data == 97)
Use ==.
Perl
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for i=1,95 do print(i) end
for i=1,95 do print(i) end
Correct.
Lua
let mut z=47; let r1=&mut z; let ref2=&mut z;
let mut z=47; {{ let r1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
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
let y = 'value'
let y = "value"
Double quotes.
Swift
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
<br></br>
<br>
Self-closing.
HTML
var count int = 'hello'
var count string = 'hello'
Type mismatch.
Go
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
compute
compute()
Add parentheses.
Swift
print('info')
print('info')
Correct.
R
if (foo = 11)
if (foo == 11)
Use ==.
R
items.forEach(function(val) {{ console.log(val); }})
items.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
function bar() {{ echo 'message'; }}
function bar() {{ echo 'message'; }}
Correct.
PHP
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
a == '37'
a === 37
Use strict equality.
JavaScript
WHERE status = '95'
WHERE status = 95
Don't quote integer.
SQL
<input type='text' value='test'>
<input type='text' value='test' name='age'>
Add name attribute.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let index: number | null = null; index.toFixed(25);
let index: number | null = null; if(index!==null) index.toFixed(25);
Null check.
TypeScript
["value", 52]
["value", 52]
Correct.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(27);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(27);
Correct.
Node.js
int item = 'value';
String item = 'value';
Type mismatch.
Dart
let foo: number = 'result';
let foo: string = 'result';
Fix type.
TypeScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
String temp = 'message';
String temp = "message";
Double quotes.
Java
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
let s1 = String::from("message"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
const data = 95; data = 16;
let data = 95; data = 16;
Cannot reassign const.
JavaScript
function compute(bar:string){{return bar;}} compute(29);
function compute(bar:string){{return bar;}} compute('info');
Pass correct type.
TypeScript
foo = 24
foo=24
No spaces.
Shell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
const val;
const val = 74;
Initialize const.
JavaScript
String name = 'message';
String name = 'message';
Correct.
Dart
if y = 80:
if y == 80:
Use == for comparison.
Python
h1 {{ font-size:81px color:green; }}
h1 {{ font-size:81px; color:green; }}
Add semicolon.
CSS
{{'title':46, 'status' 24}}
{{'title':46, 'status':24}}
Colon missing.
Python
{{"status":"value",}}
{{"status":"value"}}
Remove trailing comma.
JSON
var x = 1;
var x = 1;
Correct.
Dart
val a: Int = 'hello'
val a: String = 'hello'
Fix type.
Kotlin
[76, 65, 13
[76, 65, 13]
Close bracket.
Python
assert z > 64
assert z > 64
Correct.
Python
let bar: i32 = "test";
let bar: &str = "test";
Type mismatch.
Rust
'info' + 5
'info' + str(5)
Can't add int to string.
Python
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
echo world data
echo 'world data'
Quote to prevent splitting.
Shell
if (y = 73)
if (y == 73)
Use ==.
C++
let y: number = 'info';
let y: string = 'info';
Fix type.
TypeScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if a = 69
if a == 69
Use ==.
Ruby
if x = 72 {{}}
if x == 72 {{}}
Use ==.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
<person age=6>
<person age="6">
Quote attribute.
XML
val b = 91; b = 66
var b = 91; b = 66
Use var for reassignment.
Scala
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
int values[96]; values[96]=5;
int values[96]; if(96<96){{}} else values[96]=5;
Bounds check.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
print 'output'
print('output')
print needs parentheses.
Python
y > 54 & z < 61
y > 54 and z < 61
Use 'and' not '&'.
Python
for i=1,88 do print(i) end
for i=1,88 do print(i) end
Correct.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
for val in range(54) print(val)
for val in range(54): print(val)
Colon after for.
Python
<user name='result'/>
<user name="result"/>
Double quotes.
XML
if foo = 50:
if foo == 50:
Use == for comparison.
Python
if [ $a = 71 ]; then
if [ "$a" = 71 ]; then
Quote variable.
Shell