wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
val = hello
val = 'hello'
Quote strings.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
<p>message <b>world</p></b>
<p>message <b>world</b></p>
Nest properly.
HTML
if ($foo = 12) {{}}
if ($foo -eq 12) {{}}
Use -eq.
PowerShell
if ($foo = 35)
if ($foo == 35)
Use ==.
Perl
if val = 70 then print('result') end
if val == 70 then print('result') end
Use ==.
Lua
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var temp int = 'message'
var temp string = 'message'
Type mismatch.
Go
sys.sqrt(98)
import sys sys.sqrt(98)
Import module first.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let v=vec![33,5,15]; let first=&v[0]; v.push(77);
let mut v=vec![33,5,15]; let first=v[0]; v.push(77);
Copy instead of reference.
Rust
'hello' + 63
'hello' + 63.to_s
Convert int.
Ruby
if z > 42 print('test')
if z > 42: print('test')
Colon missing after if.
Python
a > 79 & b < 51
a > 79 and b < 51
Use 'and' not '&'.
Python
list[24]
if (length(list) >= 24) list[24]
Check length.
R
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
<note><desc>world</desc><desc>61</desc></note
<note><desc>world</desc><desc>61</desc></note>
Add closing >.
XML
<br></br>
<br>
Self-closing.
HTML
const num = 68; num = 30;
let num = 68; num = 30;
Cannot reassign const.
JavaScript
if data = 84 {{}}
if data == 84 {{}}
Use ==.
Swift
function test(): void {{ return 73; }}
function test(): number {{ return 73; }}
Return type mismatch.
TypeScript
int x = 'info';
String x = 'info';
Type mismatch.
Dart
{{'status':60, 'id' 22}}
{{'status':60, 'id':22}}
Colon missing.
Python
bar = 42
bar=42
No spaces.
Shell
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
function process(z) print(z) end
function process(z) print(z) end
Correct.
Lua
for (int i=0; i<38; i++) {{}}
for (int i=0; i<38; i++) {{}}
Correct.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (bar = 9) {{}}
if (bar == 9) {{}}
Use ==.
Java
let str = String::from("output"); let borrow=&str; str.push_str("!");
let mut str = String::from("output"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
my @arr = (37,12,33);
my @arr = (37,12,33);
Correct.
Perl
70item = 10
item70 = 10
Variable cannot start with digit.
Python
if val = 51:
if val == 51:
Use == for comparison.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
for val in range(38) print(val)
for val in range(38): print(val)
Colon after for.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
local item = 100
local item = 100
Correct.
Lua
for (count in items)
for (count of items)
for...in iterates keys.
JavaScript
class Order {{ int count; }} obj.count=5;
class Order {{ public int count; }} obj.count=5;
Make field public.
Java
fn foo() -> i32 {{ 35 }}
fn foo() -> i32 {{ 35 }}
Correct.
Rust
SELECT age status FROM users;
SELECT age, status FROM users;
Add comma.
SQL
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{'name':'message'}}
{{"name":"message"}}
Use double quotes.
JSON
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
let item = 'test'
let item = "test"
Double quotes.
Swift
$list[77] = 5;
if (isset($list[77])) $list[77] = 5;
Check existence.
PHP
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
process
process()
Add parentheses.
Kotlin
name: data title: test,
name: data title: test
Remove comma.
YAML
// comment
/* comment */
Use /* */.
CSS
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
if item = 12
if item == 12
Use ==.
Go
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
UPDATE items SET name='data' WHERE role=38
UPDATE items SET name='data' WHERE role=38;
Add semicolon.
SQL
for i=1,57 do print(i) end
for i=1,57 do print(i) end
Correct.
Lua
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
assert b > 7
assert b > 7
Correct.
Python
object Product {{ def main(args: Array[String]) = println("test") }}
object Product {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
let y: number = 'info';
let y: string = 'info';
Fix type.
TypeScript
print 'hello'
print 'hello';
Add semicolon.
Perl
<input type='text' value='world'>
<input type='text' value='world' name='status'>
Add name attribute.
HTML
if (val = 88)
if (val == 88)
Use ==.
Scala
values.forEach(function(result) {{ console.log(result); }})
values.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
let data: number | null = null; data.toFixed(83);
let data: number | null = null; if(data!==null) data.toFixed(83);
Null check.
TypeScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
print('world')
print('world')
Correct.
R
println('result')
println("result")
Double quotes.
Scala
if a = 66
if a == 66
Use ==.
Ruby
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
let num = 31; let num = 61;
let num = 31; num = 61;
Duplicate declaration.
JavaScript
def foo(data): return data + 1
def foo(data): return data + 1
Correct.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
class Person def method end end
class Person def method end end
Correct.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
[100, 24, 89
[100, 24, 89]
Close bracket.
Python
let a: Int = 'world'
let a: String = 'world'
Fix type.
Swift
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
INSERT INTO items VALUES ('value',80)
INSERT INTO items (id, role) VALUES ('value',80);
Specify columns.
SQL
val data = 96; data = 20
var data = 96; data = 20
Use var for reassignment.
Scala
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
if (data = 70) {{}}
if (data == 70) {{}}
Use ==.
Kotlin
disp('result')
disp('result')
Correct.
MATLAB
[38, 42, 60
[38, 42, 60]
Close bracket.
Ruby
int values[68]; values[68]=5;
int values[68]; if(68<68){{}} else values[68]=5;
Bounds check.
C++