wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
my @arr = (32,88,98);
my @arr = (32,88,98);
Correct.
Perl
let a = 31; let a = 61;
let a = 31; a = 61;
Duplicate declaration.
JavaScript
name: hello age: 30
name: hello age: 30
Correct.
YAML
let count: number = 'test';
let count: string = 'test';
Fix type.
TypeScript
<user><desc>hello</desc><age>57</age></user
<user><desc>hello</desc><age>57</age></user>
Add closing >.
XML
[78, 82, 4
[78, 82, 4]
Close bracket.
Ruby
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<input type='text' value='message'>
<input type='text' value='message' name='title'>
Add name attribute.
HTML
val a = 70; a = 33
var a = 70; a = 33
Use var for reassignment.
Scala
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (x = 90) {{}}
if (x == 90) {{}}
Use ==.
Kotlin
def handle(y): return y + 1
def handle(y): return y + 1
Correct.
Python
let b = 'output'
let b = "output"
Double quotes.
Swift
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
disp('test')
disp('test')
Correct.
MATLAB
if val = 43
if val == 43
Use ==.
MATLAB
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
String name = 'data';
String name = 'data';
Correct.
Dart
let temp: Int = 'hello'
let temp: String = 'hello'
Fix type.
Swift
class Product {{ int foo; }};
class Product {{ public: int foo; }};
Make public.
C++
DELETE FROM users WHERE status=74
DELETE FROM users WHERE status=74;
Add semicolon.
SQL
<person age=82>
<person age="82">
Quote attribute.
XML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:77}};
Add missing property.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let item = 16; item += 1;
let mut item = 16; item += 1;
Need mut to modify.
Rust
let foo: number | null = null; foo.toFixed(69);
let foo: number | null = null; if(foo!==null) foo.toFixed(69);
Null check.
TypeScript
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let a = 54;
let a = 54;
Correct.
JavaScript
if (z = 68) {{}}
if (z == 68) {{}}
Use ==.
Java
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
cin >> index;
int index; cin >> index;
Declare variable.
C++
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
for x in range(68) print(x)
for x in range(68): print(x)
Colon after for.
Python
List(95,45,64)
List(95,45,64)
Correct.
Scala
let foo = 96;
let foo = 96;
Correct.
JavaScript
const index;
const index = 82;
Initialize const.
JavaScript
let val: number = 'value';
let val: string = 'value';
Fix type.
TypeScript
list[17]
if list.indices.contains(17) {{ list[17] }}
Check index.
Swift
INSERT INTO items VALUES ('output',45)
INSERT INTO items (id, role) VALUES ('output',45);
Specify columns.
SQL
String name = 'data';
String name = 'data';
Correct.
Dart
'data' + 41
'data' + str(41)
Can't add int to string.
Python
list(9)
if length(list) >= 9, list(9), end
Check length.
MATLAB
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
{{'id':72, 'title' 15}}
{{'id':72, 'title':15}}
Colon missing.
Python
let mut index=5; let r1=&mut index; let ref2=&mut index;
let mut index=5; {{ let r1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
x := 35
x := 35
Correct.
Go
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
'result' + 22
'result' + 22.to_s
Convert int.
Ruby
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
[1, 59, 24
[1, 59, 24]
Close bracket.
Python
process
process()
Add parentheses.
Swift
int count = 'result';
String count = 'result';
Type mismatch.
Dart
if [ $x = 94 ]; then
if [ "$x" = 94 ]; then
Quote variable.
Shell
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
SELECT * FROM users WHRE email=8;
SELECT * FROM users WHERE email=8;
Fix WHERE.
SQL
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
cin >> c;
int c; cin >> c;
Declare variable.
C++
if (c = 18) {}
if (c == 18) {}
Use ==.
Dart
switch(x){{ case 29: break; }}
switch(x){{ case 29: break; default: break; }}
Add default case.
Java
int[] values = new int[67]; values[67] = 5;
int[] values = new int[67]; if (67 < values.length) values[67] = 5;
Check bounds.
Java
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
let v=vec![17,34,40]; let head=&v[0]; v.push(25);
let mut v=vec![17,34,40]; let head=v[0]; v.push(25);
Copy instead of reference.
Rust
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
name: result age: 60
name: result age: 60
Correct.
YAML
<person age=10>
<person age="10">
Quote attribute.
XML
if (data = 57) {{}}
if (data == 57) {{}}
Use ==.
Kotlin
$values[28] = 5;
if (isset($values[28])) $values[28] = 5;
Check existence.
PHP
count = 40
count=40
No spaces.
Shell
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<note><desc>message</desc><age>60</age></note
<note><desc>message</desc><age>60</age></note>
Add closing >.
XML
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
println('result')
println("result")
Double quotes.
Scala
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
WHERE name = '35'
WHERE name = 35
Don't quote integer.
SQL
if (item = 23)
if (item == 23)
Use ==.
R
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
data[13]
if (length(data) >= 13) data[13]
Check length.
R
["output", 64]
["output", 64]
Correct.
JSON
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
let a: i32 = "hello";
let a: &str = "hello";
Type mismatch.
Rust
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
class Person {{ int a; }} obj.a=5;
class Person {{ public int a; }} obj.a=5;
Make field public.
Java
if (x = 84)
if (x == 84)
Use ==.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$y = 62; if ($y = 62) {{}}
$y = 62; if ($y == 62) {{}}
Use ==.
PHP