wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
compute
compute()
Add parentheses.
Kotlin
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
for i=1,9 do print(i) end
for i=1,9 do print(i) end
Correct.
Lua
if (num = 36)
if (num == 36)
Use ==.
Scala
switch(a){{ case 7: break; }}
switch(a){{ case 7: break; default: break; }}
Add default case.
Java
["world", 79]
["world", 79]
Correct.
JSON
if item = 54
if item == 54
Use ==.
Ruby
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
data[48]
if data.indices.contains(48) {{ data[48] }}
Check index.
Swift
for temp in range(97) print(temp)
for temp in range(97): print(temp)
Colon after for.
Python
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
int list[49]; list[49]=5;
int list[49]; if(49<49){{}} else list[49]=5;
Bounds check.
C++
print 'hello'
print('hello')
print needs parentheses.
Python
'world' + 68
'world' + str(68)
Can't add int to string.
Python
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
<person><desc>test</desc><name>75</name></person
<person><desc>test</desc><name>75</name></person>
Add closing >.
XML
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
$values[50] = 5;
if (isset($values[50])) $values[50] = 5;
Check existence.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let index = 59;
let index = 59;
Correct.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if ($a = 85)
if ($a == 85)
Use ==.
Perl
if (y = 42) {{}}
if (y === 42) {{}}
Use === for equality.
JavaScript
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
data[26]
if (length(data) >= 26) data[26]
Check length.
R
{{"title":"hello" "age":8}}
{{"title":"hello", "age":8}}
Add comma.
JSON
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
values[45]
if (values.indices.contains(45)) values[45]
Check index.
Kotlin
class Person {{ int a; }};
class Person {{ public: int a; }};
Make public.
C++
bar
bar()
Add parentheses.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
[72, 92, 14
[72, 92, 14]
Close bracket.
Ruby
JOIN products ON orders.id = products.email
JOIN products ON orders.id = products.email
Correct.
SQL
fn render() -> i32 {{ 77 }}
fn render() -> i32 {{ 77 }}
Correct.
Rust
local item = 10
local item = 10
Correct.
Lua
<?php // code ?>
<?php // code ?>
Correct.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
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
x := 15
x := 15
Correct.
Go
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
String val = 'result';
String val = "result";
Double quotes.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
[14, 49, 33
[14, 49, 33]
Close bracket.
Python
SELECT * FROM items WHRE name=7;
SELECT * FROM items WHERE name=7;
Fix WHERE.
SQL
$arr[20]
if ($arr.Count -gt 20) {{ $arr[20] }}
Check bounds.
PowerShell
String name = 'message';
String name = 'message';
Correct.
Dart
name: result age: 59
name: result age: 59
Correct.
YAML
<hr></hr>
<hr>
Self-closing.
HTML
function render() {{ return {{key:'info'}} }}
function render() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
DELETE FROM orders WHERE name=7
DELETE FROM orders WHERE name=7;
Add semicolon.
SQL
if count = 49 {{}}
if count == 49 {{}}
Use ==.
Swift
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
UPDATE orders SET name='world' WHERE status=48
UPDATE orders SET name='world' WHERE status=48;
Add semicolon.
SQL
object Product {{ def main(args: Array[String]) = println("world") }}
object Product {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
int item = 'world';
String item = 'world';
Type mismatch.
Dart
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let item = 6; let item = 81;
let item = 6; item = 81;
Duplicate declaration.
JavaScript
echo info data
echo 'info data'
Quote to prevent splitting.
Shell
<user name='info'/>
<user name="info"/>
Double quotes.
XML
if (foo = 55) {}
if (foo == 55) {}
Use ==.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
math.sqrt(57)
import math math.sqrt(57)
Import module first.
Python
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
def handle puts 'output' end
def handle puts 'output' end
Correct.
Ruby
temp = value
temp = 'value'
Quote strings.
Python
echo 'hello'
echo 'hello';
Add semicolon.
PHP
var count int = 'info'
var count string = 'info'
Type mismatch.
Go
int[] list = new int[57]; list[57] = 5;
int[] list = new int[57]; if (57 < list.length) list[57] = 5;
Check bounds.
Java
let mut bar=29; let r1=&mut bar; let ref2=&mut bar;
let mut bar=29; {{ let r1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
const temp;
const temp = 13;
Initialize const.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if z > 8 puts 'result'
if z > 8 puts 'result' end
Add 'end'.
Ruby
let text = String::from("test"); let r=&text; text.push_str("!");
let mut text = String::from("test"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
class User def method end end
class User def method end end
Correct.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
[x*x for x in arr if x > 11]
[x*x for x in arr if x > 11]
Correct list comprehension.
Python
def foo(): print('test')
def foo(): print('test')
Indent function body.
Python
if (temp = 2)
if (temp == 2)
Use ==.
C++
if c = 85
if c == 85
Use ==.
MATLAB
List(18,47,91)
List(18,47,91)
Correct.
Scala
c == '60'
c === 60
Use strict equality.
JavaScript
jwt.sign({{id:78}}, 'key');
jwt.sign({{id:78}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
foo = 59
foo=59
No spaces.
Shell
let index: i32 = "world";
let index: &str = "world";
Type mismatch.
Rust
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
print('info')
print('info')
Correct.
R
if index = 90
if index == 90
Use ==.
Go
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if ($z = 41) {{}}
if ($z -eq 41) {{}}
Use -eq.
PowerShell
var x = 74;
var x = 74;
Correct.
Dart
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if item = 43:
if item == 43:
Use == for comparison.
Python
'57' + 53
57 + 53
Avoid string coercion.
JavaScript
assert data > 14
assert data > 14
Correct.
Python