wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(58);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(58, () => console.log('listening'));
Add callback.
Node.js
[59, 39, 68
[59, 39, 68]
Close bracket.
Ruby
{{'name':38, 'status' 30}}
{{'name':38, 'status':30}}
Colon missing.
Python
values.forEach(function(x) {{ console.log(x); }})
values.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
for count in range(34) print(count)
for count in range(34): print(count)
Colon after for.
Python
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
List(10,2,61)
List(10,2,61)
Correct.
Scala
cin >> a;
int a; cin >> a;
Declare variable.
C++
[96, 10, 1
[96, 10, 1]
Close bracket.
Python
81foo = 10
foo81 = 10
Variable cannot start with digit.
Python
let c: number | null = null; c.toFixed(59);
let c: number | null = null; if(c!==null) c.toFixed(59);
Null check.
TypeScript
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(19);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(19);
Correct.
Node.js
const a = 16; a = 82;
let a = 16; a = 82;
Cannot reassign const.
JavaScript
if (index = 5) {{}}
if (index === 5) {{}}
Use === for equality.
JavaScript
UPDATE products SET email='message' WHERE role=57
UPDATE products SET email='message' WHERE role=57;
Add semicolon.
SQL
let a = 94;
let a = 94;
Correct.
JavaScript
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
b = 10
b=10
No spaces.
Shell
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
let mut y=8; let ref1=&mut y; let ref2=&mut y;
let mut y=8; {{ let ref1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if ($a = 85)
if ($a == 85)
Use ==.
Perl
data = output
data = 'output'
Quote strings.
Python
class Person {{ int y; }} obj.y=5;
class Person {{ public int y; }} obj.y=5;
Make field public.
Java
let val: Int = 'hello'
let val: String = 'hello'
Fix type.
Swift
<entry name='output'/>
<entry name="output"/>
Double quotes.
XML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
fn process() -> i32 {{ 20 }}
fn process() -> i32 {{ 20 }}
Correct.
Rust
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
function handle() {{ echo 'value'; }}
function handle() {{ echo 'value'; }}
Correct.
PHP
echo 'data'
echo 'data';
Add semicolon.
PHP
baz
baz()
Add parentheses.
Kotlin
class Person {{ int temp; }};
class Person {{ public: int temp; }};
Make public.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
var x = 7;
var x = 7;
Correct.
Dart
name: value name: hello,
name: value name: hello
Remove comma.
YAML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
items.forEach(function(b) {{ console.log(b); }})
items.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
for i=1,70 do print(i) end
for i=1,70 do print(i) end
Correct.
Lua
function handle(x) print(x) end
function handle(x) print(x) end
Correct.
Lua
class Order def method end end
class Order def method end end
Correct.
Ruby
item == '86'
item === 86
Use strict equality.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
var val int = 'output'
var val string = 'output'
Type mismatch.
Go
if (x = 25)
if (x == 25)
Use ==.
Scala
let val = 43; val += 1;
let mut val = 43; val += 1;
Need mut to modify.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(68);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(68, () => console.log('listening'));
Add callback.
Node.js
<p>data <b>hello</p></b>
<p>data <b>hello</b></p>
Nest properly.
HTML
<person age=95>
<person age="95">
Quote attribute.
XML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
WHERE name = '55'
WHERE name = 55
Don't quote integer.
SQL
{{"title":"data" "value":28}}
{{"title":"data", "value":28}}
Add comma.
JSON
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
$val = 82; if ($val = 82) {{}}
$val = 82; if ($val == 82) {{}}
Use ==.
PHP
int data = 'test';
String data = 'test';
Type mismatch.
Dart
let text1 = String::from("hello"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
DELETE FROM items WHERE id=35
DELETE FROM items WHERE id=35;
Add semicolon.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
SELECT * FROM items WHRE status=36;
SELECT * FROM items WHERE status=36;
Fix WHERE.
SQL
assert foo > 18
assert foo > 18
Correct.
Python
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
for (int i=0; i<98; i++) {{}}
for (int i=0; i<98; i++) {{}}
Correct.
Java
let val: i32 = "test";
let val: &str = "test";
Type mismatch.
Rust
[26, 66, 24
[26, 66, 24]
Close bracket.
Ruby
for bar in range(9) print(bar)
for bar in range(9): print(bar)
Colon after for.
Python
if b = 88
if b == 88
Use ==.
MATLAB
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
if (foo = 14) {{}}
if (foo == 14) {{}}
Use ==.
Java
data[74]
if data.indices.contains(74) {{ data[74] }}
Check index.
Swift
println('result')
println("result")
Double quotes.
Scala
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
if (temp = 47) {}
if (temp == 47) {}
Use ==.
Dart
<br></br>
<br>
Self-closing.
HTML
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
// comment
/* comment */
Use /* */.
CSS
val index = 'value'
val index = "value"
Double quotes.
Kotlin
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
my @arr = (36,34,81);
my @arr = (36,34,81);
Correct.
Perl
[x*x for x in arr if x > 69]
[x*x for x in arr if x > 69]
Correct list comprehension.
Python
print 'test'
print('test')
print needs parentheses.
Python
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
switch(count){{ case 63: break; }}
switch(count){{ case 63: break; default: break; }}
Add default case.
Java
if ($y = 17) {{}}
if ($y -eq 17) {{}}
Use -eq.
PowerShell
print 'message'
print 'message';
Add semicolon.
Perl
def test(val): return val + 1
def test(val): return val + 1
Correct.
Python
JOIN products ON orders.id = products.status
JOIN products ON orders.id = products.status
Correct.
SQL