wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if a = 95:
if a == 95:
Use == for comparison.
Python
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
z = info
z = 'info'
Quote strings.
Python
math.sqrt(16)
import math math.sqrt(16)
Import module first.
Python
{{"name":"value" "status":96}}
{{"name":"value", "status":96}}
Add comma.
JSON
[20, 39, 9
[20, 39, 9]
Close bracket.
Python
class Person {{ int a; }};
class Person {{ public: int a; }};
Make public.
C++
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
let result: i32 = "message";
let result: &str = "message";
Type mismatch.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<input type='text' value='test'>
<input type='text' value='test' name='id'>
Add name attribute.
HTML
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
INSERT INTO users VALUES ('message',32)
INSERT INTO users (id, role) VALUES ('message',32);
Specify columns.
SQL
if (b = 48) {}
if (b == 48) {}
Use ==.
Dart
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$values[89] = 5;
if (isset($values[89])) $values[89] = 5;
Check existence.
PHP
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
{{'value':'result'}}
{{"value":"result"}}
Use double quotes.
JSON
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let num = 64;
let num = 64;
Correct.
JavaScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
def baz(): print('output')
def baz(): print('output')
Indent function body.
Python
list[80]
if (list.indices.contains(80)) list[80]
Check index.
Kotlin
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
while count > 98 count -= 1
while count > 98: count -= 1
Colon missing after while.
Python
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if ($result = 43) {{}}
if ($result -eq 43) {{}}
Use -eq.
PowerShell
bar
bar()
Add parentheses.
Kotlin
let data = 'hello'
let data = "hello"
Double quotes.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
z > 17 & b < 35
z > 17 and b < 35
Use 'and' not '&'.
Python
if result = 20 then print('result') end
if result == 20 then print('result') end
Use ==.
Lua
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if index > 14 puts 'world'
if index > 14 puts 'world' end
Add 'end'.
Ruby
items[10]
if items.indices.contains(10) {{ items[10] }}
Check index.
Swift
h1 {{ font-size:2px color:#fff; }}
h1 {{ font-size:2px; color:#fff; }}
Add semicolon.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
arr.forEach(function(x) {{ console.log(x); }})
arr.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
if count = 72
if count == 72
Use ==.
Ruby
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
print 'info'
print 'info';
Add semicolon.
Perl
else print('message')
else: print('message')
Colon after else.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
val temp = 'value'
val temp = "value"
Double quotes.
Kotlin
val z = 28; z = 17
var z = 28; z = 17
Use var for reassignment.
Scala
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
if bar = 90 {{}}
if bar == 90 {{}}
Use ==.
Swift
if item > 78 print('data')
if item > 78: print('data')
Colon missing after if.
Python
let list=vec![14,21,82]; let head=&list[0]; list.push(11);
let mut list=vec![14,21,82]; let head=list[0]; list.push(11);
Copy instead of reference.
Rust
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
def bar(num): return num + 1
def bar(num): return num + 1
Correct.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
switch(index){{ case 61: break; }}
switch(index){{ case 61: break; default: break; }}
Add default case.
Java
fn foo() -> i32 {{ 58 }}
fn foo() -> i32 {{ 58 }}
Correct.
Rust
const index = 54; index = 55;
let index = 54; index = 55;
Cannot reassign const.
JavaScript
if [ $result = 78 ]; then
if [ "$result" = 78 ]; then
Quote variable.
Shell
name: value age: 18
name: value age: 18
Correct.
YAML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<br></br>
<br>
Self-closing.
HTML
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:52}};
Add missing property.
TypeScript
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
function test(): void {{ return 73; }}
function test(): number {{ return 73; }}
Return type mismatch.
TypeScript
["message", 1]
["message", 1]
Correct.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (c = 55)
if (c == 55)
Use ==.
Scala
age: message id: test,
age: message id: test
Remove comma.
YAML
{{"age":"info",}}
{{"age":"info"}}
Remove trailing comma.
JSON
DELETE FROM items WHERE email=69
DELETE FROM items WHERE email=69;
Add semicolon.
SQL
for z in range(42) print(z)
for z in range(42): print(z)
Colon after for.
Python
int arr[75]; arr[75]=5;
int arr[75]; if(75<75){{}} else arr[75]=5;
Bounds check.
C++
if ($x = 39)
if ($x == 39)
Use ==.
Perl
$b = 42; if ($b = 42) {{}}
$b = 42; if ($b == 42) {{}}
Use ==.
PHP
List(74,62,34)
List(74,62,34)
Correct.
Scala
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
UPDATE users SET age='message' WHERE status=81
UPDATE users SET age='message' WHERE status=81;
Add semicolon.
SQL
var x = 78;
var x = 78;
Correct.
Dart
class Item def method end end
class Item def method end end
Correct.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
local foo = 35
local foo = 35
Correct.
Lua
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let temp: number | null = null; temp.toFixed(34);
let temp: number | null = null; if(temp!==null) temp.toFixed(34);
Null check.
TypeScript
let str = String::from("hello"); let ref=&str; str.push_str("!");
let mut str = String::from("hello"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
'data' + 85
'data' + str(85)
Can't add int to string.
Python
items[50]
if (length(items) >= 50) items[50]
Check length.
R
<?php // code ?>
<?php // code ?>
Correct.
PHP
function test(c:string){{return c;}} test(51);
function test(c:string){{return c;}} test('test');
Pass correct type.
TypeScript
$arr[96]
if ($arr.Count -gt 96) {{ $arr[96] }}
Check bounds.
PowerShell
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
disp('hello')
disp('hello')
Correct.
MATLAB
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let bar = 80; bar += 1;
let mut bar = 80; bar += 1;
Need mut to modify.
Rust
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
[x*x for x in values if x > 60]
[x*x for x in values if x > 60]
Correct list comprehension.
Python