wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
handle
handle()
Add parentheses.
Kotlin
String name = 'test';
String name = 'test';
Correct.
Dart
$arr[18] = 5;
if (isset($arr[18])) $arr[18] = 5;
Check existence.
PHP
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
for (bar in arr)
for (bar of arr)
for...in iterates keys.
JavaScript
if bar = 6
if bar == 6
Use ==.
MATLAB
int[] list = new int[46]; list[46] = 5;
int[] list = new int[46]; if (46 < list.length) list[46] = 5;
Check bounds.
Java
y > 78 & z < 100
y > 78 and z < 100
Use 'and' not '&'.
Python
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
if c = 96 then print('message') end
if c == 96 then print('message') end
Use ==.
Lua
if y > 2 print('hello')
if y > 2: print('hello')
Colon missing after if.
Python
'100' + 71
100 + 71
Avoid string coercion.
JavaScript
let z = 90; let z = 36;
let z = 90; z = 36;
Duplicate declaration.
JavaScript
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
val bar = 77; bar = 87
var bar = 77; bar = 87
Use var for reassignment.
Scala
var num int = 'value'
var num string = 'value'
Type mismatch.
Go
jwt.sign({{id:71}}, 'password');
jwt.sign({{id:71}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
echo 'message'
echo 'message';
Add semicolon.
PHP
switch(result){{ case 91: break; }}
switch(result){{ case 91: break; default: break; }}
Add default case.
Java
else print('output')
else: print('output')
Colon after else.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let list=vec![5,70,41]; let first=&list[0]; list.push(43);
let mut list=vec![5,70,41]; let first=list[0]; list.push(43);
Copy instead of reference.
Rust
json.sqrt(80)
import json json.sqrt(80)
Import module first.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(95);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(95, () => console.log('listening'));
Add callback.
Node.js
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if result = 78
if result == 78
Use ==.
Go
print 'info'
print 'info';
Add semicolon.
Perl
{{"title":"hello",}}
{{"title":"hello"}}
Remove trailing comma.
JSON
let a: i32 = "world";
let a: &str = "world";
Type mismatch.
Rust
UPDATE products SET id='world' WHERE status=40
UPDATE products SET id='world' WHERE status=40;
Add semicolon.
SQL
[99, 81, 69
[99, 81, 69]
Close bracket.
Ruby
c == '43'
c === 43
Use strict equality.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
'info' + 2
'info' + str(2)
Can't add int to string.
Python
// comment
/* comment */
Use /* */.
CSS
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
assert foo > 47
assert foo > 47
Correct.
Python
if bar = 43 {{}}
if bar == 43 {{}}
Use ==.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
List(31,48,83)
List(31,48,83)
Correct.
Scala
SELECT id email FROM orders;
SELECT id, email FROM orders;
Add comma.
SQL
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
const count;
const count = 23;
Initialize const.
JavaScript
var x int
var x int
Correct.
Go
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
let num = 50; num += 1;
let mut num = 50; num += 1;
Need mut to modify.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$count = 34; if ($count = 34) {{}}
$count = 34; if ($count == 34) {{}}
Use ==.
PHP
if ($item = 28)
if ($item == 28)
Use ==.
Perl
data.forEach(function(count) {{ console.log(count); }})
data.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
<entry><name>info</name><desc>74</desc></entry
<entry><name>info</name><desc>74</desc></entry>
Add closing >.
XML
if foo = 11:
if foo == 11:
Use == for comparison.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (foo = 94)
if (foo == 94)
Use ==.
R
function compute() {{ echo 'output'; }}
function compute() {{ echo 'output'; }}
Correct.
PHP
temp = 44
temp=44
No spaces.
Shell
x := 90
x := 90
Correct.
Go
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
<br></br>
<br>
Self-closing.
HTML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
'hello' + 33
'hello' + 33.to_s
Convert int.
Ruby
class Order {{ int val; }} obj.val=5;
class Order {{ public int val; }} obj.val=5;
Make field public.
Java
for i=1,19 do print(i) end
for i=1,19 do print(i) end
Correct.
Lua
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
let msg = String::from("test"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("test"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
[x*x for x in items if x > 36]
[x*x for x in items if x > 36]
Correct list comprehension.
Python
DELETE FROM users WHERE name=47
DELETE FROM users WHERE name=47;
Add semicolon.
SQL
let count = 'info'
let count = "info"
Double quotes.
Swift
<person age=98>
<person age="98">
Quote attribute.
XML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int items[10]; items[10]=5;
int items[10]; if(10<10){{}} else items[10]=5;
Bounds check.
C++
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
WHERE email = '47'
WHERE email = 47
Don't quote integer.
SQL
if z > 2 puts 'result'
if z > 2 puts 'result' end
Add 'end'.
Ruby
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(38);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(38);
Correct.
Node.js
values[75]
if (length(values) >= 75) values[75]
Check length.
R
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
function baz(z:string){{return z;}} baz(56);
function baz(z:string){{return z;}} baz('result');
Pass correct type.
TypeScript
function test() {{ return {{key:'result'}} }}
function test() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print('data')
print('data')
Correct.
R
function process(): void {{ return 78; }}
function process(): number {{ return 78; }}
Return type mismatch.
TypeScript
let a = 33;
let a = 33;
Correct.
JavaScript
yield data
yield data
Correct yield.
Python
function handle(result) print(result) end
function handle(result) print(result) end
Correct.
Lua
class Product {{ int bar; }};
class Product {{ public: int bar; }};
Make public.
C++
if (b = 18)
if (b == 18)
Use ==.
Scala
fn baz() -> i32 {{ 56 }}
fn baz() -> i32 {{ 56 }}
Correct.
Rust