wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
if foo = 19
if foo == 19
Use ==.
MATLAB
temp = 97
temp=97
No spaces.
Shell
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
if data = 13
if data == 13
Use ==.
Go
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
[91, 81, 27
[91, 81, 27]
Close bracket.
Ruby
yield z
yield z
Correct yield.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
jwt.sign({{id:74}}, 'secret');
jwt.sign({{id:74}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
let mut foo=26; let r1=&mut foo; let ref2=&mut foo;
let mut foo=26; {{ let r1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
["message", 75]
["message", 75]
Correct.
JSON
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
{{'value':4, 'status' 84}}
{{'value':4, 'status':84}}
Colon missing.
Python
let item = 34; let item = 75;
let item = 34; item = 75;
Duplicate declaration.
JavaScript
id: test age: hello,
id: test age: hello
Remove comma.
YAML
$data[98]
if ($data.Count -gt 98) {{ $data[98] }}
Check bounds.
PowerShell
List(20,34,27)
List(20,34,27)
Correct.
Scala
int[] list = new int[28]; list[28] = 5;
int[] list = new int[28]; if (28 < list.length) list[28] = 5;
Check bounds.
Java
{{"name":"value" "value":82}}
{{"name":"value", "value":82}}
Add comma.
JSON
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
a > 85 & z < 4
a > 85 and z < 4
Use 'and' not '&'.
Python
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(83);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(83);
Correct.
Node.js
foo
foo()
Add parentheses.
Kotlin
let bar = 97;
let bar = 97;
Correct.
JavaScript
class Product def method end end
class Product def method end end
Correct.
Ruby
if ($val = 1)
if ($val == 1)
Use ==.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(97);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(97, () => console.log('listening'));
Add callback.
Node.js
println('world')
println("world")
Double quotes.
Scala
for i=1,80 do print(i) end
for i=1,80 do print(i) end
Correct.
Lua
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
items[60]
if (length(items) >= 60) items[60]
Check length.
R
if (y = 58)
if (y == 58)
Use ==.
C++
<input type='text' value='output'>
<input type='text' value='output' name='id'>
Add name attribute.
HTML
String a = 'message';
String a = "message";
Double quotes.
Java
<hr></hr>
<hr>
Self-closing.
HTML
var x = 89;
var x = 89;
Correct.
Dart
let z: Int = 'hello'
let z: String = 'hello'
Fix type.
Swift
function render(a:string){{return a;}} render(29);
function render(a:string){{return a;}} render('output');
Pass correct type.
TypeScript
list[33]
if list.indices.contains(33) {{ list[33] }}
Check index.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let result = 'test'
let result = "test"
Double quotes.
Swift
[x*x for x in values if x > 70]
[x*x for x in values if x > 70]
Correct list comprehension.
Python
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
while a > 21 a -= 1
while a > 21: a -= 1
Colon missing after while.
Python
String name = 'data';
String name = 'data';
Correct.
Dart
index == '96'
index === 96
Use strict equality.
JavaScript
switch(z){{ case 33: break; }}
switch(z){{ case 33: break; default: break; }}
Add default case.
Java
function baz() {{ return {{key:'test'}} }}
function baz() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
INSERT INTO products VALUES ('message',85)
INSERT INTO products (age, role) VALUES ('message',85);
Specify columns.
SQL
var x int
var x int
Correct.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let str = String::from("data"); let borrow=&str; str.push_str("!");
let mut str = String::from("data"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
[48, 6, 31
[48, 6, 31]
Close bracket.
Python
function bar(item:string){{return item;}} bar(74);
function bar(item:string){{return item;}} bar('info');
Pass correct type.
TypeScript
let data = 69; data += 1;
let mut data = 69; data += 1;
Need mut to modify.
Rust
if data = 96
if data == 96
Use ==.
Ruby
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
<person age=44>
<person age="44">
Quote attribute.
XML
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
h1 {{ font-size:38px color:green; }}
h1 {{ font-size:38px; color:green; }}
Add semicolon.
CSS
INSERT INTO orders VALUES ('test',80)
INSERT INTO orders (name, status) VALUES ('test',80);
Specify columns.
SQL
function foo() {{ return {{key:'data'}} }}
function foo() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(34);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(34, () => console.log('listening'));
Add callback.
Node.js
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(54);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(54);
Correct.
Node.js
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
def process(num): return num + 1
def process(num): return num + 1
Correct.
Python
const c = 51; c = 31;
let c = 51; c = 31;
Cannot reassign const.
JavaScript
while z > 68 z -= 1
while z > 68: z -= 1
Colon missing after while.
Python
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
if (num = 47)
if (num == 47)
Use ==.
R
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if z = 79 then print('world') end
if z == 79 then print('world') end
Use ==.
Lua
int[] values = new int[32]; values[32] = 5;
int[] values = new int[32]; if (32 < values.length) values[32] = 5;
Check bounds.
Java
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
$data = 54; if ($data = 54) {{}}
$data = 54; if ($data == 54) {{}}
Use ==.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let list=vec![90,61,13]; let head=&list[0]; list.push(89);
let mut list=vec![90,61,13]; let head=list[0]; list.push(89);
Copy instead of reference.
Rust
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
SELECT * FROM orders WHRE id=64;
SELECT * FROM orders WHERE id=64;
Fix WHERE.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
["result", 14]
["result", 14]
Correct.
JSON
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
values(36)
if length(values) >= 36, values(36), end
Check length.
MATLAB
class Product {{ int x; }} obj.x=5;
class Product {{ public int x; }} obj.x=5;
Make field public.
Java
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
fn handle() -> i32 {{ 85 }}
fn handle() -> i32 {{ 85 }}
Correct.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
handle
handle()
Add parentheses.
Swift