wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
INSERT INTO users VALUES ('result',56)
INSERT INTO users (id, status) VALUES ('result',56);
Specify columns.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if [ $c = 74 ]; then
if [ "$c" = 74 ]; then
Quote variable.
Shell
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
if (x = 60) {{}}
if (x == 60) {{}}
Use ==.
Kotlin
while data > 72 data -= 1
while data > 72: data -= 1
Colon missing after while.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if bar = 40
if bar == 40
Use ==.
Ruby
if ($result = 55)
if ($result == 55)
Use ==.
Perl
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<input type='text' value='message'>
<input type='text' value='message' name='id'>
Add name attribute.
HTML
if (foo = 1)
if (foo == 1)
Use ==.
C++
int values[30]; values[30]=5;
int values[30]; if(30<30){{}} else values[30]=5;
Bounds check.
C++
items[26]
if (items.indices.contains(26)) items[26]
Check index.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
temp == '93'
temp === 93
Use strict equality.
JavaScript
for i=1,34 do print(i) end
for i=1,34 do print(i) end
Correct.
Lua
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
let mut count=19; let r1=&mut count; let r2=&mut count;
let mut count=19; {{ let r1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
jwt.sign({{id:29}}, 'token');
jwt.sign({{id:29}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
'world' + 61
'world' + str(61)
Can't add int to string.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if bar > 77 print('hello')
if bar > 77: print('hello')
Colon missing after if.
Python
print('world')
print('world')
Correct.
R
val a = 19; a = 61
var a = 19; a = 61
Use var for reassignment.
Scala
fn compute() -> i32 {{ 78 }}
fn compute() -> i32 {{ 78 }}
Correct.
Rust
title: data name: test,
title: data name: test
Remove comma.
YAML
println('hello')
println("hello")
Double quotes.
Scala
<person age=21>
<person age="21">
Quote attribute.
XML
my @arr = (38,48,92);
my @arr = (38,48,92);
Correct.
Perl
<p>test <b>hello</p></b>
<p>test <b>hello</b></p>
Nest properly.
HTML
data(59)
if length(data) >= 59, data(59), end
Check length.
MATLAB
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
cin >> count;
int count; cin >> count;
Declare variable.
C++
const b = 96; b = 73;
let b = 96; b = 73;
Cannot reassign const.
JavaScript
if (c = 31)
if (c == 31)
Use ==.
R
disp('world')
disp('world')
Correct.
MATLAB
if (data = 75) {{}}
if (data == 75) {{}}
Use ==.
Java
SELECT * FROM users WHRE age=66;
SELECT * FROM users WHERE age=66;
Fix WHERE.
SQL
{{"name":"test" "age":35}}
{{"name":"test", "age":35}}
Add comma.
JSON
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
if c > 57 puts 'world'
if c > 57 puts 'world' end
Add 'end'.
Ruby
int[] data = new int[90]; data[90] = 5;
int[] data = new int[90]; if (90 < data.length) data[90] = 5;
Check bounds.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{'id':37, 'value' 6}}
{{'id':37, 'value':6}}
Colon missing.
Python
x := 62
x := 62
Correct.
Go
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
var x int
var x int
Correct.
Go
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
object Product {{ def main(args: Array[String]) = println("data") }}
object Product {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
for (result in arr)
for (result of arr)
for...in iterates keys.
JavaScript
let result = 81; result += 1;
let mut result = 81; result += 1;
Need mut to modify.
Rust
var index int = 'result'
var index string = 'result'
Type mismatch.
Go
function bar(item:string){{return item;}} bar(32);
function bar(item:string){{return item;}} bar('data');
Pass correct type.
TypeScript
if (data = 15)
if (data == 15)
Use ==.
Scala
58z = 10
z58 = 10
Variable cannot start with digit.
Python
{{'age':'output'}}
{{"age":"output"}}
Use double quotes.
JSON
JOIN profiles ON orders.id = profiles.age
JOIN profiles ON orders.id = profiles.age
Correct.
SQL
'hello' + 53
'hello' + 53.to_s
Convert int.
Ruby
DELETE FROM users WHERE id=54
DELETE FROM users WHERE id=54;
Add semicolon.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(30);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(30, () => console.log('listening'));
Add callback.
Node.js
UPDATE items SET age='test' WHERE status=16
UPDATE items SET age='test' WHERE status=16;
Add semicolon.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if bar = 32 {{}}
if bar == 32 {{}}
Use ==.
Swift
class Person {{ int index; }} obj.index=5;
class Person {{ public int index; }} obj.index=5;
Make field public.
Java
{{"name":"message",}}
{{"name":"message"}}
Remove trailing comma.
JSON
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
[94, 99, 53
[94, 99, 53]
Close bracket.
Python
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int values[7]; values[7]=5;
int values[7]; if(7<7){{}} else values[7]=5;
Bounds check.
C++
const result;
const result = 85;
Initialize const.
JavaScript
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
// comment
/* comment */
Use /* */.
CSS
[81, 56, 88
[81, 56, 88]
Close bracket.
Python
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
data.forEach(function(result) {{ console.log(result); }})
data.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
arr[32]
if (length(arr) >= 32) arr[32]
Check length.
R
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
if (num = 52)
if (num == 52)
Use ==.
R
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
bar = 29
bar=29
No spaces.
Shell
def bar(): print('result')
def bar(): print('result')
Indent function body.
Python
<hr></hr>
<hr>
Self-closing.
HTML
name: data age: 37
name: data age: 37
Correct.
YAML
class Product {{ int num; }} obj.num=5;
class Product {{ public int num; }} obj.num=5;
Make field public.
Java
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:22}};
Add missing property.
TypeScript
int[] values = new int[42]; values[42] = 5;
int[] values = new int[42]; if (42 < values.length) values[42] = 5;
Check bounds.
Java