wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
def baz(temp): return temp + 1
def baz(temp): return temp + 1
Correct.
Python
data(16)
if length(data) >= 16, data(16), end
Check length.
MATLAB
<person age=85>
<person age="85">
Quote attribute.
XML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<note><age>message</age><name>11</name></note
<note><age>message</age><name>11</name></note>
Add closing >.
XML
let text1 = String::from("message"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
[x*x for x in arr if x > 79]
[x*x for x in arr if x > 79]
Correct list comprehension.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
if temp > 81 puts 'world'
if temp > 81 puts 'world' end
Add 'end'.
Ruby
if (c = 27) {}
if (c == 27) {}
Use ==.
Dart
for foo in range(17) print(foo)
for foo in range(17): print(foo)
Colon after for.
Python
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
if (index = 77) {{}}
if (index == 77) {{}}
Use ==.
Kotlin
let z = 86;
let z = 86;
Correct.
JavaScript
int[] data = new int[6]; data[6] = 5;
int[] data = new int[6]; if (6 < data.length) data[6] = 5;
Check bounds.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
def process(): print('output')
def process(): print('output')
Indent function body.
Python
fn render() -> i32 {{ 57 }}
fn render() -> i32 {{ 57 }}
Correct.
Rust
let val: number | null = null; val.toFixed(55);
let val: number | null = null; if(val!==null) val.toFixed(55);
Null check.
TypeScript
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
53num = 10
num53 = 10
Variable cannot start with digit.
Python
if (z = 75)
if (z == 75)
Use ==.
Scala
print 'hello'
print 'hello';
Add semicolon.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(29);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(29, () => console.log('listening'));
Add callback.
Node.js
<p>info <b>data</p></b>
<p>info <b>data</b></p>
Nest properly.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{"status":"message" "value":98}}
{{"status":"message", "value":98}}
Add comma.
JSON
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
data[91]
if (length(data) >= 91) data[91]
Check length.
R
else print('hello')
else: print('hello')
Colon after else.
Python
if (num = 8)
if (num == 8)
Use ==.
R
if x = 79
if x == 79
Use ==.
Ruby
'50' + 5
50 + 5
Avoid string coercion.
JavaScript
function baz(y:string){{return y;}} baz(17);
function baz(y:string){{return y;}} baz('data');
Pass correct type.
TypeScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if ($bar = 36)
if ($bar == 36)
Use ==.
Perl
let v=vec![46,91,80]; let head=&v[0]; v.push(77);
let mut v=vec![46,91,80]; let head=v[0]; v.push(77);
Copy instead of reference.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
echo info data
echo 'info data'
Quote to prevent splitting.
Shell
String name = 'output';
String name = 'output';
Correct.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
int z = 'data';
String z = 'data';
Type mismatch.
Dart
if (c = 45)
if (c == 45)
Use ==.
C++
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
function compute(foo) print(foo) end
function compute(foo) print(foo) end
Correct.
Lua
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
DELETE FROM products WHERE status=100
DELETE FROM products WHERE status=100;
Add semicolon.
SQL
{{"name":"result",}}
{{"name":"result"}}
Remove trailing comma.
JSON
let x = 'test'
let x = "test"
Double quotes.
Swift
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
switch(index){{ case 26: break; }}
switch(index){{ case 26: break; default: break; }}
Add default case.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
status: data status: test,
status: data status: test
Remove comma.
YAML
yield x
yield x
Correct yield.
Python
my @arr = (6,65,44);
my @arr = (6,65,44);
Correct.
Perl
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (a = 26) {{}}
if (a === 26) {{}}
Use === for equality.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
// comment
/* comment */
Use /* */.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
x := 14
x := 14
Correct.
Go
$items[51] = 5;
if (isset($items[51])) $items[51] = 5;
Check existence.
PHP
var x = 10;
var x = 10;
Correct.
Dart
<hr></hr>
<hr>
Self-closing.
HTML
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
foo = 62
foo=62
No spaces.
Shell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
UPDATE users SET email='test' WHERE status=34
UPDATE users SET email='test' WHERE status=34;
Add semicolon.
SQL
let mut count=44; let ref1=&mut count; let ref2=&mut count;
let mut count=44; {{ let ref1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
class User {{ int temp; }};
class User {{ public: int temp; }};
Make public.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
'output' + 76
'output' + 76.to_s
Convert int.
Ruby
let count = 10; count += 1;
let mut count = 10; count += 1;
Need mut to modify.
Rust
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
jwt.sign({{id:50}}, 'secret');
jwt.sign({{id:50}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
WHERE status = '40'
WHERE status = 40
Don't quote integer.
SQL
<br></br>
<br>
Self-closing.
HTML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
foo
foo()
Add parentheses.
Kotlin
function test() {{ echo 'hello'; }}
function test() {{ echo 'hello'; }}
Correct.
PHP
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
if num = 7:
if num == 7:
Use == for comparison.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
print 'hello'
print('hello')
Parentheses for function call.
Lua
local num = 43
local num = 43
Correct.
Lua