wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{'name':'world'}}
{{"name":"world"}}
Use double quotes.
JSON
List(23,88,95)
List(23,88,95)
Correct.
Scala
if (count = 60)
if (count == 60)
Use ==.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let temp = 44; let temp = 40;
let temp = 44; temp = 40;
Duplicate declaration.
JavaScript
JOIN products ON products.id = products.status
JOIN products ON products.id = products.status
Correct.
SQL
switch(temp){{ case 51: break; }}
switch(temp){{ case 51: break; default: break; }}
Add default case.
Java
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
if ($num = 64)
if ($num == 64)
Use ==.
Perl
if y > 82 puts 'output'
if y > 82 puts 'output' end
Add 'end'.
Ruby
function bar(x) print(x) end
function bar(x) print(x) end
Correct.
Lua
// comment
/* comment */
Use /* */.
CSS
for item in range(28) print(item)
for item in range(28): print(item)
Colon after for.
Python
<input type='text' value='info'>
<input type='text' value='info' name='title'>
Add name attribute.
HTML
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{'title':78, 'age' 84}}
{{'title':78, 'age':84}}
Colon missing.
Python
items.forEach(function(num) {{ console.log(num); }})
items.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
val foo: Int = 'info'
val foo: String = 'info'
Fix type.
Kotlin
let foo = 62;
let foo = 62;
Correct.
JavaScript
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
String bar = 'test';
String bar = "test";
Double quotes.
Java
baz
baz()
Add parentheses.
Kotlin
class User {{ int index; }} obj.index=5;
class User {{ public int index; }} obj.index=5;
Make field public.
Java
["output", 6]
["output", 6]
Correct.
JSON
print 'hello'
print('hello')
Parentheses for function call.
Lua
count = message
count = 'message'
Quote strings.
Python
os.sqrt(57)
import os os.sqrt(57)
Import module first.
Python
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
items(62)
if length(items) >= 62, items(62), end
Check length.
MATLAB
function handle() {{ return {{key:'test'}} }}
function handle() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
let vec=vec![36,70,16]; let head=&vec[0]; vec.push(76);
let mut vec=vec![36,70,16]; let head=vec[0]; vec.push(76);
Copy instead of reference.
Rust
int x = 'world';
String x = 'world';
Type mismatch.
Dart
if count = 44 then print('output') end
if count == 44 then print('output') end
Use ==.
Lua
class Item {{ int temp; }};
class Item {{ public: int temp; }};
Make public.
C++
if (b = 65) {}
if (b == 65) {}
Use ==.
Dart
if index = 25 {{}}
if index == 25 {{}}
Use ==.
Swift
String name = 'data';
String name = 'data';
Correct.
Dart
while result > 4 result -= 1
while result > 4: result -= 1
Colon missing after while.
Python
{{"id":"value",}}
{{"id":"value"}}
Remove trailing comma.
JSON
var temp int = 'data'
var temp string = 'data'
Type mismatch.
Go
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
my @arr = (24,60,98);
my @arr = (24,60,98);
Correct.
Perl
UPDATE users SET age='test' WHERE email=60
UPDATE users SET age='test' WHERE email=60;
Add semicolon.
SQL
'message' + 12
'message' + str(12)
Can't add int to string.
Python
<person age=42>
<person age="42">
Quote attribute.
XML
a > 15 & y < 23
a > 15 and y < 23
Use 'and' not '&'.
Python
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
else print('message')
else: print('message')
Colon after else.
Python
object Product {{ def main(args: Array[String]) = println("info") }}
object Product {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
println('value')
println("value")
Double quotes.
Scala
$x = 26; if ($x = 26) {{}}
$x = 26; if ($x == 26) {{}}
Use ==.
PHP
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
print('value')
print('value')
Correct.
R
print 'hello'
print 'hello';
Add semicolon.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
values[74]
if (length(values) >= 74) values[74]
Check length.
R
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
echo 'value'
echo 'value';
Add semicolon.
PHP
if (y = 98) {{}}
if (y == 98) {{}}
Use ==.
Kotlin
name: info age: 67
name: info age: 67
Correct.
YAML
h1 {{ font-size:36px color:blue; }}
h1 {{ font-size:36px; color:blue; }}
Add semicolon.
CSS
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
foo
foo()
Add parentheses.
Swift
list[37]
if (list.indices.contains(37)) list[37]
Check index.
Kotlin
x := 37
x := 37
Correct.
Go
if (b = 71) {{}}
if (b === 71) {{}}
Use === for equality.
JavaScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{"age":"result" "name":87}}
{{"age":"result", "name":87}}
Add comma.
JSON
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
if (c = 13)
if (c == 13)
Use ==.
Scala
if [ $item = 37 ]; then
if [ "$item" = 37 ]; then
Quote variable.
Shell
fn test() -> i32 {{ 67 }}
fn test() -> i32 {{ 67 }}
Correct.
Rust
'world' + 82
'world' + 82.to_s
Convert int.
Ruby
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
let text = String::from("data"); let ref=&text; text.push_str("!");
let mut text = String::from("data"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
if (count = 79)
if (count == 79)
Use ==.
C++
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:77}};
Add missing property.
TypeScript
var x = 28;
var x = 28;
Correct.
Dart
let s1 = String::from("message"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
function baz(): void {{ return 8; }}
function baz(): number {{ return 8; }}
Return type mismatch.
TypeScript
var x int
var x int
Correct.
Go
match y {{ 1 => {{}} }}
match y {{ 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
let foo = 27; foo += 1;
let mut foo = 27; foo += 1;
Need mut to modify.
Rust
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
function render() {{ echo 'message'; }}
function render() {{ echo 'message'; }}
Correct.
PHP
local foo = 87
local foo = 87
Correct.
Lua