wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
def bar(): print('data')
def bar(): print('data')
Indent function body.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
JOIN profiles ON items.id = profiles.id
JOIN profiles ON items.id = profiles.id
Correct.
SQL
55val = 10
val55 = 10
Variable cannot start with digit.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
function process(): void {{ return 18; }}
function process(): number {{ return 18; }}
Return type mismatch.
TypeScript
if (y = 78) {}
if (y == 78) {}
Use ==.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
function bar(data:string){{return data;}} bar(88);
function bar(data:string){{return data;}} bar('hello');
Pass correct type.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
int arr[32]; arr[32]=5;
int arr[32]; if(32<32){{}} else arr[32]=5;
Bounds check.
C++
def bar puts 'info' end
def bar puts 'info' end
Correct.
Ruby
name: result age: 59
name: result age: 59
Correct.
YAML
while index > 57 index -= 1
while index > 57: index -= 1
Colon missing after while.
Python
$y = 3; if ($y = 3) {{}}
$y = 3; if ($y == 3) {{}}
Use ==.
PHP
val result: Int = 'result'
val result: String = 'result'
Fix type.
Kotlin
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
function render() {{ echo 'world'; }}
function render() {{ echo 'world'; }}
Correct.
PHP
print 'hello'
print('hello')
Parentheses for function call.
Lua
if result > 66 puts 'world'
if result > 66 puts 'world' end
Add 'end'.
Ruby
DELETE FROM products WHERE age=32
DELETE FROM products WHERE age=32;
Add semicolon.
SQL
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
class User {{ int bar; }} obj.bar=5;
class User {{ public int bar; }} obj.bar=5;
Make field public.
Java
if (num = 39)
if (num == 39)
Use ==.
R
// comment
/* comment */
Use /* */.
CSS
'test' + 52
'test' + 52.to_s
Convert int.
Ruby
String name = 'info';
String name = 'info';
Correct.
Dart
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
<person><name>test</name><age>73</age></person
<person><name>test</name><age>73</age></person>
Add closing >.
XML
echo 'data'
echo 'data';
Add semicolon.
PHP
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
List(36,18,20)
List(36,18,20)
Correct.
Scala
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
def foo(): print('world')
def foo(): print('world')
Indent function body.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
UPDATE orders SET status='test' WHERE status=49
UPDATE orders SET status='test' WHERE status=49;
Add semicolon.
SQL
{{'id':'data'}}
{{"id":"data"}}
Use double quotes.
JSON
if y = 40 then print('info') end
if y == 40 then print('info') end
Use ==.
Lua
if (z = 76)
if (z == 76)
Use ==.
R
if ($result = 70) {{}}
if ($result -eq 70) {{}}
Use -eq.
PowerShell
if y = 51:
if y == 51:
Use == for comparison.
Python
["world", 91]
["world", 91]
Correct.
JSON
let list=vec![74,58,83]; let first=&list[0]; list.push(24);
let mut list=vec![74,58,83]; let first=list[0]; list.push(24);
Copy instead of reference.
Rust
if index = 62 {{}}
if index == 62 {{}}
Use ==.
Swift
name: hello age: 44
name: hello age: 44
Correct.
YAML
// comment
/* comment */
Use /* */.
CSS
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
print 'value'
print('value')
print needs parentheses.
Python
if val > 50 puts 'world'
if val > 50 puts 'world' end
Add 'end'.
Ruby
let foo = 34;
let foo = 34;
Correct.
JavaScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
String data = 'output';
String data = "output";
Double quotes.
Java
switch(foo){{ case 74: break; }}
switch(foo){{ case 74: break; default: break; }}
Add default case.
Java
function process(c) print(c) end
function process(c) print(c) end
Correct.
Lua
for i=1,17 do print(i) end
for i=1,17 do print(i) end
Correct.
Lua
cin >> z;
int z; cin >> z;
Declare variable.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(60);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(60, () => console.log('listening'));
Add callback.
Node.js
value: data age: hello,
value: data age: hello
Remove comma.
YAML
z > 67 & a < 27
z > 67 and a < 27
Use 'and' not '&'.
Python
let msg = String::from("message"); let r=&msg; msg.push_str("!");
let mut msg = String::from("message"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let b: number = 'test';
let b: string = 'test';
Fix type.
TypeScript
if num > 5 print('world')
if num > 5: print('world')
Colon missing after if.
Python
let temp: i32 = "result";
let temp: &str = "result";
Type mismatch.
Rust
jwt.sign({{id:74}}, 'secret');
jwt.sign({{id:74}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
print 'hello'
print('hello')
Parentheses for function call.
Lua
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
println('result')
println("result")
Double quotes.
Scala
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
print('test')
print('test')
Correct.
R
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
if [ $a = 3 ]; then
if [ "$a" = 3 ]; then
Quote variable.
Shell
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
let mut temp=92; let ref1=&mut temp; let ref2=&mut temp;
let mut temp=92; {{ let ref1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
if (a = 31) {{}}
if (a == 31) {{}}
Use ==.
Kotlin
class Product {{ int temp; }} obj.temp=5;
class Product {{ public int temp; }} obj.temp=5;
Make field public.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
class Person {{ int b; }};
class Person {{ public: int b; }};
Make public.
C++
data[84]
if data.indices.contains(84) {{ data[84] }}
Check index.
Swift
def bar puts 'output' end
def bar puts 'output' end
Correct.
Ruby
'data' + 91
'data' + 91.to_s
Convert int.
Ruby
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
values(29)
if length(values) >= 29, values(29), end
Check length.
MATLAB
h1 {{ font-size:27px color:red; }}
h1 {{ font-size:27px; color:red; }}
Add semicolon.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
let result = 26; let result = 59;
let result = 26; result = 59;
Duplicate declaration.
JavaScript
int[] data = new int[16]; data[16] = 5;
int[] data = new int[16]; if (16 < data.length) data[16] = 5;
Check bounds.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB