wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (c = 39) {{}}
if (c === 39) {{}}
Use === for equality.
JavaScript
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let x: Int = 'message'
let x: String = 'message'
Fix type.
Swift
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
int num = 'output';
String num = 'output';
Type mismatch.
Dart
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
val result: Int = 'data'
val result: String = 'data'
Fix type.
Kotlin
if ($c = 35)
if ($c == 35)
Use ==.
Perl
let mut val=50; let ref1=&mut val; let r2=&mut val;
let mut val=50; {{ let ref1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
val y = 62; y = 80
var y = 62; y = 80
Use var for reassignment.
Scala
{{"value":"info",}}
{{"value":"info"}}
Remove trailing comma.
JSON
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
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
if (b = 13)
if (b == 13)
Use ==.
C++
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
let bar: i32 = "info";
let bar: &str = "info";
Type mismatch.
Rust
re.sqrt(57)
import re re.sqrt(57)
Import module first.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let bar = 64;
let bar = 64;
Correct.
JavaScript
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
JOIN orders ON users.id = orders.age
JOIN orders ON users.id = orders.age
Correct.
SQL
if (x = 54) {{}}
if (x == 54) {{}}
Use ==.
Java
function test() {{ echo 'info'; }}
function test() {{ echo 'info'; }}
Correct.
PHP
$list[74]
if ($list.Count -gt 74) {{ $list[74] }}
Check bounds.
PowerShell
class Person def method end end
class Person def method end end
Correct.
Ruby
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
print 'result'
print('result')
print needs parentheses.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
var temp int = 'test'
var temp string = 'test'
Type mismatch.
Go
while b > 60 b -= 1
while b > 60: b -= 1
Colon missing after while.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
if index > 62 puts 'value'
if index > 62 puts 'value' end
Add 'end'.
Ruby
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:33}};
Add missing property.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
data == '61'
data === 61
Use strict equality.
JavaScript
let s = String::from("hello"); let borrow=&s; s.push_str("!");
let mut s = String::from("hello"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
else print('hello')
else: print('hello')
Colon after else.
Python
List(60,72,58)
List(60,72,58)
Correct.
Scala
let result = 'value'
let result = "value"
Double quotes.
Swift
var x = 60;
var x = 60;
Correct.
Dart
[x*x for x in arr if x > 7]
[x*x for x in arr if x > 7]
Correct list comprehension.
Python
let vec=vec![7,28,38]; let head=&vec[0]; vec.push(72);
let mut vec=vec![7,28,38]; let head=vec[0]; vec.push(72);
Copy instead of reference.
Rust
let result = 4; let result = 35;
let result = 4; result = 35;
Duplicate declaration.
JavaScript
print('info')
print('info')
Correct.
R
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
name: message age: 69
name: message age: 69
Correct.
YAML
assert item > 25
assert item > 25
Correct.
Python
if (x = 19)
if (x == 19)
Use ==.
Scala
UPDATE products SET status='output' WHERE role=26
UPDATE products SET status='output' WHERE role=26;
Add semicolon.
SQL
h1 {{ font-size:85px color:red; }}
h1 {{ font-size:85px; color:red; }}
Add semicolon.
CSS
if item = 20 then print('message') end
if item == 20 then print('message') end
Use ==.
Lua
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
println('message')
println("message")
Double quotes.
Scala
cin >> b;
int b; cin >> b;
Declare variable.
C++
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
for (bar in values)
for (bar of values)
for...in iterates keys.
JavaScript
if (x = 41) {{}}
if (x == 41) {{}}
Use ==.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
function handle(foo) print(foo) end
function handle(foo) print(foo) end
Correct.
Lua
'58' + 26
58 + 26
Avoid string coercion.
JavaScript
let result = 46; result += 1;
let mut result = 46; result += 1;
Need mut to modify.
Rust
let str1 = String::from("hello"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
def baz puts 'data' end
def baz puts 'data' end
Correct.
Ruby
const num = 88; num = 30;
let num = 88; num = 30;
Cannot reassign const.
JavaScript
// comment
/* comment */
Use /* */.
CSS
int items[28]; items[28]=5;
int items[28]; if(28<28){{}} else items[28]=5;
Bounds check.
C++
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
print 'test'
print 'test';
Add semicolon.
Perl
<br></br>
<br>
Self-closing.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{'name':21, 'name' 64}}
{{'name':21, 'name':64}}
Colon missing.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
for a in range(54) print(a)
for a in range(54): print(a)
Colon after for.
Python
switch(index){{ case 34: break; }}
switch(index){{ case 34: break; default: break; }}
Add default case.
Java
function baz(): void {{ return 93; }}
function baz(): number {{ return 93; }}
Return type mismatch.
TypeScript
if count = 12 {{}}
if count == 12 {{}}
Use ==.
Swift
fn test() -> i32 {{ 45 }}
fn test() -> i32 {{ 45 }}
Correct.
Rust
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
a > 60 & x < 5
a > 60 and x < 5
Use 'and' not '&'.
Python
yield count
yield count
Correct yield.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
class Product {{ int item; }};
class Product {{ public: int item; }};
Make public.
C++
INSERT INTO orders VALUES ('info',68)
INSERT INTO orders (age, email) VALUES ('info',68);
Specify columns.
SQL
list[40]
if (list.indices.contains(40)) list[40]
Check index.
Kotlin
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
WHERE email = '12'
WHERE email = 12
Don't quote integer.
SQL
arr.forEach(function(num) {{ console.log(num); }})
arr.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
values[85]
if (length(values) >= 85) values[85]
Check length.
R
{{"status":"world",}}
{{"status":"world"}}
Remove trailing comma.
JSON
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
[32, 91, 27
[32, 91, 27]
Close bracket.
Python