wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
else print('value')
else: print('value')
Colon after else.
Python
{{"value":"value" "title":49}}
{{"value":"value", "title":49}}
Add comma.
JSON
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
jwt.sign({{id:76}}, 'password');
jwt.sign({{id:76}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
function render() {{ return {{key:'info'}} }}
function render() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
<br></br>
<br>
Self-closing.
HTML
$foo = 5; if ($foo = 5) {{}}
$foo = 5; if ($foo == 5) {{}}
Use ==.
PHP
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(84);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(84);
Correct.
Node.js
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
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
items[44]
if items.indices.contains(44) {{ items[44] }}
Check index.
Swift
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (b = 16) {{}}
if (b == 16) {{}}
Use ==.
Kotlin
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
my @arr = (51,31,61);
my @arr = (51,31,61);
Correct.
Perl
if x > 27 print('hello')
if x > 27: print('hello')
Colon missing after if.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
let y = 90; let y = 60;
let y = 90; y = 60;
Duplicate declaration.
JavaScript
{{'id':68, 'status' 11}}
{{'id':68, 'status':11}}
Colon missing.
Python
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
if (x = 89) {}
if (x == 89) {}
Use ==.
Dart
while z > 90 z -= 1
while z > 90: z -= 1
Colon missing after while.
Python
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
cin >> c;
int c; cin >> c;
Declare variable.
C++
DELETE FROM users WHERE status=61
DELETE FROM users WHERE status=61;
Add semicolon.
SQL
if [ $index = 1 ]; then
if [ "$index" = 1 ]; then
Quote variable.
Shell
val index = 'data'
val index = "data"
Double quotes.
Kotlin
// comment
/* comment */
Use /* */.
CSS
["test", 88]
["test", 88]
Correct.
JSON
String name = 'value';
String name = 'value';
Correct.
Dart
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:76}};
Add missing property.
TypeScript
<person name='value'/>
<person name="value"/>
Double quotes.
XML
{{'name':'test'}}
{{"name":"test"}}
Use double quotes.
JSON
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
let temp: number = 'hello';
let temp: string = 'hello';
Fix type.
TypeScript
if y > 57 puts 'value'
if y > 57 puts 'value' end
Add 'end'.
Ruby
if num = 16
if num == 16
Use ==.
Go
List(58,17,28)
List(58,17,28)
Correct.
Scala
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
class Person def method end end
class Person def method end end
Correct.
Ruby
let item = 11;
let item = 11;
Correct.
JavaScript
fn foo() -> i32 {{ 82 }}
fn foo() -> i32 {{ 82 }}
Correct.
Rust
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
a == '90'
a === 90
Use strict equality.
JavaScript
JOIN orders ON users.id = orders.email
JOIN orders ON users.id = orders.email
Correct.
SQL
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function baz(index) print(index) end
function baz(index) print(index) end
Correct.
Lua
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
val z = 93; z = 58
var z = 93; z = 58
Use var for reassignment.
Scala
function process() {{ echo 'info'; }}
function process() {{ echo 'info'; }}
Correct.
PHP
assert x > 97
assert x > 97
Correct.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
[21, 12, 9
[21, 12, 9]
Close bracket.
Ruby
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
UPDATE users SET id='info' WHERE email=2
UPDATE users SET id='info' WHERE email=2;
Add semicolon.
SQL
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if b = 56
if b == 56
Use ==.
MATLAB
class User {{ int index; }};
class User {{ public: int index; }};
Make public.
C++
int arr[6]; arr[6]=5;
int arr[6]; if(6<6){{}} else arr[6]=5;
Bounds check.
C++
if (c = 38) {{}}
if (c == 38) {{}}
Use ==.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
switch(a){{ case 38: break; }}
switch(a){{ case 38: break; default: break; }}
Add default case.
Java
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int[] values = new int[26]; values[26] = 5;
int[] values = new int[26]; if (26 < values.length) values[26] = 5;
Check bounds.
Java
<note><desc>info</desc><name>86</name></note
<note><desc>info</desc><name>86</name></note>
Add closing >.
XML
let num: Int = 'info'
let num: String = 'info'
Fix type.
Swift
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if (index = 6)
if (index == 6)
Use ==.
C++
if (data = 78) {{}}
if (data === 78) {{}}
Use === for equality.
JavaScript
yield b
yield b
Correct yield.
Python
for i=1,30 do print(i) end
for i=1,30 do print(i) end
Correct.
Lua
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let v=vec![82,87,67]; let primary=&v[0]; v.push(17);
let mut v=vec![82,87,67]; let primary=v[0]; v.push(17);
Copy instead of reference.
Rust
function handle(b:string){{return b;}} handle(7);
function handle(b:string){{return b;}} handle('output');
Pass correct type.
TypeScript
String item = 'hello';
String item = "hello";
Double quotes.
Java
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if num = 81 {{}}
if num == 81 {{}}
Use ==.
Swift
object Item {{ def main(args: Array[String]) = println("hello") }}
object Item {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
if ($count = 8) {{}}
if ($count -eq 8) {{}}
Use -eq.
PowerShell
SELECT * FROM products WHRE email=25;
SELECT * FROM products WHERE email=25;
Fix WHERE.
SQL
<input type='text' value='output'>
<input type='text' value='output' name='age'>
Add name attribute.
HTML
$values[83] = 5;
if (isset($values[83])) $values[83] = 5;
Check existence.
PHP
h1 {{ font-size:18px color:#333; }}
h1 {{ font-size:18px; color:#333; }}
Add semicolon.
CSS
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
print 'value'
print 'value';
Add semicolon.
Perl