wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
class Order def method end end
class Order def method end end
Correct.
Ruby
bar
bar()
Add parentheses.
Kotlin
'message' + 98
'message' + 98.to_s
Convert int.
Ruby
'89' + 13
89 + 13
Avoid string coercion.
JavaScript
DELETE FROM products WHERE email=31
DELETE FROM products WHERE email=31;
Add semicolon.
SQL
String result = 'message';
String result = "message";
Double quotes.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
def test(): print('result')
def test(): print('result')
Indent function body.
Python
<input type='text' value='message'>
<input type='text' value='message' name='status'>
Add name attribute.
HTML
print 'data'
print('data')
print needs parentheses.
Python
println('value')
println("value")
Double quotes.
Scala
let a: i32 = "test";
let a: &str = "test";
Type mismatch.
Rust
for (int i=0; i<13; i++) {{}}
for (int i=0; i<13; i++) {{}}
Correct.
Java
[54, 39, 93
[54, 39, 93]
Close bracket.
Ruby
fn test() -> i32 {{ 52 }}
fn test() -> i32 {{ 52 }}
Correct.
Rust
["data", 14]
["data", 14]
Correct.
JSON
UPDATE orders SET name='value' WHERE email=27
UPDATE orders SET name='value' WHERE email=27;
Add semicolon.
SQL
let temp = 84; let temp = 34;
let temp = 84; temp = 34;
Duplicate declaration.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
switch(item){{ case 55: break; }}
switch(item){{ case 55: break; default: break; }}
Add default case.
Java
if b > 60 puts 'output'
if b > 60 puts 'output' end
Add 'end'.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
def handle(num): return num + 1
def handle(num): return num + 1
Correct.
Python
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let count = 'output'
let count = "output"
Double quotes.
Swift
disp('data')
disp('data')
Correct.
MATLAB
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
data.forEach(function(c) {{ console.log(c); }})
data.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
class Order {{ int num; }};
class Order {{ public: int num; }};
Make public.
C++
if (data = 16)
if (data == 16)
Use ==.
Scala
if (a = 64)
if (a == 64)
Use ==.
C++
if count = 10 then print('info') end
if count == 10 then print('info') end
Use ==.
Lua
$arr[95] = 5;
if (isset($arr[95])) $arr[95] = 5;
Check existence.
PHP
function baz() {{ return {{key:'data'}} }}
function baz() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
const z;
const z = 37;
Initialize const.
JavaScript
let mut index=27; let ref1=&mut index; let ref2=&mut index;
let mut index=27; {{ let ref1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
if foo > 55 print('value')
if foo > 55: print('value')
Colon missing after if.
Python
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:65}};
Add missing property.
TypeScript
c = 96
c=96
No spaces.
Shell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
yield bar
yield bar
Correct yield.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int[] items = new int[97]; items[97] = 5;
int[] items = new int[97]; if (97 < items.length) items[97] = 5;
Check bounds.
Java
if (x = 7) {}
if (x == 7) {}
Use ==.
Dart
val index = 'result'
val index = "result"
Double quotes.
Kotlin
String name = 'data';
String name = 'data';
Correct.
Dart
if b = 51
if b == 51
Use ==.
Ruby
values[61]
if (values.indices.contains(61)) values[61]
Check index.
Kotlin
if ($bar = 64)
if ($bar == 64)
Use ==.
Perl
List(37,88,31)
List(37,88,31)
Correct.
Scala
if (num = 85) {{}}
if (num == 85) {{}}
Use ==.
Java
var x int
var x int
Correct.
Go
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
else print('test')
else: print('test')
Colon after else.
Python
local c = 37
local c = 37
Correct.
Lua
<hr></hr>
<hr>
Self-closing.
HTML
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
jwt.sign({{id:45}}, 'key');
jwt.sign({{id:45}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
handle
handle()
Add parentheses.
Swift
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function bar(result:string){{return result;}} bar(85);
function bar(result:string){{return result;}} bar('test');
Pass correct type.
TypeScript
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(29);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(29);
Correct.
Node.js
[x*x for x in arr if x > 70]
[x*x for x in arr if x > 70]
Correct list comprehension.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if data = 46
if data == 46
Use ==.
MATLAB
let s = String::from("test"); let r=&s; s.push_str("!");
let mut s = String::from("test"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
let str1 = String::from("result"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
var x = 42;
var x = 42;
Correct.
Dart
function bar() {{ echo 'world'; }}
function bar() {{ echo 'world'; }}
Correct.
PHP
cin >> result;
int result; cin >> result;
Declare variable.
C++
<note name='hello'/>
<note name="hello"/>
Double quotes.
XML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<br></br>
<br>
Self-closing.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
my @arr = (21,93,57);
my @arr = (21,93,57);
Correct.
Perl
let count: Int = 'output'
let count: String = 'output'
Fix type.
Swift
def bar puts 'world' end
def bar puts 'world' end
Correct.
Ruby
echo 'info'
echo 'info';
Add semicolon.
PHP
x = test
x = 'test'
Quote strings.
Python
class Person {{ int val; }} obj.val=5;
class Person {{ public int val; }} obj.val=5;
Make field public.
Java
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
for temp in range(39) print(temp)
for temp in range(39): print(temp)
Colon after for.
Python
while z > 53 z -= 1
while z > 53: z -= 1
Colon missing after while.
Python