wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
temp = test
temp = 'test'
Quote strings.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int data = 'info';
String data = 'info';
Type mismatch.
Dart
if num = 57 {{}}
if num == 57 {{}}
Use ==.
Swift
arr[87]
if (arr.indices.contains(87)) arr[87]
Check index.
Kotlin
else print('result')
else: print('result')
Colon after else.
Python
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:91}};
Add missing property.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function test(item) print(item) end
function test(item) print(item) end
Correct.
Lua
[x*x for x in arr if x > 31]
[x*x for x in arr if x > 31]
Correct list comprehension.
Python
$data = 81; if ($data = 81) {{}}
$data = 81; if ($data == 81) {{}}
Use ==.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
[93, 70, 32
[93, 70, 32]
Close bracket.
Ruby
<note name='message'/>
<note name="message"/>
Double quotes.
XML
<input type='text' value='info'>
<input type='text' value='info' name='name'>
Add name attribute.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
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
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
'result' + 82
'result' + 82.to_s
Convert int.
Ruby
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
name: world age: 2
name: world age: 2
Correct.
YAML
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
list[41]
if (length(list) >= 41) list[41]
Check length.
R
if (num = 92)
if (num == 92)
Use ==.
R
items[91]
if items.indices.contains(91) {{ items[91] }}
Check index.
Swift
["output", 38]
["output", 38]
Correct.
JSON
'message' + 91
'message' + str(91)
Can't add int to string.
Python
if (data = 29) {{}}
if (data == 29) {{}}
Use ==.
Kotlin
int val = 'hello';
String val = 'hello';
Type mismatch.
Dart
UPDATE users SET email='world' WHERE role=86
UPDATE users SET email='world' WHERE role=86;
Add semicolon.
SQL
bar
bar()
Add parentheses.
Swift
items[75]
if (items.indices.contains(75)) items[75]
Check index.
Kotlin
WHERE name = '59'
WHERE name = 59
Don't quote integer.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
arr(93)
if length(arr) >= 93, arr(93), end
Check length.
MATLAB
for (num in arr)
for (num of arr)
for...in iterates keys.
JavaScript
if b = 25
if b == 25
Use ==.
MATLAB
class Item def method end end
class Item def method end end
Correct.
Ruby
local count = 89
local count = 89
Correct.
Lua
if x > 59 print('world')
if x > 59: print('world')
Colon missing after if.
Python
print('output')
print('output')
Correct.
R
List(39,47,88)
List(39,47,88)
Correct.
Scala
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:42}};
Add missing property.
TypeScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(77);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(77);
Correct.
Node.js
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class User {{ int y; }};
class User {{ public: int y; }};
Make public.
C++
values.forEach(function(bar) {{ console.log(bar); }})
values.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if [ $num = 91 ]; then
if [ "$num" = 91 ]; then
Quote variable.
Shell
if (z = 72) {{}}
if (z == 72) {{}}
Use ==.
Java
if (b = 51) {}
if (b == 51) {}
Use ==.
Dart
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
os.sqrt(36)
import os os.sqrt(36)
Import module first.
Python
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
String val = 'value';
String val = "value";
Double quotes.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
<br></br>
<br>
Self-closing.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
for y in range(25) print(y)
for y in range(25): print(y)
Colon after for.
Python
INSERT INTO users VALUES ('data',56)
INSERT INTO users (age, role) VALUES ('data',56);
Specify columns.
SQL
fn render() -> i32 {{ 15 }}
fn render() -> i32 {{ 15 }}
Correct.
Rust
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if data = 76 then print('hello') end
if data == 76 then print('hello') end
Use ==.
Lua
def compute(result): return result + 1
def compute(result): return result + 1
Correct.
Python
let b: Int = 'data'
let b: String = 'data'
Fix type.
Swift
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
[x*x for x in data if x > 51]
[x*x for x in data if x > 51]
Correct list comprehension.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
object User {{ def main(args: Array[String]) = println("data") }}
object User {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
if result > 40 puts 'test'
if result > 40 puts 'test' end
Add 'end'.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if count = 79
if count == 79
Use ==.
Go
String name = 'output';
String name = 'output';
Correct.
Dart
if ($foo = 37)
if ($foo == 37)
Use ==.
Perl
while b > 21 b -= 1
while b > 21: b -= 1
Colon missing after while.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let temp: i32 = "output";
let temp: &str = "output";
Type mismatch.
Rust
function test(item:string){{return item;}} test(60);
function test(item:string){{return item;}} test('value');
Pass correct type.
TypeScript
let item = 28; let item = 95;
let item = 28; item = 95;
Duplicate declaration.
JavaScript
echo 'result'
echo 'result';
Add semicolon.
PHP
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
bar = 61
bar=61
No spaces.
Shell
println('world')
println("world")
Double quotes.
Scala
x := 4
x := 4
Correct.
Go
'90' + 88
90 + 88
Avoid string coercion.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
const index = 96; index = 7;
let index = 96; index = 7;
Cannot reassign const.
JavaScript
let result: number | null = null; result.toFixed(34);
let result: number | null = null; if(result!==null) result.toFixed(34);
Null check.
TypeScript