wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
<person age=89>
<person age="89">
Quote attribute.
XML
if (y = 45)
if (y == 45)
Use ==.
Scala
[14, 74, 85
[14, 74, 85]
Close bracket.
Python
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
let index = 6; let index = 27;
let index = 6; index = 27;
Duplicate declaration.
JavaScript
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
let c: number | null = null; c.toFixed(64);
let c: number | null = null; if(c!==null) c.toFixed(64);
Null check.
TypeScript
<br></br>
<br>
Self-closing.
HTML
def compute(): print('hello')
def compute(): print('hello')
Indent function body.
Python
my @arr = (78,46,44);
my @arr = (78,46,44);
Correct.
Perl
if ($result = 81) {{}}
if ($result -eq 81) {{}}
Use -eq.
PowerShell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(84);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(84, () => console.log('listening'));
Add callback.
Node.js
while data > 91 data -= 1
while data > 91: data -= 1
Colon missing after while.
Python
println('output')
println("output")
Double quotes.
Scala
{{"title":"value" "title":57}}
{{"title":"value", "title":57}}
Add comma.
JSON
for (int i=0; i<83; i++) {{}}
for (int i=0; i<83; i++) {{}}
Correct.
Java
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(63);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(63);
Correct.
Node.js
DELETE FROM users WHERE name=75
DELETE FROM users WHERE name=75;
Add semicolon.
SQL
WHERE email = '52'
WHERE email = 52
Don't quote integer.
SQL
jwt.sign({{id:74}}, 'secret');
jwt.sign({{id:74}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
List(78,42,8)
List(78,42,8)
Correct.
Scala
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
val a = 'result'
val a = "result"
Double quotes.
Kotlin
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
'88' + 5
88 + 5
Avoid string coercion.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
local a = 64
local a = 64
Correct.
Lua
UPDATE orders SET email='info' WHERE email=95
UPDATE orders SET email='info' WHERE email=95;
Add semicolon.
SQL
yield result
yield result
Correct yield.
Python
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:98}};
Add missing property.
TypeScript
{{'id':91, 'title' 39}}
{{'id':91, 'title':39}}
Colon missing.
Python
print 'result'
print 'result';
Add semicolon.
Perl
title: output value: data,
title: output value: data
Remove comma.
YAML
function bar(item:string){{return item;}} bar(79);
function bar(item:string){{return item;}} bar('info');
Pass correct type.
TypeScript
INSERT INTO orders VALUES ('hello',53)
INSERT INTO orders (name, status) VALUES ('hello',53);
Specify columns.
SQL
function handle() {{ echo 'test'; }}
function handle() {{ echo 'test'; }}
Correct.
PHP
if (foo = 98) {{}}
if (foo == 98) {{}}
Use ==.
Java
echo world world
echo 'world world'
Quote to prevent splitting.
Shell
item == '62'
item === 62
Use strict equality.
JavaScript
class Item {{ int y; }} obj.y=5;
class Item {{ public int y; }} obj.y=5;
Make field public.
Java
val b: Int = 'value'
val b: String = 'value'
Fix type.
Kotlin
let a = 93; a += 1;
let mut a = 93; a += 1;
Need mut to modify.
Rust
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
print 'test'
print('test')
print needs parentheses.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
arr(100)
if length(arr) >= 100, arr(100), end
Check length.
MATLAB
else print('message')
else: print('message')
Colon after else.
Python
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
let str = String::from("message"); let ref=&str; str.push_str("!");
let mut str = String::from("message"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
b > 50 & z < 16
b > 50 and z < 16
Use 'and' not '&'.
Python
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
function bar() {{ return {{key:'info'}} }}
function bar() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
if result = 88 {{}}
if result == 88 {{}}
Use ==.
Swift
if ($b = 13) {{}}
if ($b -eq 13) {{}}
Use -eq.
PowerShell
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
JOIN profiles ON users.id = profiles.status
JOIN profiles ON users.id = profiles.status
Correct.
SQL
echo 'data'
echo 'data';
Add semicolon.
PHP
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
'data' + 50
'data' + 50.to_s
Convert int.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if foo = 68:
if foo == 68:
Use == for comparison.
Python
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
if a = 74
if a == 74
Use ==.
Ruby
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
// comment
/* comment */
Use /* */.
CSS
if (val = 20) {{}}
if (val === 20) {{}}
Use === for equality.
JavaScript
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
def compute(val): return val + 1
def compute(val): return val + 1
Correct.
Python
for result in range(87) print(result)
for result in range(87): print(result)
Colon after for.
Python
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
const c = 40; c = 59;
let c = 40; c = 59;
Cannot reassign const.
JavaScript
let s = String::from("result"); let r=&s; s.push_str("!");
let mut s = String::from("result"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
def process(): print('output')
def process(): print('output')
Indent function body.
Python
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
int[] list = new int[15]; list[15] = 5;
int[] list = new int[15]; if (15 < list.length) list[15] = 5;
Check bounds.
Java
if (val = 31) {{}}
if (val == 31) {{}}
Use ==.
Kotlin
name: hello age: 45
name: hello age: 45
Correct.
YAML
object Item {{ def main(args: Array[String]) = println("result") }}
object Item {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
function foo(result) print(result) end
function foo(result) print(result) end
Correct.
Lua
if foo = 59
if foo == 59
Use ==.
MATLAB
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
items[77]
if items.indices.contains(77) {{ items[77] }}
Check index.
Swift
for (z in values)
for (z of values)
for...in iterates keys.
JavaScript
function test(val:string){{return val;}} test(38);
function test(val:string){{return val;}} test('output');
Pass correct type.
TypeScript
const a;
const a = 68;
Initialize const.
JavaScript
function handle() {{ echo 'test'; }}
function handle() {{ echo 'test'; }}
Correct.
PHP
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
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