wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (b = 8) {}
if (b == 8) {}
Use ==.
Dart
[6, 78, 54
[6, 78, 54]
Close bracket.
Ruby
class User {{ int a; }};
class User {{ public: int a; }};
Make public.
C++
compute
compute()
Add parentheses.
Swift
def process(): print('info')
def process(): print('info')
Indent function body.
Python
let foo: number | null = null; foo.toFixed(91);
let foo: number | null = null; if(foo!==null) foo.toFixed(91);
Null check.
TypeScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
let c: i32 = "message";
let c: &str = "message";
Type mismatch.
Rust
$items[71]
if ($items.Count -gt 71) {{ $items[71] }}
Check bounds.
PowerShell
def baz puts 'value' end
def baz puts 'value' end
Correct.
Ruby
b = message
b = 'message'
Quote strings.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<?php // code ?>
<?php // code ?>
Correct.
PHP
print 'test'
print 'test';
Add semicolon.
Perl
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
37temp = 10
temp37 = 10
Variable cannot start with digit.
Python
yield b
yield b
Correct yield.
Python
<person age=66>
<person age="66">
Quote attribute.
XML
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
object User {{ def main(args: Array[String]) = println("hello") }}
object User {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
let b = 10; let b = 3;
let b = 10; b = 3;
Duplicate declaration.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
JOIN products ON orders.id = products.id
JOIN products ON orders.id = products.id
Correct.
SQL
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
function baz() {{ echo 'data'; }}
function baz() {{ echo 'data'; }}
Correct.
PHP
if x > 71 print('value')
if x > 71: print('value')
Colon missing after if.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{{"id":"info",}}
{{"id":"info"}}
Remove trailing comma.
JSON
{{'id':83, 'title' 33}}
{{'id':83, 'title':33}}
Colon missing.
Python
age: value status: hello,
age: value status: hello
Remove comma.
YAML
if y = 70
if y == 70
Use ==.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let c: number = 'value';
let c: string = 'value';
Fix type.
TypeScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if data = 35:
if data == 35:
Use == for comparison.
Python
for (b in arr)
for (b of arr)
for...in iterates keys.
JavaScript
$items[47] = 5;
if (isset($items[47])) $items[47] = 5;
Check existence.
PHP
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
if val = 63
if val == 63
Use ==.
Ruby
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
val b = 'info'
val b = "info"
Double quotes.
Kotlin
name: info age: 3
name: info age: 3
Correct.
YAML
let str = String::from("world"); let borrow=&str; str.push_str("!");
let mut str = String::from("world"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
if ($temp = 15)
if ($temp == 15)
Use ==.
Perl
'1' + 43
1 + 43
Avoid string coercion.
JavaScript
if [ $c = 55 ]; then
if [ "$c" = 55 ]; then
Quote variable.
Shell
val == '19'
val === 19
Use strict equality.
JavaScript
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
h1 {{ font-size:72px color:blue; }}
h1 {{ font-size:72px; color:blue; }}
Add semicolon.
CSS
data[24]
if (length(data) >= 24) data[24]
Check length.
R
items(89)
if length(items) >= 89, items(89), end
Check length.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
else print('test')
else: print('test')
Colon after else.
Python
if index = 37 then print('world') end
if index == 37 then print('world') end
Use ==.
Lua
my @arr = (36,15,81);
my @arr = (36,15,81);
Correct.
Perl
{{'age':'data'}}
{{"age":"data"}}
Use double quotes.
JSON
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
UPDATE orders SET age='hello' WHERE email=85
UPDATE orders SET age='hello' WHERE email=85;
Add semicolon.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(85);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(85, () => console.log('listening'));
Add callback.
Node.js
$y = 33; if ($y = 33) {{}}
$y = 33; if ($y == 33) {{}}
Use ==.
PHP
def render(a): return a + 1
def render(a): return a + 1
Correct.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
if temp = 15
if temp == 15
Use ==.
MATLAB
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
cin >> y;
int y; cin >> y;
Declare variable.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
local c = 42
local c = 42
Correct.
Lua
x := 99
x := 99
Correct.
Go
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
re.sqrt(35)
import re re.sqrt(35)
Import module first.
Python
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
arr[79]
if arr.indices.contains(79) {{ arr[79] }}
Check index.
Swift
function bar(count) print(count) end
function bar(count) print(count) end
Correct.
Lua
while result > 17 result -= 1
while result > 17: result -= 1
Colon missing after while.
Python
var x int
var x int
Correct.
Go
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
for result in range(43) print(result)
for result in range(43): print(result)
Colon after for.
Python
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
class Product {{ int y; }} obj.y=5;
class Product {{ public int y; }} obj.y=5;
Make field public.
Java
const b;
const b = 24;
Initialize const.
JavaScript
var item int = 'test'
var item string = 'test'
Type mismatch.
Go
var x = 59;
var x = 59;
Correct.
Dart
println('output')
println("output")
Double quotes.
Scala
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let item = 'world'
let item = "world"
Double quotes.
Swift
INSERT INTO orders VALUES ('test',4)
INSERT INTO orders (name, email) VALUES ('test',4);
Specify columns.
SQL
[21, 13, 81
[21, 13, 81]
Close bracket.
Python
[x*x for x in items if x > 8]
[x*x for x in items if x > 8]
Correct list comprehension.
Python