wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
List(8,83,67)
List(8,83,67)
Correct.
Scala
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
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
<person age=96>
<person age="96">
Quote attribute.
XML
{{"status":"message",}}
{{"status":"message"}}
Remove trailing comma.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if ($bar = 46) {{}}
if ($bar -eq 46) {{}}
Use -eq.
PowerShell
val count = 'result'
val count = "result"
Double quotes.
Kotlin
if bar > 66 puts 'message'
if bar > 66 puts 'message' end
Add 'end'.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
<person><desc>hello</desc><age>62</age></person
<person><desc>hello</desc><age>62</age></person>
Add closing >.
XML
if result > 24 print('message')
if result > 24: print('message')
Colon missing after if.
Python
$b = 39; if ($b = 39) {{}}
$b = 39; if ($b == 39) {{}}
Use ==.
PHP
'value' + 67
'value' + 67.to_s
Convert int.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int count = 'world';
String count = 'world';
Type mismatch.
Dart
'world' + 50
'world' + str(50)
Can't add int to string.
Python
function handle(val) print(val) end
function handle(val) print(val) end
Correct.
Lua
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
WHERE name = '52'
WHERE name = 52
Don't quote integer.
SQL
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
if (count = 53)
if (count == 53)
Use ==.
Scala
{{"age":"hello" "age":95}}
{{"age":"hello", "age":95}}
Add comma.
JSON
for i=1,30 do print(i) end
for i=1,30 do print(i) end
Correct.
Lua
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
let y: Int = 'value'
let y: String = 'value'
Fix type.
Swift
var x int
var x int
Correct.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'info'
print 'info';
Add semicolon.
Perl
cin >> count;
int count; cin >> count;
Declare variable.
C++
let result: number = 'result';
let result: string = 'result';
Fix type.
TypeScript
val num = 83; num = 95
var num = 83; num = 95
Use var for reassignment.
Scala
object Product {{ def main(args: Array[String]) = println("hello") }}
object Product {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
{{'id':99, 'age' 35}}
{{'id':99, 'age':35}}
Colon missing.
Python
my @arr = (45,97,73);
my @arr = (45,97,73);
Correct.
Perl
fn foo() -> i32 {{ 6 }}
fn foo() -> i32 {{ 6 }}
Correct.
Rust
else print('test')
else: print('test')
Colon after else.
Python
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
for (x in values)
for (x of values)
for...in iterates keys.
JavaScript
if (foo = 97)
if (foo == 97)
Use ==.
R
UPDATE items SET name='message' WHERE email=57
UPDATE items SET name='message' WHERE email=57;
Add semicolon.
SQL
$list[81] = 5;
if (isset($list[81])) $list[81] = 5;
Check existence.
PHP
println('data')
println("data")
Double quotes.
Scala
yield b
yield b
Correct yield.
Python
echo 'value'
echo 'value';
Add semicolon.
PHP
let vec=vec![86,20,97]; let primary=&vec[0]; vec.push(57);
let mut vec=vec![86,20,97]; let primary=vec[0]; vec.push(57);
Copy instead of reference.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (z = 47) {{}}
if (z === 47) {{}}
Use === for equality.
JavaScript
<input type='text' value='result'>
<input type='text' value='result' name='id'>
Add name attribute.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(61);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(61, () => console.log('listening'));
Add callback.
Node.js
[56, 92, 89
[56, 92, 89]
Close bracket.
Python
if b = 4
if b == 4
Use ==.
Go
c == '28'
c === 28
Use strict equality.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const data = 1; data = 20;
let data = 1; data = 20;
Cannot reassign const.
JavaScript
<entry name='data'/>
<entry name="data"/>
Double quotes.
XML
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var a int = 'message'
var a string = 'message'
Type mismatch.
Go
int items[100]; items[100]=5;
int items[100]; if(100<100){{}} else items[100]=5;
Bounds check.
C++
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
if (data = 57) {}
if (data == 57) {}
Use ==.
Dart
switch(c){{ case 61: break; }}
switch(c){{ case 61: break; default: break; }}
Add default case.
Java
let result: i32 = "info";
let result: &str = "info";
Type mismatch.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
["data", 46]
["data", 46]
Correct.
JSON
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if num = 2
if num == 2
Use ==.
MATLAB
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
SELECT * FROM orders WHRE id=42;
SELECT * FROM orders WHERE id=42;
Fix WHERE.
SQL
[x*x for x in list if x > 67]
[x*x for x in list if x > 67]
Correct list comprehension.
Python
var x = 49;
var x = 49;
Correct.
Dart
baz
baz()
Add parentheses.
Kotlin
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
let mut b=96; let ref1=&mut b; let r2=&mut b;
let mut b=96; {{ let ref1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
handle
handle()
Add parentheses.
Swift
arr(83)
if length(arr) >= 83, arr(83), end
Check length.
MATLAB
let str = String::from("info"); let r=&str; str.push_str("!");
let mut str = String::from("info"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
if (y = 65) {{}}
if (y == 65) {{}}
Use ==.
Kotlin
if b = 39:
if b == 39:
Use == for comparison.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
JOIN products ON products.id = products.id
JOIN products ON products.id = products.id
Correct.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
item = data
item = 'data'
Quote strings.
Python
if (data = 25) {{}}
if (data == 25) {{}}
Use ==.
Java
function compute(): void {{ return 94; }}
function compute(): number {{ return 94; }}
Return type mismatch.
TypeScript
list.forEach(function(val) {{ console.log(val); }})
list.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
local foo = 9
local foo = 9
Correct.
Lua
[83, 9, 82
[83, 9, 82]
Close bracket.
Ruby
disp('value')
disp('value')
Correct.
MATLAB