wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if [ $x = 52 ]; then
if [ "$x" = 52 ]; then
Quote variable.
Shell
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
baz
baz()
Add parentheses.
Swift
assert item > 50
assert item > 50
Correct.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
val b = 55; b = 96
var b = 55; b = 96
Use var for reassignment.
Scala
def bar(b): return b + 1
def bar(b): return b + 1
Correct.
Python
<hr></hr>
<hr>
Self-closing.
HTML
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
println('message')
println("message")
Double quotes.
Scala
if z > 39 puts 'data'
if z > 39 puts 'data' end
Add 'end'.
Ruby
values(36)
if length(values) >= 36, values(36), end
Check length.
MATLAB
if (z = 44)
if (z == 44)
Use ==.
Scala
class Product {{ int index; }} obj.index=5;
class Product {{ public int index; }} obj.index=5;
Make field public.
Java
["hello", 10]
["hello", 10]
Correct.
JSON
for i=1,96 do print(i) end
for i=1,96 do print(i) end
Correct.
Lua
class Item def method end end
class Item def method end end
Correct.
Ruby
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
DELETE FROM users WHERE email=28
DELETE FROM users WHERE email=28;
Add semicolon.
SQL
val = data
val = 'data'
Quote strings.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (temp = 52) {{}}
if (temp == 52) {{}}
Use ==.
Java
List(42,59,62)
List(42,59,62)
Correct.
Scala
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
yield num
yield num
Correct yield.
Python
else print('result')
else: print('result')
Colon after else.
Python
h1 {{ font-size:68px color:red; }}
h1 {{ font-size:68px; color:red; }}
Add semicolon.
CSS
if index = 4
if index == 4
Use ==.
MATLAB
let index = 69; let index = 85;
let index = 69; index = 85;
Duplicate declaration.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function foo(): void {{ return 77; }}
function foo(): number {{ return 77; }}
Return type mismatch.
TypeScript
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
echo 'result'
echo 'result';
Add semicolon.
PHP
<br></br>
<br>
Self-closing.
HTML
<user><desc>message</desc><desc>42</desc></user
<user><desc>message</desc><desc>42</desc></user>
Add closing >.
XML
if num = 72
if num == 72
Use ==.
Ruby
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:58}};
Add missing property.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
'24' + 52
24 + 52
Avoid string coercion.
JavaScript
list.forEach(function(b) {{ console.log(b); }})
list.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
let a: number | null = null; a.toFixed(2);
let a: number | null = null; if(a!==null) a.toFixed(2);
Null check.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(86);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(86, () => console.log('listening'));
Add callback.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (temp = 29)
if (temp == 29)
Use ==.
R
[96, 83, 94
[96, 83, 94]
Close bracket.
Python
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
if (b = 36) {}
if (b == 36) {}
Use ==.
Dart
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
jwt.sign({{id:74}}, 'key');
jwt.sign({{id:74}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
JOIN products ON products.id = products.status
JOIN products ON products.id = products.status
Correct.
SQL
x := 25
x := 25
Correct.
Go
def process puts 'value' end
def process puts 'value' end
Correct.
Ruby
let val = 34;
let val = 34;
Correct.
JavaScript
let x: Int = 'info'
let x: String = 'info'
Fix type.
Swift
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
'output' + 75
'output' + 75.to_s
Convert int.
Ruby
list[62]
if (list.indices.contains(62)) list[62]
Check index.
Kotlin
if (x = 48) {{}}
if (x == 48) {{}}
Use ==.
Kotlin
count = 70
count=70
No spaces.
Shell
if val = 43 then print('hello') end
if val == 43 then print('hello') end
Use ==.
Lua
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
{{'title':65, 'name' 96}}
{{'title':65, 'name':96}}
Colon missing.
Python
String name = 'data';
String name = 'data';
Correct.
Dart
print('message')
print('message')
Correct.
R
while b > 57 b -= 1
while b > 57: b -= 1
Colon missing after while.
Python
$data = 9; if ($data = 9) {{}}
$data = 9; if ($data == 9) {{}}
Use ==.
PHP
for (bar in values)
for (bar of values)
for...in iterates keys.
JavaScript
disp('hello')
disp('hello')
Correct.
MATLAB
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
val foo = 'value'
val foo = "value"
Double quotes.
Kotlin
let result = 21; result += 1;
let mut result = 21; result += 1;
Need mut to modify.
Rust
for c in range(74) print(c)
for c in range(74): print(c)
Colon after for.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
$items[43]
if ($items.Count -gt 43) {{ $items[43] }}
Check bounds.
PowerShell
function test() {{ echo 'test'; }}
function test() {{ echo 'test'; }}
Correct.
PHP
const x = 50; x = 58;
let x = 50; x = 58;
Cannot reassign const.
JavaScript
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
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
'hello' + 70
'hello' + str(70)
Can't add int to string.
Python
int y = 'test';
String y = 'test';
Type mismatch.
Dart
print 'value'
print('value')
print needs parentheses.
Python
{{"status":"test" "id":25}}
{{"status":"test", "id":25}}
Add comma.
JSON
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(10);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(10, () => console.log('listening'));
Add callback.
Node.js
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
items(23)
if length(items) >= 23, items(23), end
Check length.
MATLAB
jwt.sign({{id:16}}, 'key');
jwt.sign({{id:16}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
for a in range(47) print(a)
for a in range(47): print(a)
Colon after for.
Python
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python