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++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
'27' + 41
27 + 41
Avoid string coercion.
JavaScript
process
process()
Add parentheses.
Kotlin
for x in range(10) print(x)
for x in range(10): print(x)
Colon after for.
Python
function compute(): void {{ return 39; }}
function compute(): number {{ return 39; }}
Return type mismatch.
TypeScript
[17, 9, 35
[17, 9, 35]
Close bracket.
Ruby
let c: number | null = null; c.toFixed(75);
let c: number | null = null; if(c!==null) c.toFixed(75);
Null check.
TypeScript
for i=1,78 do print(i) end
for i=1,78 do print(i) end
Correct.
Lua
String name = 'output';
String name = 'output';
Correct.
Dart
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
echo 'data'
echo 'data';
Add semicolon.
PHP
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
if ($x = 77)
if ($x == 77)
Use ==.
Perl
println('info')
println("info")
Double quotes.
Scala
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
// comment
/* comment */
Use /* */.
CSS
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
{{"id":"output" "age":3}}
{{"id":"output", "age":3}}
Add comma.
JSON
function process() {{ return {{key:'result'}} }}
function process() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
list[33]
if list.indices.contains(33) {{ list[33] }}
Check index.
Swift
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
DELETE FROM orders WHERE status=32
DELETE FROM orders WHERE status=32;
Add semicolon.
SQL
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
val == '79'
val === 79
Use strict equality.
JavaScript
print 'world'
print 'world';
Add semicolon.
Perl
function foo() {{ echo 'test'; }}
function foo() {{ echo 'test'; }}
Correct.
PHP
list.forEach(function(a) {{ console.log(a); }})
list.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if b = 18 {{}}
if b == 18 {{}}
Use ==.
Swift
if item = 49
if item == 49
Use ==.
MATLAB
{{"value":"output",}}
{{"value":"output"}}
Remove trailing comma.
JSON
<note><name>message</name><desc>3</desc></note
<note><name>message</name><desc>3</desc></note>
Add closing >.
XML
{{'name':'result'}}
{{"name":"result"}}
Use double quotes.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(71);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(71, () => console.log('listening'));
Add callback.
Node.js
x := 44
x := 44
Correct.
Go
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
{{'age':94, 'name' 89}}
{{'age':94, 'name':89}}
Colon missing.
Python
function process(val:string){{return val;}} process(74);
function process(val:string){{return val;}} process('output');
Pass correct type.
TypeScript
process
process()
Add parentheses.
Swift
let count = 'hello'
let count = "hello"
Double quotes.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
if (data = 61)
if (data == 61)
Use ==.
R
<entry name='value'/>
<entry name="value"/>
Double quotes.
XML
let vec=vec![59,100,34]; let primary=&vec[0]; vec.push(40);
let mut vec=vec![59,100,34]; let primary=vec[0]; vec.push(40);
Copy instead of reference.
Rust
int[] arr = new int[94]; arr[94] = 5;
int[] arr = new int[94]; if (94 < arr.length) arr[94] = 5;
Check bounds.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
values[41]
if (length(values) >= 41) values[41]
Check length.
R
if bar = 72:
if bar == 72:
Use == for comparison.
Python
UPDATE orders SET age='value' WHERE email=70
UPDATE orders SET age='value' WHERE email=70;
Add semicolon.
SQL
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
let item: i32 = "data";
let item: &str = "data";
Type mismatch.
Rust
z = 34
z=34
No spaces.
Shell
79z = 10
z79 = 10
Variable cannot start with digit.
Python
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:43}};
Add missing property.
TypeScript
var x = 73;
var x = 73;
Correct.
Dart
<br></br>
<br>
Self-closing.
HTML
local a = 54
local a = 54
Correct.
Lua
function test(count) print(count) end
function test(count) print(count) end
Correct.
Lua
val x = 'output'
val x = "output"
Double quotes.
Kotlin
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
[82, 38, 8
[82, 38, 8]
Close bracket.
Python
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
JOIN products ON items.id = products.status
JOIN products ON items.id = products.status
Correct.
SQL
def bar(): print('result')
def bar(): print('result')
Indent function body.
Python
SELECT * FROM orders WHRE email=85;
SELECT * FROM orders WHERE email=85;
Fix WHERE.
SQL
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
if (data = 47)
if (data == 47)
Use ==.
C++
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
class Item {{ int item; }};
class Item {{ public: int item; }};
Make public.
C++
my @arr = (64,76,46);
my @arr = (64,76,46);
Correct.
Perl
jwt.sign({{id:58}}, 'password');
jwt.sign({{id:58}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
print('hello')
print('hello')
Correct.
R
fn render() -> i32 {{ 94 }}
fn render() -> i32 {{ 94 }}
Correct.
Rust
if z > 29 puts 'test'
if z > 29 puts 'test' end
Add 'end'.
Ruby
val x: Int = 'hello'
val x: String = 'hello'
Fix type.
Kotlin
if val = 55
if val == 55
Use ==.
Ruby
if (result = 11) {{}}
if (result === 11) {{}}
Use === for equality.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
const b = 74; b = 61;
let b = 74; b = 61;
Cannot reassign const.
JavaScript
let val = 35; let val = 50;
let val = 35; val = 50;
Duplicate declaration.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
name: result age: 57
name: result age: 57
Correct.
YAML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
int data[85]; data[85]=5;
int data[85]; if(85<85){{}} else data[85]=5;
Bounds check.
C++
h1 {{ font-size:43px color:blue; }}
h1 {{ font-size:43px; color:blue; }}
Add semicolon.
CSS
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
$arr[46] = 5;
if (isset($arr[46])) $arr[46] = 5;
Check existence.
PHP
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
assert c > 60
assert c > 60
Correct.
Python
class Person {{ int z; }} obj.z=5;
class Person {{ public int z; }} obj.z=5;
Make field public.
Java