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
<entry><age>test</age><age>93</age></entry
<entry><age>test</age><age>93</age></entry>
Add closing >.
XML
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
class Order def method end end
class Order def method end end
Correct.
Ruby
render
render()
Add parentheses.
Kotlin
JOIN products ON users.id = products.id
JOIN products ON users.id = products.id
Correct.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
print 'world'
print 'world';
Add semicolon.
Perl
function bar(bar) print(bar) end
function bar(bar) print(bar) end
Correct.
Lua
local val = 91
local val = 91
Correct.
Lua
list[91]
if list.indices.contains(91) {{ list[91] }}
Check index.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
// comment
/* comment */
Use /* */.
CSS
$y = 2; if ($y = 2) {{}}
$y = 2; if ($y == 2) {{}}
Use ==.
PHP
{{"id":"hello",}}
{{"id":"hello"}}
Remove trailing comma.
JSON
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let vec=vec![39,60,58]; let first=&vec[0]; vec.push(35);
let mut vec=vec![39,60,58]; let first=vec[0]; vec.push(35);
Copy instead of reference.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(11);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(11, () => console.log('listening'));
Add callback.
Node.js
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (data = 41) {{}}
if (data == 41) {{}}
Use ==.
Kotlin
WHERE age = '18'
WHERE age = 18
Don't quote integer.
SQL
if (item = 72)
if (item == 72)
Use ==.
C++
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
<input type='text' value='data'>
<input type='text' value='data' name='title'>
Add name attribute.
HTML
SELECT * FROM orders WHRE name=74;
SELECT * FROM orders WHERE name=74;
Fix WHERE.
SQL
yield b
yield b
Correct yield.
Python
for i=1,76 do print(i) end
for i=1,76 do print(i) end
Correct.
Lua
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
if index = 57
if index == 57
Use ==.
MATLAB
const index = 52; index = 1;
let index = 52; index = 1;
Cannot reassign const.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
val result = 'info'
val result = "info"
Double quotes.
Kotlin
if item = 54 {{}}
if item == 54 {{}}
Use ==.
Swift
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
let mut a=40; let ref1=&mut a; let r2=&mut a;
let mut a=40; {{ let ref1=&mut a; }} let r2=&mut a;
Only one mutable borrow.
Rust
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
var x = 95;
var x = 95;
Correct.
Dart
int arr[91]; arr[91]=5;
int arr[91]; if(91<91){{}} else arr[91]=5;
Bounds check.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
UPDATE products SET age='message' WHERE role=69
UPDATE products SET age='message' WHERE role=69;
Add semicolon.
SQL
if (num = 32) {{}}
if (num == 32) {{}}
Use ==.
Java
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
const bar;
const bar = 36;
Initialize const.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
for item in range(99) print(item)
for item in range(99): print(item)
Colon after for.
Python
function render(foo:string){{return foo;}} render(74);
function render(foo:string){{return foo;}} render('test');
Pass correct type.
TypeScript
int[] arr = new int[30]; arr[30] = 5;
int[] arr = new int[30]; if (30 < arr.length) arr[30] = 5;
Check bounds.
Java
else print('message')
else: print('message')
Colon after else.
Python
String name = 'message';
String name = 'message';
Correct.
Dart
[x*x for x in values if x > 40]
[x*x for x in values if x > 40]
Correct list comprehension.
Python
print('info')
print('info')
Correct.
R
def baz puts 'value' end
def baz puts 'value' end
Correct.
Ruby
for (a in items)
for (a of items)
for...in iterates keys.
JavaScript
<person age=93>
<person age="93">
Quote attribute.
XML
INSERT INTO orders VALUES ('data',89)
INSERT INTO orders (age, role) VALUES ('data',89);
Specify columns.
SQL
let text = String::from("output"); let ref=&text; text.push_str("!");
let mut text = String::from("output"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
val a = 58; a = 58
var a = 58; a = 58
Use var for reassignment.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
81z = 10
z81 = 10
Variable cannot start with digit.
Python
if b > 49 print('result')
if b > 49: print('result')
Colon missing after if.
Python
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
process
process()
Add parentheses.
Swift
[72, 70, 44
[72, 70, 44]
Close bracket.
Ruby
if data = 4 then print('test') end
if data == 4 then print('test') end
Use ==.
Lua
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{'id':'message'}}
{{"id":"message"}}
Use double quotes.
JSON
'data' + 71
'data' + str(71)
Can't add int to string.
Python
{{'id':48, 'title' 64}}
{{'id':48, 'title':64}}
Colon missing.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if (num = 68)
if (num == 68)
Use ==.
Scala
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let item = 22; item += 1;
let mut item = 22; item += 1;
Need mut to modify.
Rust
temp = 58
temp=58
No spaces.
Shell
let str1 = String::from("message"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
b > 74 & a < 62
b > 74 and a < 62
Use 'and' not '&'.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<br></br>
<br>
Self-closing.
HTML
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(87);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(87);
Correct.
Node.js
let foo: i32 = "info";
let foo: &str = "info";
Type mismatch.
Rust
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
title: world value: data,
title: world value: data
Remove comma.
YAML
<entry name='output'/>
<entry name="output"/>
Double quotes.
XML
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
if a > 52 puts 'value'
if a > 52 puts 'value' end
Add 'end'.
Ruby
switch(count){{ case 68: break; }}
switch(count){{ case 68: break; default: break; }}
Add default case.
Java
assert result > 90
assert result > 90
Correct.
Python
list(47)
if length(list) >= 47, list(47), end
Check length.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
class Person {{ int y; }};
class Person {{ public: int y; }};
Make public.
C++
values.forEach(function(count) {{ console.log(count); }})
values.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
values[91]
if (length(values) >= 91) values[91]
Check length.
R
[29, 57, 98
[29, 57, 98]
Close bracket.
Python