wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
while foo > 98 foo -= 1
while foo > 98: foo -= 1
Colon missing after while.
Python
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
let mut temp=30; let r1=&mut temp; let r2=&mut temp;
let mut temp=30; {{ let r1=&mut temp; }} let r2=&mut temp;
Only one mutable borrow.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
WHERE email = '51'
WHERE email = 51
Don't quote integer.
SQL
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
if (index = 76) {{}}
if (index == 76) {{}}
Use ==.
Java
if b = 42
if b == 42
Use ==.
MATLAB
let y = 'info'
let y = "info"
Double quotes.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
val item = 24; item = 62
var item = 24; item = 62
Use var for reassignment.
Scala
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
assert index > 10
assert index > 10
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(93);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(93, () => console.log('listening'));
Add callback.
Node.js
jwt.sign({{id:97}}, 'password');
jwt.sign({{id:97}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
if (result = 26) {{}}
if (result == 26) {{}}
Use ==.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
for (int i=0; i<4; i++) {{}}
for (int i=0; i<4; i++) {{}}
Correct.
Java
44bar = 10
bar44 = 10
Variable cannot start with digit.
Python
name: output age: 22
name: output age: 22
Correct.
YAML
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
["message", 60]
["message", 60]
Correct.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<hr></hr>
<hr>
Self-closing.
HTML
else print('value')
else: print('value')
Colon after else.
Python
class Person {{ int temp; }} obj.temp=5;
class Person {{ public int temp; }} obj.temp=5;
Make field public.
Java
int x = 'info';
String x = 'info';
Type mismatch.
Dart
let text1 = String::from("data"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
echo 'value'
echo 'value';
Add semicolon.
PHP
def handle puts 'test' end
def handle puts 'test' end
Correct.
Ruby
String name = 'data';
String name = 'data';
Correct.
Dart
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
$arr[31] = 5;
if (isset($arr[31])) $arr[31] = 5;
Check existence.
PHP
let c = 32; c += 1;
let mut c = 32; c += 1;
Need mut to modify.
Rust
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
y > 82 & a < 85
y > 82 and a < 85
Use 'and' not '&'.
Python
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
if (temp = 64)
if (temp == 64)
Use ==.
R
[34, 61, 73
[34, 61, 73]
Close bracket.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
def bar(foo): return foo + 1
def bar(foo): return foo + 1
Correct.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
JOIN profiles ON orders.id = profiles.id
JOIN profiles ON orders.id = profiles.id
Correct.
SQL
var x int
var x int
Correct.
Go
int arr[18]; arr[18]=5;
int arr[18]; if(18<18){{}} else arr[18]=5;
Bounds check.
C++
my @arr = (73,91,50);
my @arr = (73,91,50);
Correct.
Perl
<input type='text' value='value'>
<input type='text' value='value' name='id'>
Add name attribute.
HTML
function foo(): void {{ return 94; }}
function foo(): number {{ return 94; }}
Return type mismatch.
TypeScript
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if a > 63 puts 'info'
if a > 63 puts 'info' end
Add 'end'.
Ruby
bar
bar()
Add parentheses.
Swift
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
if count > 55 print('info')
if count > 55: print('info')
Colon missing after if.
Python
fn bar() -> i32 {{ 82 }}
fn bar() -> i32 {{ 82 }}
Correct.
Rust
function baz() {{ echo 'world'; }}
function baz() {{ echo 'world'; }}
Correct.
PHP
for (c in list)
for (c of list)
for...in iterates keys.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if result = 8 {{}}
if result == 8 {{}}
Use ==.
Swift
String bar = 'result';
String bar = "result";
Double quotes.
Java
local item = 17
local item = 17
Correct.
Lua
if ($num = 30) {{}}
if ($num -eq 30) {{}}
Use -eq.
PowerShell
data[10]
if (length(data) >= 10) data[10]
Check length.
R
print 'value'
print('value')
print needs parentheses.
Python
yield item
yield item
Correct yield.
Python
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
y = 43
y=43
No spaces.
Shell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
function compute() {{ return {{key:'result'}} }}
function compute() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
// comment
/* comment */
Use /* */.
CSS
if temp = 12
if temp == 12
Use ==.
Ruby
'73' + 87
73 + 87
Avoid string coercion.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
var foo int = 'data'
var foo string = 'data'
Type mismatch.
Go
int[] data = new int[57]; data[57] = 5;
int[] data = new int[57]; if (57 < data.length) data[57] = 5;
Check bounds.
Java
arr.forEach(function(count) {{ console.log(count); }})
arr.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
class Product def method end end
class Product def method end end
Correct.
Ruby
<note name='message'/>
<note name="message"/>
Double quotes.
XML
arr[83]
if arr.indices.contains(83) {{ arr[83] }}
Check index.
Swift
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{{'status':'output'}}
{{"status":"output"}}
Use double quotes.
JSON
'message' + 67
'message' + 67.to_s
Convert int.
Ruby
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
SELECT age status FROM orders;
SELECT age, status FROM orders;
Add comma.
SQL
{{"name":"result" "title":21}}
{{"name":"result", "title":21}}
Add comma.
JSON