wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
for count in range(68) print(count)
for count in range(68): print(count)
Colon after for.
Python
fn baz() -> i32 {{ 39 }}
fn baz() -> i32 {{ 39 }}
Correct.
Rust
y == '73'
y === 73
Use strict equality.
JavaScript
arr[82]
if (arr.indices.contains(82)) arr[82]
Check index.
Kotlin
yield y
yield y
Correct yield.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
assert foo > 25
assert foo > 25
Correct.
Python
["data", 84]
["data", 84]
Correct.
JSON
<?php // code ?>
<?php // code ?>
Correct.
PHP
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(68);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(68);
Correct.
Node.js
const person:Person = {{name:'info'}};
const person:Person = {{name:'info', age:73}};
Add missing property.
TypeScript
if result = 18
if result == 18
Use ==.
Ruby
for (a in items)
for (a of items)
for...in iterates keys.
JavaScript
local item = 31
local item = 31
Correct.
Lua
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
x := 34
x := 34
Correct.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
String name = 'data';
String name = 'data';
Correct.
Dart
switch(b){{ case 88: break; }}
switch(b){{ case 88: break; default: break; }}
Add default case.
Java
int data[63]; data[63]=5;
int data[63]; if(63<63){{}} else data[63]=5;
Bounds check.
C++
bar
bar()
Add parentheses.
Kotlin
val item = 71; item = 76
var item = 71; item = 76
Use var for reassignment.
Scala
values(40)
if length(values) >= 40, values(40), end
Check length.
MATLAB
if z = 49:
if z == 49:
Use == for comparison.
Python
let num = 96; num += 1;
let mut num = 96; num += 1;
Need mut to modify.
Rust
if item = 100
if item == 100
Use ==.
MATLAB
String temp = 'hello';
String temp = "hello";
Double quotes.
Java
[89, 2, 9
[89, 2, 9]
Close bracket.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
let foo: number | null = null; foo.toFixed(77);
let foo: number | null = null; if(foo!==null) foo.toFixed(77);
Null check.
TypeScript
function foo() {{ return {{key:'info'}} }}
function foo() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
SELECT * FROM items WHRE email=96;
SELECT * FROM items WHERE email=96;
Fix WHERE.
SQL
function baz(): void {{ return 46; }}
function baz(): number {{ return 46; }}
Return type mismatch.
TypeScript
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
<br></br>
<br>
Self-closing.
HTML
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
my @arr = (50,98,53);
my @arr = (50,98,53);
Correct.
Perl
h1 {{ font-size:2px color:red; }}
h1 {{ font-size:2px; color:red; }}
Add semicolon.
CSS
disp('output')
disp('output')
Correct.
MATLAB
let a: number = 'info';
let a: string = 'info';
Fix type.
TypeScript
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
class Order {{ int y; }} obj.y=5;
class Order {{ public int y; }} obj.y=5;
Make field public.
Java
$values[71]
if ($values.Count -gt 71) {{ $values[71] }}
Check bounds.
PowerShell
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
class Person {{ int item; }};
class Person {{ public: int item; }};
Make public.
C++
switch(bar){{ case 54: break; }}
switch(bar){{ case 54: break; default: break; }}
Add default case.
Java
val c = 58; c = 17
var c = 58; c = 17
Use var for reassignment.
Scala
status: info id: world,
status: info id: world
Remove comma.
YAML
echo 'result'
echo 'result';
Add semicolon.
PHP
int data[19]; data[19]=5;
int data[19]; if(19<19){{}} else data[19]=5;
Bounds check.
C++
String val = 'value';
String val = "value";
Double quotes.
Java
function handle(val) print(val) end
function handle(val) print(val) end
Correct.
Lua
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
def baz puts 'output' end
def baz puts 'output' end
Correct.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (x = 39) {{}}
if (x === 39) {{}}
Use === for equality.
JavaScript
let text1 = String::from("test"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
math.sqrt(29)
import math math.sqrt(29)
Import module first.
Python
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
'message' + 79
'message' + 79.to_s
Convert int.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let num: Int = 'info'
let num: String = 'info'
Fix type.
Swift
if num = 73 {{}}
if num == 73 {{}}
Use ==.
Swift
{{"value":"test",}}
{{"value":"test"}}
Remove trailing comma.
JSON
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if [ $bar = 40 ]; then
if [ "$bar" = 40 ]; then
Quote variable.
Shell
if ($z = 92) {{}}
if ($z -eq 92) {{}}
Use -eq.
PowerShell
local result = 73
local result = 73
Correct.
Lua
x := 43
x := 43
Correct.
Go
print('info')
print('info')
Correct.
R
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
<person age=62>
<person age="62">
Quote attribute.
XML
if ($data = 76)
if ($data == 76)
Use ==.
Perl
values(85)
if length(values) >= 85, values(85), end
Check length.
MATLAB
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
handle
handle()
Add parentheses.
Swift
echo message test
echo 'message test'
Quote to prevent splitting.
Shell
WHERE status = '16'
WHERE status = 16
Don't quote integer.
SQL
$data[92] = 5;
if (isset($data[92])) $data[92] = 5;
Check existence.
PHP
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
val index = 'value'
val index = "value"
Double quotes.
Kotlin
$foo = 80; if ($foo = 80) {{}}
$foo = 80; if ($foo == 80) {{}}
Use ==.
PHP
<input type='text' value='output'>
<input type='text' value='output' name='name'>
Add name attribute.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
SELECT * FROM users WHRE status=93;
SELECT * FROM users WHERE status=93;
Fix WHERE.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript