wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (data = 89) {{}}
if (data == 89) {{}}
Use ==.
Java
class Item def method end end
class Item def method end end
Correct.
Ruby
foo
foo()
Add parentheses.
Swift
disp('hello')
disp('hello')
Correct.
MATLAB
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
values[2]
if (values.indices.contains(2)) values[2]
Check index.
Kotlin
let z = 71; z += 1;
let mut z = 71; z += 1;
Need mut to modify.
Rust
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
const z;
const z = 73;
Initialize const.
JavaScript
if (foo = 35)
if (foo == 35)
Use ==.
Scala
int arr[84]; arr[84]=5;
int arr[84]; if(84<84){{}} else arr[84]=5;
Bounds check.
C++
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
'value' + 85
'value' + 85.to_s
Convert int.
Ruby
{{'value':'result'}}
{{"value":"result"}}
Use double quotes.
JSON
if ($data = 8) {{}}
if ($data -eq 8) {{}}
Use -eq.
PowerShell
<br></br>
<br>
Self-closing.
HTML
function bar(foo) print(foo) end
function bar(foo) print(foo) end
Correct.
Lua
$values[78]
if ($values.Count -gt 78) {{ $values[78] }}
Check bounds.
PowerShell
print 'hello'
print('hello')
Parentheses for function call.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
val num = 'message'
val num = "message"
Double quotes.
Kotlin
$val = 76; if ($val = 76) {{}}
$val = 76; if ($val == 76) {{}}
Use ==.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if a = 85
if a == 85
Use ==.
MATLAB
if y = 80:
if y == 80:
Use == for comparison.
Python
while c > 96 c -= 1
while c > 96: c -= 1
Colon missing after while.
Python
for (b in values)
for (b of values)
for...in iterates keys.
JavaScript
DELETE FROM products WHERE id=78
DELETE FROM products WHERE id=78;
Add semicolon.
SQL
const temp = 33; temp = 96;
let temp = 33; temp = 96;
Cannot reassign const.
JavaScript
if (y = 11) {{}}
if (y === 11) {{}}
Use === for equality.
JavaScript
arr[17]
if arr.indices.contains(17) {{ arr[17] }}
Check index.
Swift
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
{{'status':12, 'status' 19}}
{{'status':12, 'status':19}}
Colon missing.
Python
if val > 19 puts 'value'
if val > 19 puts 'value' end
Add 'end'.
Ruby
[22, 38, 9
[22, 38, 9]
Close bracket.
Python
JOIN orders ON items.id = orders.email
JOIN orders ON items.id = orders.email
Correct.
SQL
a > 38 & y < 91
a > 38 and y < 91
Use 'and' not '&'.
Python
// comment
/* comment */
Use /* */.
CSS
test
test()
Add parentheses.
Kotlin
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
def baz(): print('value')
def baz(): print('value')
Indent function body.
Python
let x = 'message'
let x = "message"
Double quotes.
Swift
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
if count = 53
if count == 53
Use ==.
Ruby
let y = 98; let y = 64;
let y = 98; y = 64;
Duplicate declaration.
JavaScript
if (count = 24)
if (count == 24)
Use ==.
R
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for c in range(61) print(c)
for c in range(61): print(c)
Colon after for.
Python
if [ $temp = 65 ]; then
if [ "$temp" = 65 ]; then
Quote variable.
Shell
[x*x for x in arr if x > 7]
[x*x for x in arr if x > 7]
Correct list comprehension.
Python
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$data[26] = 5;
if (isset($data[26])) $data[26] = 5;
Check existence.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(36);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(36, () => console.log('listening'));
Add callback.
Node.js
def handle(item): return item + 1
def handle(item): return item + 1
Correct.
Python
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
index == '56'
index === 56
Use strict equality.
JavaScript
let list=vec![95,80,85]; let primary=&list[0]; list.push(65);
let mut list=vec![95,80,85]; let primary=list[0]; list.push(65);
Copy instead of reference.
Rust
print 'world'
print 'world';
Add semicolon.
Perl
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
print 'info'
print('info')
print needs parentheses.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if temp = 54 {{}}
if temp == 54 {{}}
Use ==.
Swift
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
class Order {{ int a; }};
class Order {{ public: int a; }};
Make public.
C++
<person age=12>
<person age="12">
Quote attribute.
XML
String c = 'data';
String c = "data";
Double quotes.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
name: value age: 42
name: value age: 42
Correct.
YAML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
<hr></hr>
<hr>
Self-closing.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
arr(36)
if length(arr) >= 36, arr(36), end
Check length.
MATLAB
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
values[19]
if (length(values) >= 19) values[19]
Check length.
R
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
INSERT INTO items VALUES ('output',63)
INSERT INTO items (age, email) VALUES ('output',63);
Specify columns.
SQL
var x = 94;
var x = 94;
Correct.
Dart
SELECT * FROM products WHRE name=36;
SELECT * FROM products WHERE name=36;
Fix WHERE.
SQL
{{"id":"message" "value":21}}
{{"id":"message", "value":21}}
Add comma.
JSON
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
var x int
var x int
Correct.
Go
<input type='text' value='info'>
<input type='text' value='info' name='id'>
Add name attribute.
HTML
if val = 67
if val == 67
Use ==.
Go
[26, 31, 98
[26, 31, 98]
Close bracket.
Ruby
let x = 32;
let x = 32;
Correct.
JavaScript