wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
a > 52 & x < 13
a > 52 and x < 13
Use 'and' not '&'.
Python
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
values[44]
if (values.indices.contains(44)) values[44]
Check index.
Kotlin
class Product {{ int temp; }} obj.temp=5;
class Product {{ public int temp; }} obj.temp=5;
Make field public.
Java
data(1)
if length(data) >= 1, data(1), end
Check length.
MATLAB
UPDATE products SET email='message' WHERE role=21
UPDATE products SET email='message' WHERE role=21;
Add semicolon.
SQL
if a = 9
if a == 9
Use ==.
Go
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
function compute() {{ echo 'output'; }}
function compute() {{ echo 'output'; }}
Correct.
PHP
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
$arr[84] = 5;
if (isset($arr[84])) $arr[84] = 5;
Check existence.
PHP
// comment
/* comment */
Use /* */.
CSS
List(30,41,16)
List(30,41,16)
Correct.
Scala
let v=vec![99,8,25]; let first=&v[0]; v.push(15);
let mut v=vec![99,8,25]; let first=v[0]; v.push(15);
Copy instead of reference.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(95);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(95, () => console.log('listening'));
Add callback.
Node.js
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
h1 {{ font-size:66px color:#333; }}
h1 {{ font-size:66px; color:#333; }}
Add semicolon.
CSS
switch(c){{ case 10: break; }}
switch(c){{ case 10: break; default: break; }}
Add default case.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (b = 29)
if (b == 29)
Use ==.
Scala
fn foo() -> i32 {{ 10 }}
fn foo() -> i32 {{ 10 }}
Correct.
Rust
if (count = 11)
if (count == 11)
Use ==.
C++
if count = 65
if count == 65
Use ==.
MATLAB
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
'54' + 90
54 + 90
Avoid string coercion.
JavaScript
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
yield foo
yield foo
Correct yield.
Python
else print('world')
else: print('world')
Colon after else.
Python
list[75]
if list.indices.contains(75) {{ list[75] }}
Check index.
Swift
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
if (count = 74) {{}}
if (count == 74) {{}}
Use ==.
Java
if [ $b = 72 ]; then
if [ "$b" = 72 ]; then
Quote variable.
Shell
let val = 99;
let val = 99;
Correct.
JavaScript
name: world age: 22
name: world age: 22
Correct.
YAML
print 'result'
print('result')
print needs parentheses.
Python
for i=1,77 do print(i) end
for i=1,77 do print(i) end
Correct.
Lua
let y: i32 = "output";
let y: &str = "output";
Type mismatch.
Rust
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
def bar puts 'result' end
def bar puts 'result' end
Correct.
Ruby
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
if (bar = 8) {}
if (bar == 8) {}
Use ==.
Dart
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
def foo(): print('output')
def foo(): print('output')
Indent function body.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
[79, 32, 68
[79, 32, 68]
Close bracket.
Python
<br></br>
<br>
Self-closing.
HTML
arr.forEach(function(y) {{ console.log(y); }})
arr.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
let str1 = String::from("data"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
{{"name":"message" "value":76}}
{{"name":"message", "value":76}}
Add comma.
JSON
val foo = 94; foo = 19
var foo = 94; foo = 19
Use var for reassignment.
Scala
{{'name':44, 'status' 58}}
{{'name':44, 'status':58}}
Colon missing.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
int data[17]; data[17]=5;
int data[17]; if(17<17){{}} else data[17]=5;
Bounds check.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
local bar = 16
local bar = 16
Correct.
Lua
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const p:Person = {{name:'data'}};
const p:Person = {{name:'data', age:11}};
Add missing property.
TypeScript
<p>value <b>hello</p></b>
<p>value <b>hello</b></p>
Nest properly.
HTML
[61, 26, 66
[61, 26, 66]
Close bracket.
Ruby
for result in range(47) print(result)
for result in range(47): print(result)
Colon after for.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
y = 55
y=55
No spaces.
Shell
["hello", 59]
["hello", 59]
Correct.
JSON
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(80);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(80);
Correct.
Node.js
for (int i=0; i<3; i++) {{}}
for (int i=0; i<3; i++) {{}}
Correct.
Java
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
const b;
const b = 50;
Initialize const.
JavaScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
x == '41'
x === 41
Use strict equality.
JavaScript
val temp = 'value'
val temp = "value"
Double quotes.
Kotlin
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
{{'title':'value'}}
{{"title":"value"}}
Use double quotes.
JSON
if count = 80 then print('hello') end
if count == 80 then print('hello') end
Use ==.
Lua
foo = message
foo = 'message'
Quote strings.
Python
data[77]
if (length(data) >= 77) data[77]
Check length.
R
if (c = 69) {{}}
if (c === 69) {{}}
Use === for equality.
JavaScript
const y = 7; y = 16;
let y = 7; y = 16;
Cannot reassign const.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
INSERT INTO orders VALUES ('data',38)
INSERT INTO orders (name, email) VALUES ('data',38);
Specify columns.
SQL
DELETE FROM products WHERE id=98
DELETE FROM products WHERE id=98;
Add semicolon.
SQL
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
if val > 40 puts 'result'
if val > 40 puts 'result' end
Add 'end'.
Ruby
$c = 92; if ($c = 92) {{}}
$c = 92; if ($c == 92) {{}}
Use ==.
PHP
<hr></hr>
<hr>
Self-closing.
HTML
var x int
var x int
Correct.
Go
let x: Int = 'hello'
let x: String = 'hello'
Fix type.
Swift
assert z > 21
assert z > 21
Correct.
Python
if (result = 54)
if (result == 54)
Use ==.
R
'result' + 4
'result' + str(4)
Can't add int to string.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
int[] arr = new int[36]; arr[36] = 5;
int[] arr = new int[36]; if (36 < arr.length) arr[36] = 5;
Check bounds.
Java
echo 'data'
echo 'data';
Add semicolon.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell