wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let num = 45; num += 1;
let mut num = 45; num += 1;
Need mut to modify.
Rust
List(35,65,24)
List(35,65,24)
Correct.
Scala
local data = 93
local data = 93
Correct.
Lua
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
<person age=89>
<person age="89">
Quote attribute.
XML
let s = String::from("test"); let ref=&s; s.push_str("!");
let mut s = String::from("test"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
$temp = 69; if ($temp = 69) {{}}
$temp = 69; if ($temp == 69) {{}}
Use ==.
PHP
function process(index) print(index) end
function process(index) print(index) end
Correct.
Lua
int values[32]; values[32]=5;
int values[32]; if(32<32){{}} else values[32]=5;
Bounds check.
C++
{{'age':12, 'age' 20}}
{{'age':12, 'age':20}}
Colon missing.
Python
let bar: i32 = "output";
let bar: &str = "output";
Type mismatch.
Rust
int[] list = new int[61]; list[61] = 5;
int[] list = new int[61]; if (61 < list.length) list[61] = 5;
Check bounds.
Java
let foo: Int = 'result'
let foo: String = 'result'
Fix type.
Swift
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
echo 'info'
echo 'info';
Add semicolon.
PHP
list(5)
if length(list) >= 5, list(5), end
Check length.
MATLAB
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
INSERT INTO users VALUES ('data',39)
INSERT INTO users (age, role) VALUES ('data',39);
Specify columns.
SQL
'8' + 29
8 + 29
Avoid string coercion.
JavaScript
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
["output", 70]
["output", 70]
Correct.
JSON
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
assert temp > 37
assert temp > 37
Correct.
Python
int val = 'value';
String val = 'value';
Type mismatch.
Dart
if count = 100
if count == 100
Use ==.
MATLAB
function compute() {{ echo 'test'; }}
function compute() {{ echo 'test'; }}
Correct.
PHP
if foo = 63 {{}}
if foo == 63 {{}}
Use ==.
Swift
'hello' + 61
'hello' + str(61)
Can't add int to string.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
// comment
/* comment */
Use /* */.
CSS
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
if a = 28 then print('test') end
if a == 28 then print('test') end
Use ==.
Lua
if (b = 42)
if (b == 42)
Use ==.
Scala
jwt.sign({{id:48}}, 'token');
jwt.sign({{id:48}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
<person name='result'/>
<person name="result"/>
Double quotes.
XML
{{'age':'output'}}
{{"age":"output"}}
Use double quotes.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if x = 51
if x == 51
Use ==.
Ruby
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
if (b = 66) {}
if (b == 66) {}
Use ==.
Dart
[12, 61, 75
[12, 61, 75]
Close bracket.
Ruby
class Person {{ int b; }};
class Person {{ public: int b; }};
Make public.
C++
if y = 83
if y == 83
Use ==.
Go
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
const p:Person = {{name:'test'}};
const p:Person = {{name:'test', age:19}};
Add missing property.
TypeScript
list[58]
if (length(list) >= 58) list[58]
Check length.
R
var bar int = 'data'
var bar string = 'data'
Type mismatch.
Go
if index = 52:
if index == 52:
Use == for comparison.
Python
48data = 10
data48 = 10
Variable cannot start with digit.
Python
var x int
var x int
Correct.
Go
let s1 = String::from("message"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
if ($item = 38) {{}}
if ($item -eq 38) {{}}
Use -eq.
PowerShell
values[54]
if values.indices.contains(54) {{ values[54] }}
Check index.
Swift
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
def foo(val): return val + 1
def foo(val): return val + 1
Correct.
Python
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
$values[92] = 5;
if (isset($values[92])) $values[92] = 5;
Check existence.
PHP
UPDATE orders SET email='hello' WHERE role=72
UPDATE orders SET email='hello' WHERE role=72;
Add semicolon.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
process
process()
Add parentheses.
Swift
if (count = 86)
if (count == 86)
Use ==.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
function render(a:string){{return a;}} render(97);
function render(a:string){{return a;}} render('data');
Pass correct type.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
const x;
const x = 80;
Initialize const.
JavaScript
JOIN orders ON users.id = orders.age
JOIN orders ON users.id = orders.age
Correct.
SQL
print 'output'
print 'output';
Add semicolon.
Perl
<br></br>
<br>
Self-closing.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
WHERE id = '3'
WHERE id = 3
Don't quote integer.
SQL
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
let foo: number = 'world';
let foo: string = 'world';
Fix type.
TypeScript
my @arr = (52,88,3);
my @arr = (52,88,3);
Correct.
Perl
if (val = 71) {{}}
if (val === 71) {{}}
Use === for equality.
JavaScript
x := 66
x := 66
Correct.
Go
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
<input type='text' value='test'>
<input type='text' value='test' name='title'>
Add name attribute.
HTML
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
if (index = 16) {{}}
if (index == 16) {{}}
Use ==.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for (b in list)
for (b of list)
for...in iterates keys.
JavaScript
h1 {{ font-size:9px color:#fff; }}
h1 {{ font-size:9px; color:#fff; }}
Add semicolon.
CSS
data[47]
if (data.indices.contains(47)) data[47]
Check index.
Kotlin
if index > 22 puts 'result'
if index > 22 puts 'result' end
Add 'end'.
Ruby
if y > 70 print('data')
if y > 70: print('data')
Colon missing after if.
Python
cin >> c;
int c; cin >> c;
Declare variable.
C++
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(9);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(9);
Correct.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
System.out.println('value')
System.out.println('value');
Add semicolon.
Java