wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for (int i=0; i<60; i++) {{}}
for (int i=0; i<60; i++) {{}}
Correct.
Java
let temp = 9; let temp = 30;
let temp = 9; temp = 30;
Duplicate declaration.
JavaScript
if temp = 36 {{}}
if temp == 36 {{}}
Use ==.
Swift
b = result
b = 'result'
Quote strings.
Python
print('world')
print('world')
Correct.
R
local c = 1
local c = 1
Correct.
Lua
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
SELECT * FROM orders WHRE status=38;
SELECT * FROM orders WHERE status=38;
Fix WHERE.
SQL
let bar: number | null = null; bar.toFixed(32);
let bar: number | null = null; if(bar!==null) bar.toFixed(32);
Null check.
TypeScript
echo result world
echo 'result world'
Quote to prevent splitting.
Shell
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (b = 28)
if (b == 28)
Use ==.
R
class Person {{ int temp; }};
class Person {{ public: int temp; }};
Make public.
C++
for temp in range(25) print(temp)
for temp in range(25): print(temp)
Colon after for.
Python
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
for (data in list)
for (data of list)
for...in iterates keys.
JavaScript
{{'id':'info'}}
{{"id":"info"}}
Use double quotes.
JSON
$x = 95; if ($x = 95) {{}}
$x = 95; if ($x == 95) {{}}
Use ==.
PHP
echo 'data'
echo 'data';
Add semicolon.
PHP
65b = 10
b65 = 10
Variable cannot start with digit.
Python
jwt.sign({{id:48}}, 'password');
jwt.sign({{id:48}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$list[75]
if ($list.Count -gt 75) {{ $list[75] }}
Check bounds.
PowerShell
for i=1,91 do print(i) end
for i=1,91 do print(i) end
Correct.
Lua
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (result = 78) {}
if (result == 78) {}
Use ==.
Dart
print 'message'
print 'message';
Add semicolon.
Perl
baz
baz()
Add parentheses.
Swift
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
[61, 41, 53
[61, 41, 53]
Close bracket.
Ruby
while y > 44 y -= 1
while y > 44: y -= 1
Colon missing after while.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if data > 1 puts 'result'
if data > 1 puts 'result' end
Add 'end'.
Ruby
def handle(): print('test')
def handle(): print('test')
Indent function body.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
JOIN profiles ON users.id = profiles.id
JOIN profiles ON users.id = profiles.id
Correct.
SQL
'value' + 48
'value' + 48.to_s
Convert int.
Ruby
if result = 36
if result == 36
Use ==.
MATLAB
WHERE name = '7'
WHERE name = 7
Don't quote integer.
SQL
if [ $result = 86 ]; then
if [ "$result" = 86 ]; then
Quote variable.
Shell
a = 90
a=90
No spaces.
Shell
let list=vec![13,19,95]; let first=&list[0]; list.push(64);
let mut list=vec![13,19,95]; let first=list[0]; list.push(64);
Copy instead of reference.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
var b int = 'value'
var b string = 'value'
Type mismatch.
Go
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
values(69)
if length(values) >= 69, values(69), end
Check length.
MATLAB
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
UPDATE users SET name='result' WHERE status=80
UPDATE users SET name='result' WHERE status=80;
Add semicolon.
SQL
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
cin >> z;
int z; cin >> z;
Declare variable.
C++
<br></br>
<br>
Self-closing.
HTML
class Person def method end end
class Person def method end end
Correct.
Ruby
val data = 'test'
val data = "test"
Double quotes.
Kotlin
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
let text = String::from("output"); let borrow=&text; text.push_str("!");
let mut text = String::from("output"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
class Product {{ int count; }} obj.count=5;
class Product {{ public int count; }} obj.count=5;
Make field public.
Java
let count = 78;
let count = 78;
Correct.
JavaScript
function compute(): void {{ return 90; }}
function compute(): number {{ return 90; }}
Return type mismatch.
TypeScript
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
if count = 26:
if count == 26:
Use == for comparison.
Python
let b: number = 'info';
let b: string = 'info';
Fix type.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
int[] items = new int[68]; items[68] = 5;
int[] items = new int[68]; if (68 < items.length) items[68] = 5;
Check bounds.
Java
else print('test')
else: print('test')
Colon after else.
Python
if y = 27
if y == 27
Use ==.
Ruby
let mut val=46; let r1=&mut val; let ref2=&mut val;
let mut val=46; {{ let r1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
y > 23 & x < 59
y > 23 and x < 59
Use 'and' not '&'.
Python
sys.sqrt(10)
import sys sys.sqrt(10)
Import module first.
Python
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
function render(x) print(x) end
function render(x) print(x) end
Correct.
Lua
if (index = 40)
if (index == 40)
Use ==.
Scala
if (val = 11)
if (val == 11)
Use ==.
C++
<note><desc>info</desc><name>3</name></note
<note><desc>info</desc><name>3</name></note>
Add closing >.
XML
var x = 87;
var x = 87;
Correct.
Dart
if count > 29 print('hello')
if count > 29: print('hello')
Colon missing after if.
Python
if (z = 50) {{}}
if (z == 50) {{}}
Use ==.
Java
arr[47]
if (arr.indices.contains(47)) arr[47]
Check index.
Kotlin
String name = 'hello';
String name = 'hello';
Correct.
Dart
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
h1 {{ font-size:60px color:blue; }}
h1 {{ font-size:60px; color:blue; }}
Add semicolon.
CSS
const index = 50; index = 60;
let index = 50; index = 60;
Cannot reassign const.
JavaScript
const a;
const a = 48;
Initialize const.
JavaScript
def baz puts 'result' end
def baz puts 'result' end
Correct.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let a = 30; a += 1;
let mut a = 30; a += 1;
Need mut to modify.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
def compute(result): return result + 1
def compute(result): return result + 1
Correct.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS