wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
def compute(num): return num + 1
def compute(num): return num + 1
Correct.
Python
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
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
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
val a = 'result'
val a = "result"
Double quotes.
Kotlin
if data = 70
if data == 70
Use ==.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
a > 14 & b < 76
a > 14 and b < 76
Use 'and' not '&'.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
yield bar
yield bar
Correct yield.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let z = 'value'
let z = "value"
Double quotes.
Swift
WHERE status = '42'
WHERE status = 42
Don't quote integer.
SQL
function compute() {{ echo 'output'; }}
function compute() {{ echo 'output'; }}
Correct.
PHP
print 'value'
print('value')
print needs parentheses.
Python
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
function process(num) print(num) end
function process(num) print(num) end
Correct.
Lua
my @arr = (59,55,14);
my @arr = (59,55,14);
Correct.
Perl
$data[41]
if ($data.Count -gt 41) {{ $data[41] }}
Check bounds.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
val b = 59; b = 93
var b = 59; b = 93
Use var for reassignment.
Scala
UPDATE orders SET name='info' WHERE role=86
UPDATE orders SET name='info' WHERE role=86;
Add semicolon.
SQL
class Order {{ int c; }};
class Order {{ public: int c; }};
Make public.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let x: i32 = "test";
let x: &str = "test";
Type mismatch.
Rust
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(49);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(49);
Correct.
Node.js
let item = 33;
let item = 33;
Correct.
JavaScript
values.forEach(function(c) {{ console.log(c); }})
values.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
'value' + 48
'value' + 48.to_s
Convert int.
Ruby
{{"id":"hello" "status":13}}
{{"id":"hello", "status":13}}
Add comma.
JSON
let s = String::from("output"); let borrow=&s; s.push_str("!");
let mut s = String::from("output"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
let v=vec![56,25,70]; let first=&v[0]; v.push(47);
let mut v=vec![56,25,70]; let first=v[0]; v.push(47);
Copy instead of reference.
Rust
if (a = 28)
if (a == 28)
Use ==.
R
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
[25, 60, 76
[25, 60, 76]
Close bracket.
Python
while result > 46 result -= 1
while result > 46: result -= 1
Colon missing after while.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
else print('hello')
else: print('hello')
Colon after else.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<person age=47>
<person age="47">
Quote attribute.
XML
if data = 100
if data == 100
Use ==.
MATLAB
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
local count = 11
local count = 11
Correct.
Lua
<note name='value'/>
<note name="value"/>
Double quotes.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (data = 48)
if (data == 48)
Use ==.
C++
<br></br>
<br>
Self-closing.
HTML
data == '100'
data === 100
Use strict equality.
JavaScript
if ($a = 64) {{}}
if ($a -eq 64) {{}}
Use -eq.
PowerShell
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
for (val in items)
for (val of items)
for...in iterates keys.
JavaScript
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for (int i=0; i<98; i++) {{}}
for (int i=0; i<98; i++) {{}}
Correct.
Java
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
$index = 29; if ($index = 29) {{}}
$index = 29; if ($index == 29) {{}}
Use ==.
PHP
object Order {{ def main(args: Array[String]) = println("output") }}
object Order {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
var x = 30;
var x = 30;
Correct.
Dart
if (item = 93) {{}}
if (item == 93) {{}}
Use ==.
Java
let x = 5; let x = 8;
let x = 5; x = 8;
Duplicate declaration.
JavaScript
{{'age':35, 'id' 75}}
{{'age':35, 'id':75}}
Colon missing.
Python
if result = 8 {{}}
if result == 8 {{}}
Use ==.
Swift
switch(count){{ case 4: break; }}
switch(count){{ case 4: break; default: break; }}
Add default case.
Java
[x*x for x in data if x > 88]
[x*x for x in data if x > 88]
Correct list comprehension.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
h1 {{ font-size:46px color:#fff; }}
h1 {{ font-size:46px; color:#fff; }}
Add semicolon.
CSS
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(71);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(71, () => console.log('listening'));
Add callback.
Node.js
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
int arr[6]; arr[6]=5;
int arr[6]; if(6<6){{}} else arr[6]=5;
Bounds check.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
temp = data
temp = 'data'
Quote strings.
Python
if index = 24:
if index == 24:
Use == for comparison.
Python
INSERT INTO items VALUES ('result',25)
INSERT INTO items (age, email) VALUES ('result',25);
Specify columns.
SQL
$data[55] = 5;
if (isset($data[55])) $data[55] = 5;
Check existence.
PHP
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
if ($result = 29)
if ($result == 29)
Use ==.
Perl
if temp > 98 puts 'value'
if temp > 98 puts 'value' end
Add 'end'.
Ruby
jwt.sign({{id:55}}, 'key');
jwt.sign({{id:55}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
bar
bar()
Add parentheses.
Kotlin
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
function baz(): void {{ return 45; }}
function baz(): number {{ return 45; }}
Return type mismatch.
TypeScript
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
disp('output')
disp('output')
Correct.
MATLAB
value: info title: data,
value: info title: data
Remove comma.
YAML
DELETE FROM orders WHERE email=63
DELETE FROM orders WHERE email=63;
Add semicolon.
SQL
let c = 29; c += 1;
let mut c = 29; c += 1;
Need mut to modify.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<user><name>result</name><desc>14</desc></user
<user><name>result</name><desc>14</desc></user>
Add closing >.
XML
var z int = 'message'
var z string = 'message'
Type mismatch.
Go
for index in range(80) print(index)
for index in range(80): print(index)
Colon after for.
Python
cin >> x;
int x; cin >> x;
Declare variable.
C++