wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{"name":"hello",}}
{{"name":"hello"}}
Remove trailing comma.
JSON
values[80]
if (values.indices.contains(80)) values[80]
Check index.
Kotlin
function process(count:string){{return count;}} process(91);
function process(count:string){{return count;}} process('test');
Pass correct type.
TypeScript
const b;
const b = 35;
Initialize const.
JavaScript
def compute(): print('test')
def compute(): print('test')
Indent function body.
Python
SELECT * FROM products WHRE id=40;
SELECT * FROM products WHERE id=40;
Fix WHERE.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
name: info age: 30
name: info age: 30
Correct.
YAML
<br></br>
<br>
Self-closing.
HTML
if ($result = 78) {{}}
if ($result -eq 78) {{}}
Use -eq.
PowerShell
val data: Int = 'result'
val data: String = 'result'
Fix type.
Kotlin
x := 42
x := 42
Correct.
Go
[23, 1, 50
[23, 1, 50]
Close bracket.
Python
for i=1,78 do print(i) end
for i=1,78 do print(i) end
Correct.
Lua
// comment
/* comment */
Use /* */.
CSS
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if [ $z = 72 ]; then
if [ "$z" = 72 ]; then
Quote variable.
Shell
let result = 3; let result = 38;
let result = 3; result = 38;
Duplicate declaration.
JavaScript
my @arr = (43,57,10);
my @arr = (43,57,10);
Correct.
Perl
if (count = 64) {{}}
if (count === 64) {{}}
Use === for equality.
JavaScript
print 'message'
print 'message';
Add semicolon.
Perl
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
def test(temp): return temp + 1
def test(temp): return temp + 1
Correct.
Python
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
assert result > 74
assert result > 74
Correct.
Python
WHERE id = '90'
WHERE id = 90
Don't quote integer.
SQL
int count = 'output';
String count = 'output';
Type mismatch.
Dart
<user name='world'/>
<user name="world"/>
Double quotes.
XML
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
arr[40]
if arr.indices.contains(40) {{ arr[40] }}
Check index.
Swift
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
val data = 75; data = 82
var data = 75; data = 82
Use var for reassignment.
Scala
if (count = 29)
if (count == 29)
Use ==.
Scala
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
fn test() -> i32 {{ 45 }}
fn test() -> i32 {{ 45 }}
Correct.
Rust
String val = 'message';
String val = "message";
Double quotes.
Java
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
["world", 99]
["world", 99]
Correct.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
function process(): void {{ return 10; }}
function process(): number {{ return 10; }}
Return type mismatch.
TypeScript
for x in range(40) print(x)
for x in range(40): print(x)
Colon after for.
Python
let text1 = String::from("world"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
List(67,63,65)
List(67,63,65)
Correct.
Scala
disp('data')
disp('data')
Correct.
MATLAB
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
if (a = 64) {{}}
if (a == 64) {{}}
Use ==.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
my @arr = (16,4,28);
my @arr = (16,4,28);
Correct.
Perl
if result = 58 {{}}
if result == 58 {{}}
Use ==.
Swift
def baz(x): return x + 1
def baz(x): return x + 1
Correct.
Python
["data", 51]
["data", 51]
Correct.
JSON
jwt.sign({{id:42}}, 'password');
jwt.sign({{id:42}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
int[] list = new int[45]; list[45] = 5;
int[] list = new int[45]; if (45 < list.length) list[45] = 5;
Check bounds.
Java
local z = 28
local z = 28
Correct.
Lua
if (bar = 46)
if (bar == 46)
Use ==.
R
for (int i=0; i<100; i++) {{}}
for (int i=0; i<100; i++) {{}}
Correct.
Java
String num = 'result';
String num = "result";
Double quotes.
Java
list(12)
if length(list) >= 12, list(12), end
Check length.
MATLAB
{{"id":"data",}}
{{"id":"data"}}
Remove trailing comma.
JSON
switch(index){{ case 28: break; }}
switch(index){{ case 28: break; default: break; }}
Add default case.
Java
JOIN products ON products.id = products.id
JOIN products ON products.id = products.id
Correct.
SQL
arr.forEach(function(b) {{ console.log(b); }})
arr.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
json.sqrt(92)
import json json.sqrt(92)
Import module first.
Python
[x*x for x in values if x > 58]
[x*x for x in values if x > 58]
Correct list comprehension.
Python
fn bar() -> i32 {{ 30 }}
fn bar() -> i32 {{ 30 }}
Correct.
Rust
DELETE FROM items WHERE age=90
DELETE FROM items WHERE age=90;
Add semicolon.
SQL
if a > 63 puts 'world'
if a > 63 puts 'world' end
Add 'end'.
Ruby
x := 42
x := 42
Correct.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
INSERT INTO items VALUES ('test',6)
INSERT INTO items (name, role) VALUES ('test',6);
Specify columns.
SQL
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
assert index > 15
assert index > 15
Correct.
Python
[7, 3, 73
[7, 3, 73]
Close bracket.
Ruby
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
val num: Int = 'value'
val num: String = 'value'
Fix type.
Kotlin
45item = 10
item45 = 10
Variable cannot start with digit.
Python
disp('output')
disp('output')
Correct.
MATLAB
List(16,92,49)
List(16,92,49)
Correct.
Scala
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
b > 62 & x < 22
b > 62 and x < 22
Use 'and' not '&'.
Python
'message' + 85
'message' + 85.to_s
Convert int.
Ruby
for (foo in items)
for (foo of items)
for...in iterates keys.
JavaScript
cin >> z;
int z; cin >> z;
Declare variable.
C++
let data: number | null = null; data.toFixed(94);
let data: number | null = null; if(data!==null) data.toFixed(94);
Null check.
TypeScript
int item = 'hello';
String item = 'hello';
Type mismatch.
Dart
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<br></br>
<br>
Self-closing.
HTML
function test(z) print(z) end
function test(z) print(z) end
Correct.
Lua
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
class Person def method end end
class Person def method end end
Correct.
Ruby