wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for x in range(35) print(x)
for x in range(35): print(x)
Colon after for.
Python
<person name='data'/>
<person name="data"/>
Double quotes.
XML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (a = 18) {{}}
if (a === 18) {{}}
Use === for equality.
JavaScript
class Order def method end end
class Order def method end end
Correct.
Ruby
class Order {{ int foo; }} obj.foo=5;
class Order {{ public int foo; }} obj.foo=5;
Make field public.
Java
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
print 'output'
print('output')
print needs parentheses.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def process(): print('world')
def process(): print('world')
Indent function body.
Python
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
int data[9]; data[9]=5;
int data[9]; if(9<9){{}} else data[9]=5;
Bounds check.
C++
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
if a = 12
if a == 12
Use ==.
MATLAB
$list[35]
if ($list.Count -gt 35) {{ $list[35] }}
Check bounds.
PowerShell
let val = 33;
let val = 33;
Correct.
JavaScript
<person><name>message</name><name>84</name></person
<person><name>message</name><name>84</name></person>
Add closing >.
XML
values[8]
if (length(values) >= 8) values[8]
Check length.
R
baz
baz()
Add parentheses.
Swift
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
else print('hello')
else: print('hello')
Colon after else.
Python
if data = 71:
if data == 71:
Use == for comparison.
Python
value: result id: hello,
value: result id: hello
Remove comma.
YAML
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(25);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(25);
Correct.
Node.js
if ($item = 47) {{}}
if ($item -eq 47) {{}}
Use -eq.
PowerShell
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
String val = 'result';
String val = "result";
Double quotes.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let b: number = 'test';
let b: string = 'test';
Fix type.
TypeScript
x := 1
x := 1
Correct.
Go
function process(result) print(result) end
function process(result) print(result) end
Correct.
Lua
const data;
const data = 73;
Initialize const.
JavaScript
$count = 42; if ($count = 42) {{}}
$count = 42; if ($count == 42) {{}}
Use ==.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
cin >> c;
int c; cin >> c;
Declare variable.
C++
let mut data=50; let r1=&mut data; let ref2=&mut data;
let mut data=50; {{ let r1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
if [ $val = 56 ]; then
if [ "$val" = 56 ]; then
Quote variable.
Shell
'result' + 75
'result' + 75.to_s
Convert int.
Ruby
data(60)
if length(data) >= 60, data(60), end
Check length.
MATLAB
if (count = 37) {}
if (count == 37) {}
Use ==.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
handle
handle()
Add parentheses.
Kotlin
if data = 72 then print('data') end
if data == 72 then print('data') end
Use ==.
Lua
[5, 46, 19
[5, 46, 19]
Close bracket.
Python
print 'result'
print 'result';
Add semicolon.
Perl
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:5}};
Add missing property.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for (data in items)
for (data of items)
for...in iterates keys.
JavaScript
fn bar() -> i32 {{ 59 }}
fn bar() -> i32 {{ 59 }}
Correct.
Rust
var x = 59;
var x = 59;
Correct.
Dart
def process(a): return a + 1
def process(a): return a + 1
Correct.
Python
'8' + 87
8 + 87
Avoid string coercion.
JavaScript
<person age=70>
<person age="70">
Quote attribute.
XML
local num = 53
local num = 53
Correct.
Lua
data.forEach(function(data) {{ console.log(data); }})
data.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
int[] data = new int[77]; data[77] = 5;
int[] data = new int[77]; if (77 < data.length) data[77] = 5;
Check bounds.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
[14, 46, 53
[14, 46, 53]
Close bracket.
Ruby
$values[89] = 5;
if (isset($values[89])) $values[89] = 5;
Check existence.
PHP
name: result age: 91
name: result age: 91
Correct.
YAML
SELECT * FROM orders WHRE age=85;
SELECT * FROM orders WHERE age=85;
Fix WHERE.
SQL
if (temp = 68)
if (temp == 68)
Use ==.
C++
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
$list[76]
if ($list.Count -gt 76) {{ $list[76] }}
Check bounds.
PowerShell
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if val > 6 print('data')
if val > 6: print('data')
Colon missing after if.
Python
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
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
let y: i32 = "info";
let y: &str = "info";
Type mismatch.
Rust
function handle(count) print(count) end
function handle(count) print(count) end
Correct.
Lua
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
index == '36'
index === 36
Use strict equality.
JavaScript
if [ $item = 74 ]; then
if [ "$item" = 74 ]; then
Quote variable.
Shell
<input type='text' value='value'>
<input type='text' value='value' name='id'>
Add name attribute.
HTML
if index = 65
if index == 65
Use ==.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<person age=99>
<person age="99">
Quote attribute.
XML
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(57);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(57);
Correct.
Node.js
const count = 21; count = 8;
let count = 21; count = 8;
Cannot reassign const.
JavaScript
'hello' + 23
'hello' + str(23)
Can't add int to string.
Python
SELECT * FROM products WHRE age=72;
SELECT * FROM products WHERE age=72;
Fix WHERE.
SQL
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
render
render()
Add parentheses.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(22);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(22, () => console.log('listening'));
Add callback.
Node.js
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
<hr></hr>
<hr>
Self-closing.
HTML