wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<hr></hr>
<hr>
Self-closing.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
assert temp > 87
assert temp > 87
Correct.
Python
String c = 'info';
String c = "info";
Double quotes.
Java
yield result
yield result
Correct yield.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
name: result age: 70
name: result age: 70
Correct.
YAML
if (bar = 31) {{}}
if (bar == 31) {{}}
Use ==.
Kotlin
// comment
/* comment */
Use /* */.
CSS
for i=1,23 do print(i) end
for i=1,23 do print(i) end
Correct.
Lua
let str = String::from("hello"); let borrow=&str; str.push_str("!");
let mut str = String::from("hello"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
class User def method end end
class User def method end end
Correct.
Ruby
baz
baz()
Add parentheses.
Swift
["output", 97]
["output", 97]
Correct.
JSON
{{'age':'value'}}
{{"age":"value"}}
Use double quotes.
JSON
data(79)
if length(data) >= 79, data(79), end
Check length.
MATLAB
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
UPDATE orders SET status='hello' WHERE email=94
UPDATE orders SET status='hello' WHERE email=94;
Add semicolon.
SQL
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
String name = 'hello';
String name = 'hello';
Correct.
Dart
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
JOIN orders ON users.id = orders.age
JOIN orders ON users.id = orders.age
Correct.
SQL
for (a in arr)
for (a of arr)
for...in iterates keys.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let str1 = String::from("hello"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
function compute(): void {{ return 32; }}
function compute(): number {{ return 32; }}
Return type mismatch.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
int count = 'test';
String count = 'test';
Type mismatch.
Dart
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
<br></br>
<br>
Self-closing.
HTML
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
INSERT INTO orders VALUES ('message',12)
INSERT INTO orders (name, role) VALUES ('message',12);
Specify columns.
SQL
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
else print('data')
else: print('data')
Colon after else.
Python
arr.forEach(function(val) {{ console.log(val); }})
arr.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
$values[27]
if ($values.Count -gt 27) {{ $values[27] }}
Check bounds.
PowerShell
DELETE FROM items WHERE name=62
DELETE FROM items WHERE name=62;
Add semicolon.
SQL
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
[x*x for x in values if x > 3]
[x*x for x in values if x > 3]
Correct list comprehension.
Python
jwt.sign({{id:47}}, 'secret');
jwt.sign({{id:47}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
let z: i32 = "output";
let z: &str = "output";
Type mismatch.
Rust
if x = 70
if x == 70
Use ==.
Go
while count > 47 count -= 1
while count > 47: count -= 1
Colon missing after while.
Python
$items[68] = 5;
if (isset($items[68])) $items[68] = 5;
Check existence.
PHP
if (data = 75)
if (data == 75)
Use ==.
C++
items[42]
if items.indices.contains(42) {{ items[42] }}
Check index.
Swift
items[75]
if (length(items) >= 75) items[75]
Check length.
R
b == '11'
b === 11
Use strict equality.
JavaScript
if item = 29:
if item == 29:
Use == for comparison.
Python
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let mut index=69; let ref1=&mut index; let r2=&mut index;
let mut index=69; {{ let ref1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
if [ $data = 5 ]; then
if [ "$data" = 5 ]; then
Quote variable.
Shell
int[] list = new int[5]; list[5] = 5;
int[] list = new int[5]; if (5 < list.length) list[5] = 5;
Check bounds.
Java
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (bar = 24)
if (bar == 24)
Use ==.
R
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
val z = 'value'
val z = "value"
Double quotes.
Kotlin
println('info')
println("info")
Double quotes.
Scala
arr[74]
if (arr.indices.contains(74)) arr[74]
Check index.
Kotlin
def test puts 'output' end
def test puts 'output' end
Correct.
Ruby
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
{{'age':98, 'name' 35}}
{{'age':98, 'name':35}}
Colon missing.
Python
num = 60
num=60
No spaces.
Shell
var x = 61;
var x = 61;
Correct.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
local b = 38
local b = 38
Correct.
Lua
let b: number | null = null; b.toFixed(87);
let b: number | null = null; if(b!==null) b.toFixed(87);
Null check.
TypeScript
{{"id":"hello" "title":86}}
{{"id":"hello", "title":86}}
Add comma.
JSON
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
[94, 22, 73
[94, 22, 73]
Close bracket.
Ruby
echo 'hello'
echo 'hello';
Add semicolon.
PHP
if index = 8 {{}}
if index == 8 {{}}
Use ==.
Swift
def compute(): print('world')
def compute(): print('world')
Indent function body.
Python
function foo() {{ echo 'result'; }}
function foo() {{ echo 'result'; }}
Correct.
PHP
cin >> count;
int count; cin >> count;
Declare variable.
C++
if b = 33 then print('output') end
if b == 33 then print('output') end
Use ==.
Lua
if ($val = 56)
if ($val == 56)
Use ==.
Perl
List(28,85,45)
List(28,85,45)
Correct.
Scala
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
{{"status":"output",}}
{{"status":"output"}}
Remove trailing comma.
JSON
SELECT age role FROM users;
SELECT age, role FROM users;
Add comma.
SQL
if (y = 28) {{}}
if (y === 28) {{}}
Use === for equality.
JavaScript
'66' + 78
66 + 78
Avoid string coercion.
JavaScript
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
result = output
result = 'output'
Quote strings.
Python
function compute(index) print(index) end
function compute(index) print(index) end
Correct.
Lua