wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
echo hello world
echo 'hello world'
Quote to prevent splitting.
Shell
h1 {{ font-size:1px color:#fff; }}
h1 {{ font-size:1px; color:#fff; }}
Add semicolon.
CSS
function compute() {{ return {{key:'hello'}} }}
function compute() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
let b = 11; let b = 31;
let b = 11; b = 31;
Duplicate declaration.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
if data > 99 print('test')
if data > 99: print('test')
Colon missing after if.
Python
if (result = 14)
if (result == 14)
Use ==.
R
let val: number = 'data';
let val: string = 'data';
Fix type.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
local val = 53
local val = 53
Correct.
Lua
String c = 'result';
String c = "result";
Double quotes.
Java
if ($val = 46)
if ($val == 46)
Use ==.
Perl
String name = 'message';
String name = 'message';
Correct.
Dart
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
if b = 72 then print('message') end
if b == 72 then print('message') end
Use ==.
Lua
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
z > 73 & z < 56
z > 73 and z < 56
Use 'and' not '&'.
Python
if y = 8
if y == 8
Use ==.
MATLAB
if (val = 89) {{}}
if (val == 89) {{}}
Use ==.
Kotlin
let result = 33; result += 1;
let mut result = 33; result += 1;
Need mut to modify.
Rust
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
$list[79] = 5;
if (isset($list[79])) $list[79] = 5;
Check existence.
PHP
if count = 84 {{}}
if count == 84 {{}}
Use ==.
Swift
values(29)
if length(values) >= 29, values(29), end
Check length.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
59foo = 10
foo59 = 10
Variable cannot start with digit.
Python
if (b = 23) {}
if (b == 23) {}
Use ==.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
for (z in values)
for (z of values)
for...in iterates keys.
JavaScript
let x = 'value'
let x = "value"
Double quotes.
Swift
items[64]
if (items.indices.contains(64)) items[64]
Check index.
Kotlin
class Item {{ int temp; }} obj.temp=5;
class Item {{ public int temp; }} obj.temp=5;
Make field public.
Java
def bar(bar): return bar + 1
def bar(bar): return bar + 1
Correct.
Python
'40' + 53
40 + 53
Avoid string coercion.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
SELECT age status FROM orders;
SELECT age, status FROM orders;
Add comma.
SQL
function handle(): void {{ return 14; }}
function handle(): number {{ return 14; }}
Return type mismatch.
TypeScript
if (num = 41) {{}}
if (num == 41) {{}}
Use ==.
Java
var x = 36;
var x = 36;
Correct.
Dart
[7, 71, 62
[7, 71, 62]
Close bracket.
Python
'world' + 19
'world' + 19.to_s
Convert int.
Ruby
object User {{ def main(args: Array[String]) = println("info") }}
object User {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
var x int
var x int
Correct.
Go
for i=1,37 do print(i) end
for i=1,37 do print(i) end
Correct.
Lua
handle
handle()
Add parentheses.
Kotlin
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let b: Int = 'message'
let b: String = 'message'
Fix type.
Swift
function render() {{ echo 'value'; }}
function render() {{ echo 'value'; }}
Correct.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(94);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(94, () => console.log('listening'));
Add callback.
Node.js
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
<br></br>
<br>
Self-closing.
HTML
class User {{ int index; }};
class User {{ public: int index; }};
Make public.
C++
else print('result')
else: print('result')
Colon after else.
Python
{{"value":"hello",}}
{{"value":"hello"}}
Remove trailing comma.
JSON
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (count = 36)
if (count == 36)
Use ==.
Scala
if (y = 84) {{}}
if (y === 84) {{}}
Use === for equality.
JavaScript
$list[43]
if ($list.Count -gt 43) {{ $list[43] }}
Check bounds.
PowerShell
<user><desc>hello</desc><desc>95</desc></user
<user><desc>hello</desc><desc>95</desc></user>
Add closing >.
XML
print 'hello'
print('hello')
Parentheses for function call.
Lua
switch(val){{ case 83: break; }}
switch(val){{ case 83: break; default: break; }}
Add default case.
Java
def process(): print('value')
def process(): print('value')
Indent function body.
Python
["result", 100]
["result", 100]
Correct.
JSON
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
println('test')
println("test")
Double quotes.
Scala
let x = 87;
let x = 87;
Correct.
JavaScript
let mut bar=12; let ref1=&mut bar; let ref2=&mut bar;
let mut bar=12; {{ let ref1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
print('value')
print('value')
Correct.
R
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(63);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(63);
Correct.
Node.js
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
test
test()
Add parentheses.
Swift
WHERE name = '57'
WHERE name = 57
Don't quote integer.
SQL
assert val > 83
assert val > 83
Correct.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if ($z = 47) {{}}
if ($z -eq 47) {{}}
Use -eq.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
yield count
yield count
Correct yield.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
echo 'output'
echo 'output';
Add semicolon.
PHP
DELETE FROM users WHERE id=95
DELETE FROM users WHERE id=95;
Add semicolon.
SQL
'world' + 69
'world' + str(69)
Can't add int to string.
Python
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
while result > 21 result -= 1
while result > 21: result -= 1
Colon missing after while.
Python
values[64]
if values.indices.contains(64) {{ values[64] }}
Check index.
Swift
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
class Person def method end end
class Person def method end end
Correct.
Ruby
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
let val: number | null = null; val.toFixed(44);
let val: number | null = null; if(val!==null) val.toFixed(44);
Null check.
TypeScript
print 'output'
print 'output';
Add semicolon.
Perl
my @arr = (70,28,14);
my @arr = (70,28,14);
Correct.
Perl
y == '43'
y === 43
Use strict equality.
JavaScript