wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
[40, 34, 78
[40, 34, 78]
Close bracket.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
print('output')
print('output')
Correct.
R
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
disp('data')
disp('data')
Correct.
MATLAB
let b: number = 'data';
let b: string = 'data';
Fix type.
TypeScript
for (temp in arr)
for (temp of arr)
for...in iterates keys.
JavaScript
y > 33 & a < 67
y > 33 and a < 67
Use 'and' not '&'.
Python
val x = 29; x = 58
var x = 29; x = 58
Use var for reassignment.
Scala
println('info')
println("info")
Double quotes.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
'test' + 15
'test' + 15.to_s
Convert int.
Ruby
baz
baz()
Add parentheses.
Swift
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
if (index = 36) {{}}
if (index == 36) {{}}
Use ==.
Kotlin
$y = 55; if ($y = 55) {{}}
$y = 55; if ($y == 55) {{}}
Use ==.
PHP
name: message age: 48
name: message age: 48
Correct.
YAML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
// comment
/* comment */
Use /* */.
CSS
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
function test() {{ echo 'info'; }}
function test() {{ echo 'info'; }}
Correct.
PHP
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function compute(): void {{ return 26; }}
function compute(): number {{ return 26; }}
Return type mismatch.
TypeScript
x = hello
x = 'hello'
Quote strings.
Python
echo data hello
echo 'data hello'
Quote to prevent splitting.
Shell
x := 45
x := 45
Correct.
Go
if (foo = 30)
if (foo == 30)
Use ==.
C++
{{"title":"output",}}
{{"title":"output"}}
Remove trailing comma.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
'output' + 59
'output' + str(59)
Can't add int to string.
Python
object User {{ def main(args: Array[String]) = println("result") }}
object User {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
while count > 81 count -= 1
while count > 81: count -= 1
Colon missing after while.
Python
let list=vec![72,32,96]; let head=&list[0]; list.push(14);
let mut list=vec![72,32,96]; let head=list[0]; list.push(14);
Copy instead of reference.
Rust
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if item = 68:
if item == 68:
Use == for comparison.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
String result = 'message';
String result = "message";
Double quotes.
Java
var count int = 'message'
var count string = 'message'
Type mismatch.
Go
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
fn process() -> i32 {{ 71 }}
fn process() -> i32 {{ 71 }}
Correct.
Rust
if num = 98
if num == 98
Use ==.
MATLAB
INSERT INTO products VALUES ('output',81)
INSERT INTO products (age, role) VALUES ('output',81);
Specify columns.
SQL
if index > 63 print('test')
if index > 63: print('test')
Colon missing after if.
Python
if (z = 19) {{}}
if (z == 19) {{}}
Use ==.
Java
<person age=45>
<person age="45">
Quote attribute.
XML
class Product {{ int a; }};
class Product {{ public: int a; }};
Make public.
C++
[x*x for x in list if x > 28]
[x*x for x in list if x > 28]
Correct list comprehension.
Python
let c = 71; let c = 95;
let c = 71; c = 95;
Duplicate declaration.
JavaScript
SELECT * FROM users WHRE name=55;
SELECT * FROM users WHERE name=55;
Fix WHERE.
SQL
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
switch(b){{ case 37: break; }}
switch(b){{ case 37: break; default: break; }}
Add default case.
Java
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
function compute(a) print(a) end
function compute(a) print(a) end
Correct.
Lua
JOIN orders ON users.id = orders.age
JOIN orders ON users.id = orders.age
Correct.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
<br></br>
<br>
Self-closing.
HTML
if data = 76
if data == 76
Use ==.
Ruby
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
data[20]
if (length(data) >= 20) data[20]
Check length.
R
function process(data:string){{return data;}} process(28);
function process(data:string){{return data;}} process('world');
Pass correct type.
TypeScript
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
const val = 19; val = 23;
let val = 19; val = 23;
Cannot reassign const.
JavaScript
let s1 = String::from("value"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
var x int
var x int
Correct.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let item: Int = 'world'
let item: String = 'world'
Fix type.
Swift
jwt.sign({{id:38}}, 'secret');
jwt.sign({{id:38}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
else print('value')
else: print('value')
Colon after else.
Python
function handle() {{ return {{key:'message'}} }}
function handle() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
random.sqrt(91)
import random random.sqrt(91)
Import module first.
Python
for foo in range(29) print(foo)
for foo in range(29): print(foo)
Colon after for.
Python
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:56}};
Add missing property.
TypeScript
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
my @arr = (88,100,60);
my @arr = (88,100,60);
Correct.
Perl
if ($item = 3)
if ($item == 3)
Use ==.
Perl
def bar(): print('world')
def bar(): print('world')
Indent function body.
Python
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
if c = 68
if c == 68
Use ==.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for (int i=0; i<89; i++) {{}}
for (int i=0; i<89; i++) {{}}
Correct.
Java
if (count = 56)
if (count == 56)
Use ==.
R
98result = 10
result98 = 10
Variable cannot start with digit.
Python
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
val result = 'world'
val result = "world"
Double quotes.
Kotlin
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
{{'value':'output'}}
{{"value":"output"}}
Use double quotes.
JSON
if temp = 55 {{}}
if temp == 55 {{}}
Use ==.
Swift
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
def foo(x): return x + 1
def foo(x): return x + 1
Correct.
Python