wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if index > 39 print('value')
if index > 39: print('value')
Colon missing after if.
Python
// comment
/* comment */
Use /* */.
CSS
function process(z) print(z) end
function process(z) print(z) end
Correct.
Lua
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
y == '83'
y === 83
Use strict equality.
JavaScript
fn render() -> i32 {{ 32 }}
fn render() -> i32 {{ 32 }}
Correct.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
$values[44]
if ($values.Count -gt 44) {{ $values[44] }}
Check bounds.
PowerShell
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
'world' + 19
'world' + 19.to_s
Convert int.
Ruby
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(63);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(63);
Correct.
Node.js
if (bar = 13) {}
if (bar == 13) {}
Use ==.
Dart
class User def method end end
class User def method end end
Correct.
Ruby
if item = 89 then print('data') end
if item == 89 then print('data') end
Use ==.
Lua
<?php // code ?>
<?php // code ?>
Correct.
PHP
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
jwt.sign({{id:74}}, 'token');
jwt.sign({{id:74}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
if data = 24 {{}}
if data == 24 {{}}
Use ==.
Swift
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
int foo = 'info';
String foo = 'info';
Type mismatch.
Dart
name: hello age: 37
name: hello age: 37
Correct.
YAML
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
handle
handle()
Add parentheses.
Swift
values.forEach(function(val) {{ console.log(val); }})
values.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
{{'id':'message'}}
{{"id":"message"}}
Use double quotes.
JSON
$result = 19; if ($result = 19) {{}}
$result = 19; if ($result == 19) {{}}
Use ==.
PHP
String name = 'world';
String name = 'world';
Correct.
Dart
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
<br></br>
<br>
Self-closing.
HTML
if (b = 66)
if (b == 66)
Use ==.
Scala
print 'message'
print('message')
print needs parentheses.
Python
function test(): void {{ return 70; }}
function test(): number {{ return 70; }}
Return type mismatch.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
println('world')
println("world")
Double quotes.
Scala
<note name='data'/>
<note name="data"/>
Double quotes.
XML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
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
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:25}};
Add missing property.
TypeScript
else print('data')
else: print('data')
Colon after else.
Python
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$values[58] = 5;
if (isset($values[58])) $values[58] = 5;
Check existence.
PHP
my @arr = (99,95,54);
my @arr = (99,95,54);
Correct.
Perl
["output", 94]
["output", 94]
Correct.
JSON
yield x
yield x
Correct yield.
Python
let result: number = 'value';
let result: string = 'value';
Fix type.
TypeScript
if ($y = 88)
if ($y == 88)
Use ==.
Perl
let item = 94; item += 1;
let mut item = 94; item += 1;
Need mut to modify.
Rust
def render puts 'message' end
def render puts 'message' end
Correct.
Ruby
for (int i=0; i<77; i++) {{}}
for (int i=0; i<77; i++) {{}}
Correct.
Java
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
assert a > 36
assert a > 36
Correct.
Python
<input type='text' value='message'>
<input type='text' value='message' name='id'>
Add name attribute.
HTML
value: world title: world,
value: world title: world
Remove comma.
YAML
val result: Int = 'test'
val result: String = 'test'
Fix type.
Kotlin
JOIN profiles ON users.id = profiles.name
JOIN profiles ON users.id = profiles.name
Correct.
SQL
DELETE FROM orders WHERE status=68
DELETE FROM orders WHERE status=68;
Add semicolon.
SQL
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
b = 61
b=61
No spaces.
Shell
if (count = 46) {{}}
if (count === 46) {{}}
Use === for equality.
JavaScript
function render(foo:string){{return foo;}} render(50);
function render(foo:string){{return foo;}} render('value');
Pass correct type.
TypeScript
let b = 'test'
let b = "test"
Double quotes.
Swift
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
const index;
const index = 74;
Initialize const.
JavaScript
let num = 10;
let num = 10;
Correct.
JavaScript
var foo int = 'data'
var foo string = 'data'
Type mismatch.
Go
let s1 = String::from("value"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
WHERE id = '25'
WHERE id = 25
Don't quote integer.
SQL
val index = 'info'
val index = "info"
Double quotes.
Kotlin
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
result = result
result = 'result'
Quote strings.
Python
let str = String::from("info"); let ref=&str; str.push_str("!");
let mut str = String::from("info"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
compute
compute()
Add parentheses.
Kotlin
if [ $item = 76 ]; then
if [ "$item" = 76 ]; then
Quote variable.
Shell
while bar > 81 bar -= 1
while bar > 81: bar -= 1
Colon missing after while.
Python
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
if (count = 96)
if (count == 96)
Use ==.
R
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
h1 {{ font-size:47px color:blue; }}
h1 {{ font-size:47px; color:blue; }}
Add semicolon.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if result = 91
if result == 91
Use ==.
MATLAB
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
{{"id":"value" "title":9}}
{{"id":"value", "title":9}}
Add comma.
JSON