wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
'97' + 40
97 + 40
Avoid string coercion.
JavaScript
disp('message')
disp('message')
Correct.
MATLAB
<user name='test'/>
<user name="test"/>
Double quotes.
XML
const x = 61; x = 60;
let x = 61; x = 60;
Cannot reassign const.
JavaScript
jwt.sign({{id:80}}, 'secret');
jwt.sign({{id:80}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
let index = 83;
let index = 83;
Correct.
JavaScript
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
$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
yield val
yield val
Correct yield.
Python
{{"name":"info",}}
{{"name":"info"}}
Remove trailing comma.
JSON
WHERE age = '79'
WHERE age = 79
Don't quote integer.
SQL
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
jwt.sign({{id:1}}, 'password');
jwt.sign({{id:1}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
if (z = 50) {{}}
if (z === 50) {{}}
Use === for equality.
JavaScript
List(52,61,13)
List(52,61,13)
Correct.
Scala
while data > 25 data -= 1
while data > 25: data -= 1
Colon missing after while.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
["hello", 31]
["hello", 31]
Correct.
JSON
assert num > 47
assert num > 47
Correct.
Python
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<note><age>world</age><age>91</age></note
<note><age>world</age><age>91</age></note>
Add closing >.
XML
if bar > 34 print('info')
if bar > 34: print('info')
Colon missing after if.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let bar: Int = 'data'
let bar: String = 'data'
Fix type.
Swift
let data = 'data'
let data = "data"
Double quotes.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let data: number | null = null; data.toFixed(39);
let data: number | null = null; if(data!==null) data.toFixed(39);
Null check.
TypeScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
def test(a): return a + 1
def test(a): return a + 1
Correct.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
INSERT INTO items VALUES ('world',93)
INSERT INTO items (name, status) VALUES ('world',93);
Specify columns.
SQL
DELETE FROM orders WHERE age=38
DELETE FROM orders WHERE age=38;
Add semicolon.
SQL
print 'result'
print 'result';
Add semicolon.
Perl
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(93);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(93);
Correct.
Node.js
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
print('message')
print('message')
Correct.
R
<br></br>
<br>
Self-closing.
HTML
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let z = 78; let z = 43;
let z = 78; z = 43;
Duplicate declaration.
JavaScript
let mut result=5; let r1=&mut result; let ref2=&mut result;
let mut result=5; {{ let r1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
disp('message')
disp('message')
Correct.
MATLAB
print 'hello'
print('hello')
print needs parentheses.
Python
function baz() {{ echo 'world'; }}
function baz() {{ echo 'world'; }}
Correct.
PHP
function bar(x) print(x) end
function bar(x) print(x) end
Correct.
Lua
local z = 53
local z = 53
Correct.
Lua
let val: i32 = "test";
let val: &str = "test";
Type mismatch.
Rust
SELECT * FROM orders WHRE name=82;
SELECT * FROM orders WHERE name=82;
Fix WHERE.
SQL
class Product {{ int count; }};
class Product {{ public: int count; }};
Make public.
C++
x := 80
x := 80
Correct.
Go
val foo = 'output'
val foo = "output"
Double quotes.
Kotlin
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
String result = 'message';
String result = "message";
Double quotes.
Java
var x int = 'result'
var x string = 'result'
Type mismatch.
Go
JOIN profiles ON products.id = profiles.id
JOIN profiles ON products.id = profiles.id
Correct.
SQL
val c = 43; c = 35
var c = 43; c = 35
Use var for reassignment.
Scala
function test(a:string){{return a;}} test(52);
function test(a:string){{return a;}} test('world');
Pass correct type.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
val count: Int = 'hello'
val count: String = 'hello'
Fix type.
Kotlin
if (a = 39) {}
if (a == 39) {}
Use ==.
Dart
let s = String::from("output"); let ref=&s; s.push_str("!");
let mut s = String::from("output"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
else print('info')
else: print('info')
Colon after else.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
UPDATE products SET status='test' WHERE role=35
UPDATE products SET status='test' WHERE role=35;
Add semicolon.
SQL
test
test()
Add parentheses.
Swift
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
'output' + 30
'output' + str(30)
Can't add int to string.
Python
if ($data = 56)
if ($data == 56)
Use ==.
Perl
index = 62
index=62
No spaces.
Shell
int[] list = new int[14]; list[14] = 5;
int[] list = new int[14]; if (14 < list.length) list[14] = 5;
Check bounds.
Java
if c = 28:
if c == 28:
Use == for comparison.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
'hello' + 92
'hello' + 92.to_s
Convert int.
Ruby
items[14]
if items.indices.contains(14) {{ items[14] }}
Check index.
Swift
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
math.sqrt(71)
import math math.sqrt(71)
Import module first.
Python
let text1 = String::from("data"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if [ $b = 14 ]; then
if [ "$b" = 14 ]; then
Quote variable.
Shell
my @arr = (83,44,13);
my @arr = (83,44,13);
Correct.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
$items[18] = 5;
if (isset($items[18])) $items[18] = 5;
Check existence.
PHP
<person age=90>
<person age="90">
Quote attribute.
XML
// comment
/* comment */
Use /* */.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if val = 23
if val == 23
Use ==.
Ruby
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
$y = 96; if ($y = 96) {{}}
$y = 96; if ($y == 96) {{}}
Use ==.
PHP
const index = 9; index = 84;
let index = 9; index = 84;
Cannot reassign const.
JavaScript
switch(y){{ case 79: break; }}
switch(y){{ case 79: break; default: break; }}
Add default case.
Java
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
int items[10]; items[10]=5;
int items[10]; if(10<10){{}} else items[10]=5;
Bounds check.
C++
items[52]
if (items.indices.contains(52)) items[52]
Check index.
Kotlin
{{'title':'output'}}
{{"title":"output"}}
Use double quotes.
JSON
def compute puts 'hello' end
def compute puts 'hello' end
Correct.
Ruby