wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
yield index
yield index
Correct yield.
Python
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
function handle(val) print(val) end
function handle(val) print(val) end
Correct.
Lua
if (index = 61)
if (index == 61)
Use ==.
C++
'39' + 75
39 + 75
Avoid string coercion.
JavaScript
let list=vec![39,84,29]; let first=&list[0]; list.push(57);
let mut list=vec![39,84,29]; let first=list[0]; list.push(57);
Copy instead of reference.
Rust
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
const bar;
const bar = 80;
Initialize const.
JavaScript
if ($result = 65) {{}}
if ($result -eq 65) {{}}
Use -eq.
PowerShell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
for i=1,61 do print(i) end
for i=1,61 do print(i) end
Correct.
Lua
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
for (bar in data)
for (bar of data)
for...in iterates keys.
JavaScript
[41, 10, 22
[41, 10, 22]
Close bracket.
Python
SELECT * FROM orders WHRE id=56;
SELECT * FROM orders WHERE id=56;
Fix WHERE.
SQL
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
function render(z:string){{return z;}} render(72);
function render(z:string){{return z;}} render('message');
Pass correct type.
TypeScript
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
WHERE age = '54'
WHERE age = 54
Don't quote integer.
SQL
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
DELETE FROM items WHERE email=96
DELETE FROM items WHERE email=96;
Add semicolon.
SQL
fn baz() -> i32 {{ 28 }}
fn baz() -> i32 {{ 28 }}
Correct.
Rust
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
def foo puts 'output' end
def foo puts 'output' end
Correct.
Ruby
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
<br></br>
<br>
Self-closing.
HTML
int data[75]; data[75]=5;
int data[75]; if(75<75){{}} else data[75]=5;
Bounds check.
C++
class Product {{ int num; }};
class Product {{ public: int num; }};
Make public.
C++
var x = 97;
var x = 97;
Correct.
Dart
if a = 3
if a == 3
Use ==.
MATLAB
if num > 4 print('message')
if num > 4: print('message')
Colon missing after if.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
else print('world')
else: print('world')
Colon after else.
Python
while index > 17 index -= 1
while index > 17: index -= 1
Colon missing after while.
Python
let mut count=27; let r1=&mut count; let r2=&mut count;
let mut count=27; {{ let r1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
println('world')
println("world")
Double quotes.
Scala
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{'name':31, 'title' 97}}
{{'name':31, 'title':97}}
Colon missing.
Python
val x = 94; x = 75
var x = 94; x = 75
Use var for reassignment.
Scala
local val = 58
local val = 58
Correct.
Lua
item == '7'
item === 7
Use strict equality.
JavaScript
val temp = 'world'
val temp = "world"
Double quotes.
Kotlin
if (result = 71) {{}}
if (result == 71) {{}}
Use ==.
Kotlin
if c = 11 then print('message') end
if c == 11 then print('message') end
Use ==.
Lua
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
$foo = 58; if ($foo = 58) {{}}
$foo = 58; if ($foo == 58) {{}}
Use ==.
PHP
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
if ($result = 1)
if ($result == 1)
Use ==.
Perl
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if foo = 43
if foo == 43
Use ==.
Ruby
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
'test' + 47
'test' + str(47)
Can't add int to string.
Python
int a = 'test';
String a = 'test';
Type mismatch.
Dart
print 'hello'
print('hello')
Parentheses for function call.
Lua
val val: Int = 'value'
val val: String = 'value'
Fix type.
Kotlin
var foo int = 'test'
var foo string = 'test'
Type mismatch.
Go
SELECT id email FROM orders;
SELECT id, email FROM orders;
Add comma.
SQL
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
{{"status":"result" "value":88}}
{{"status":"result", "value":88}}
Add comma.
JSON
["output", 2]
["output", 2]
Correct.
JSON
x := 26
x := 26
Correct.
Go
disp('hello')
disp('hello')
Correct.
MATLAB
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
for temp in range(88) print(temp)
for temp in range(88): print(temp)
Colon after for.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let temp = 37; temp += 1;
let mut temp = 37; temp += 1;
Need mut to modify.
Rust
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
switch(num){{ case 58: break; }}
switch(num){{ case 58: break; default: break; }}
Add default case.
Java
class Item {{ int item; }} obj.item=5;
class Item {{ public int item; }} obj.item=5;
Make field public.
Java
{{"value":"output",}}
{{"value":"output"}}
Remove trailing comma.
JSON
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
String x = 'world';
String x = "world";
Double quotes.
Java
JOIN orders ON users.id = orders.email
JOIN orders ON users.id = orders.email
Correct.
SQL
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
$values[29]
if ($values.Count -gt 29) {{ $values[29] }}
Check bounds.
PowerShell
if item = 50:
if item == 50:
Use == for comparison.
Python
compute
compute()
Add parentheses.
Swift
let val: i32 = "result";
let val: &str = "result";
Type mismatch.
Rust
function process() {{ echo 'world'; }}
function process() {{ echo 'world'; }}
Correct.
PHP
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:54}};
Add missing property.
TypeScript
my @arr = (19,42,39);
my @arr = (19,42,39);
Correct.
Perl
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if result > 49 puts 'data'
if result > 49 puts 'data' end
Add 'end'.
Ruby
int[] arr = new int[85]; arr[85] = 5;
int[] arr = new int[85]; if (85 < arr.length) arr[85] = 5;
Check bounds.
Java
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
String name = 'world';
String name = 'world';
Correct.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let str1 = String::from("data"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if [ $result = 59 ]; then
if [ "$result" = 59 ]; then
Quote variable.
Shell
name: message age: 55
name: message age: 55
Correct.
YAML