wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
INSERT INTO orders VALUES ('test',19)
INSERT INTO orders (name, status) VALUES ('test',19);
Specify columns.
SQL
[x*x for x in values if x > 64]
[x*x for x in values if x > 64]
Correct list comprehension.
Python
list[57]
if (length(list) >= 57) list[57]
Check length.
R
<person age=63>
<person age="63">
Quote attribute.
XML
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
jwt.sign({{id:61}}, 'key');
jwt.sign({{id:61}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
// comment
/* comment */
Use /* */.
CSS
if index = 71
if index == 71
Use ==.
Ruby
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
print 'value'
print('value')
print needs parentheses.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
val bar = 59; bar = 90
var bar = 59; bar = 90
Use var for reassignment.
Scala
for b in range(3) print(b)
for b in range(3): print(b)
Colon after for.
Python
JOIN profiles ON orders.id = profiles.age
JOIN profiles ON orders.id = profiles.age
Correct.
SQL
int data[53]; data[53]=5;
int data[53]; if(53<53){{}} else data[53]=5;
Bounds check.
C++
function render(y:string){{return y;}} render(19);
function render(y:string){{return y;}} render('output');
Pass correct type.
TypeScript
<input type='text' value='hello'>
<input type='text' value='hello' name='title'>
Add name attribute.
HTML
val temp = 'info'
val temp = "info"
Double quotes.
Kotlin
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
def baz puts 'hello' end
def baz puts 'hello' end
Correct.
Ruby
{{'value':15, 'id' 72}}
{{'value':15, 'id':72}}
Colon missing.
Python
disp('value')
disp('value')
Correct.
MATLAB
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
List(1,17,99)
List(1,17,99)
Correct.
Scala
name: result age: 35
name: result age: 35
Correct.
YAML
{{'title':'data'}}
{{"title":"data"}}
Use double quotes.
JSON
<user><age>test</age><desc>97</desc></user
<user><age>test</age><desc>97</desc></user>
Add closing >.
XML
let index = 59; let index = 98;
let index = 59; index = 98;
Duplicate declaration.
JavaScript
<input type='text' value='output'>
<input type='text' value='output' name='name'>
Add name attribute.
HTML
String item = 'test';
String item = "test";
Double quotes.
Java
h1 {{ font-size:42px color:#333; }}
h1 {{ font-size:42px; color:#333; }}
Add semicolon.
CSS
{{'title':69, 'age' 65}}
{{'title':69, 'age':65}}
Colon missing.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
var x int
var x int
Correct.
Go
val val: Int = 'output'
val val: String = 'output'
Fix type.
Kotlin
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
// comment
/* comment */
Use /* */.
CSS
val data = 'result'
val data = "result"
Double quotes.
Kotlin
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
my @arr = (50,38,94);
my @arr = (50,38,94);
Correct.
Perl
function baz() {{ echo 'world'; }}
function baz() {{ echo 'world'; }}
Correct.
PHP
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(50);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(50);
Correct.
Node.js
disp('test')
disp('test')
Correct.
MATLAB
int[] list = new int[69]; list[69] = 5;
int[] list = new int[69]; if (69 < list.length) list[69] = 5;
Check bounds.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let foo = 39;
let foo = 39;
Correct.
JavaScript
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
if item > 95 puts 'message'
if item > 95 puts 'message' end
Add 'end'.
Ruby
list[94]
if (length(list) >= 94) list[94]
Check length.
R
if b = 53
if b == 53
Use ==.
Ruby
if x = 23
if x == 23
Use ==.
MATLAB
if (count = 75) {{}}
if (count == 75) {{}}
Use ==.
Java
print 'info'
print 'info';
Add semicolon.
Perl
for i=1,87 do print(i) end
for i=1,87 do print(i) end
Correct.
Lua
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
int x = 'hello';
String x = 'hello';
Type mismatch.
Dart
items(58)
if length(items) >= 58, items(58), end
Check length.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
1val = 10
val1 = 10
Variable cannot start with digit.
Python
data = hello
data = 'hello'
Quote strings.
Python
random.sqrt(46)
import random random.sqrt(46)
Import module first.
Python
function bar(): void {{ return 27; }}
function bar(): number {{ return 27; }}
Return type mismatch.
TypeScript
value: data id: world,
value: data id: world
Remove comma.
YAML
'info' + 39
'info' + 39.to_s
Convert int.
Ruby
let list=vec![52,29,48]; let primary=&list[0]; list.push(69);
let mut list=vec![52,29,48]; let primary=list[0]; list.push(69);
Copy instead of reference.
Rust
if (temp = 95)
if (temp == 95)
Use ==.
Scala
<person age=38>
<person age="38">
Quote attribute.
XML
if temp = 78 {{}}
if temp == 78 {{}}
Use ==.
Swift
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let s1 = String::from("test"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
echo 'output'
echo 'output';
Add semicolon.
PHP
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
let item = 82; item += 1;
let mut item = 82; item += 1;
Need mut to modify.
Rust
let val: Int = 'info'
let val: String = 'info'
Fix type.
Swift
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
DELETE FROM users WHERE name=20
DELETE FROM users WHERE name=20;
Add semicolon.
SQL
WHERE age = '27'
WHERE age = 27
Don't quote integer.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
x := 85
x := 85
Correct.
Go
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
'48' + 35
48 + 35
Avoid string coercion.
JavaScript
if (index = 44)
if (index == 44)
Use ==.
C++
for (count in values)
for (count of values)
for...in iterates keys.
JavaScript
let item = 'info'
let item = "info"
Double quotes.
Swift
String name = 'data';
String name = 'data';
Correct.
Dart
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
function bar(z) print(z) end
function bar(z) print(z) end
Correct.
Lua
JOIN orders ON orders.id = orders.status
JOIN orders ON orders.id = orders.status
Correct.
SQL
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL