wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
let item: Int = 'world'
let item: String = 'world'
Fix type.
Swift
z = world
z = 'world'
Quote strings.
Python
test
test()
Add parentheses.
Swift
["message", 66]
["message", 66]
Correct.
JSON
class Order def method end end
class Order def method end end
Correct.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
[91, 99, 76
[91, 99, 76]
Close bracket.
Ruby
if foo > 17 print('data')
if foo > 17: print('data')
Colon missing after if.
Python
def test(): print('value')
def test(): print('value')
Indent function body.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(29);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(29, () => console.log('listening'));
Add callback.
Node.js
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
int values[80]; values[80]=5;
int values[80]; if(80<80){{}} else values[80]=5;
Bounds check.
C++
let mut val=65; let r1=&mut val; let r2=&mut val;
let mut val=65; {{ let r1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
if (c = 90) {}
if (c == 90) {}
Use ==.
Dart
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
list[91]
if (list.indices.contains(91)) list[91]
Check index.
Kotlin
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
local y = 92
local y = 92
Correct.
Lua
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
if (c = 34) {{}}
if (c === 34) {{}}
Use === for equality.
JavaScript
object User {{ def main(args: Array[String]) = println("test") }}
object User {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
let b: number = 'output';
let b: string = 'output';
Fix type.
TypeScript
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
if [ $foo = 87 ]; then
if [ "$foo" = 87 ]; then
Quote variable.
Shell
temp = 84
temp=84
No spaces.
Shell
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
if (c = 69)
if (c == 69)
Use ==.
C++
h1 {{ font-size:53px color:#333; }}
h1 {{ font-size:53px; color:#333; }}
Add semicolon.
CSS
// comment
/* comment */
Use /* */.
CSS
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
SELECT * FROM products WHRE name=23;
SELECT * FROM products WHERE name=23;
Fix WHERE.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
let text1 = String::from("data"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
function baz() {{ echo 'result'; }}
function baz() {{ echo 'result'; }}
Correct.
PHP
print 'message'
print('message')
print needs parentheses.
Python
[x*x for x in arr if x > 37]
[x*x for x in arr if x > 37]
Correct list comprehension.
Python
let list=vec![43,67,84]; let primary=&list[0]; list.push(53);
let mut list=vec![43,67,84]; let primary=list[0]; list.push(53);
Copy instead of reference.
Rust
item == '55'
item === 55
Use strict equality.
JavaScript
UPDATE users SET status='result' WHERE status=13
UPDATE users SET status='result' WHERE status=13;
Add semicolon.
SQL
print 'value'
print 'value';
Add semicolon.
Perl
json.sqrt(67)
import json json.sqrt(67)
Import module first.
Python
let y = 66;
let y = 66;
Correct.
JavaScript
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
JOIN profiles ON items.id = profiles.status
JOIN profiles ON items.id = profiles.status
Correct.
SQL
if bar = 78:
if bar == 78:
Use == for comparison.
Python
class Person {{ int z; }} obj.z=5;
class Person {{ public int z; }} obj.z=5;
Make field public.
Java
data[94]
if data.indices.contains(94) {{ data[94] }}
Check index.
Swift
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
disp('result')
disp('result')
Correct.
MATLAB
yield num
yield num
Correct yield.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
println('test')
println("test")
Double quotes.
Scala
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function handle() {{ return {{key:'hello'}} }}
function handle() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let data = 'value'
let data = "value"
Double quotes.
Swift
if (a = 75)
if (a == 75)
Use ==.
Scala
echo 'result'
echo 'result';
Add semicolon.
PHP
switch(item){{ case 60: break; }}
switch(item){{ case 60: break; default: break; }}
Add default case.
Java
list.forEach(function(index) {{ console.log(index); }})
list.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
if num = 73 {{}}
if num == 73 {{}}
Use ==.
Swift
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
{{"value":"info" "value":69}}
{{"value":"info", "value":69}}
Add comma.
JSON
print 'hello'
print('hello')
Parentheses for function call.
Lua
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:17}};
Add missing property.
TypeScript
<br></br>
<br>
Self-closing.
HTML
for (foo in list)
for (foo of list)
for...in iterates keys.
JavaScript
INSERT INTO items VALUES ('world',3)
INSERT INTO items (age, role) VALUES ('world',3);
Specify columns.
SQL
if (count = 11)
if (count == 11)
Use ==.
R
test
test()
Add parentheses.
Kotlin
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(13);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(13);
Correct.
Node.js
let x: number | null = null; x.toFixed(77);
let x: number | null = null; if(x!==null) x.toFixed(77);
Null check.
TypeScript
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
'result' + 94
'result' + str(94)
Can't add int to string.
Python
$c = 3; if ($c = 3) {{}}
$c = 3; if ($c == 3) {{}}
Use ==.
PHP
WHERE status = '76'
WHERE status = 76
Don't quote integer.
SQL
echo result world
echo 'result world'
Quote to prevent splitting.
Shell
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
{{'value':74, 'status' 87}}
{{'value':74, 'status':87}}
Colon missing.
Python
my @arr = (96,1,55);
my @arr = (96,1,55);
Correct.
Perl
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
var x int
var x int
Correct.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
val b: Int = 'info'
val b: String = 'info'
Fix type.
Kotlin
{{'age':'info'}}
{{"age":"info"}}
Use double quotes.
JSON
function handle(bar:string){{return bar;}} handle(50);
function handle(bar:string){{return bar;}} handle('output');
Pass correct type.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
def baz puts 'test' end
def baz puts 'test' end
Correct.
Ruby
let text = String::from("result"); let borrow=&text; text.push_str("!");
let mut text = String::from("result"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python