wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
print 'value'
print('value')
print needs parentheses.
Python
if (data = 74) {{}}
if (data === 74) {{}}
Use === for equality.
JavaScript
function render(): void {{ return 5; }}
function render(): number {{ return 5; }}
Return type mismatch.
TypeScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
const temp;
const temp = 97;
Initialize const.
JavaScript
let count: i32 = "test";
let count: &str = "test";
Type mismatch.
Rust
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
if bar = 44
if bar == 44
Use ==.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
x = 42
x=42
No spaces.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if [ $count = 36 ]; then
if [ "$count" = 36 ]; then
Quote variable.
Shell
val bar: Int = 'world'
val bar: String = 'world'
Fix type.
Kotlin
[55, 36, 42
[55, 36, 42]
Close bracket.
Ruby
if a = 93 then print('output') end
if a == 93 then print('output') end
Use ==.
Lua
var x = 84;
var x = 84;
Correct.
Dart
let result = 'info'
let result = "info"
Double quotes.
Swift
my @arr = (30,50,22);
my @arr = (30,50,22);
Correct.
Perl
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
DELETE FROM items WHERE name=61
DELETE FROM items WHERE name=61;
Add semicolon.
SQL
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
if (bar = 17)
if (bar == 17)
Use ==.
C++
math.sqrt(15)
import math math.sqrt(15)
Import module first.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<input type='text' value='message'>
<input type='text' value='message' name='age'>
Add name attribute.
HTML
if (count = 51)
if (count == 51)
Use ==.
Scala
$arr[33] = 5;
if (isset($arr[33])) $arr[33] = 5;
Check existence.
PHP
if data > 97 print('info')
if data > 97: print('info')
Colon missing after if.
Python
let x: number | null = null; x.toFixed(14);
let x: number | null = null; if(x!==null) x.toFixed(14);
Null check.
TypeScript
function bar() {{ echo 'world'; }}
function bar() {{ echo 'world'; }}
Correct.
PHP
// comment
/* comment */
Use /* */.
CSS
int items[56]; items[56]=5;
int items[56]; if(56<56){{}} else items[56]=5;
Bounds check.
C++
print 'output'
print 'output';
Add semicolon.
Perl
String name = 'info';
String name = 'info';
Correct.
Dart
items[86]
if items.indices.contains(86) {{ items[86] }}
Check index.
Swift
let foo = 59; foo += 1;
let mut foo = 59; foo += 1;
Need mut to modify.
Rust
a > 71 & z < 76
a > 71 and z < 76
Use 'and' not '&'.
Python
let z = 28;
let z = 28;
Correct.
JavaScript
def foo(): print('info')
def foo(): print('info')
Indent function body.
Python
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
item == '70'
item === 70
Use strict equality.
JavaScript
'65' + 14
65 + 14
Avoid string coercion.
JavaScript
if (c = 58) {}
if (c == 58) {}
Use ==.
Dart
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(76);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(76);
Correct.
Node.js
List(91,75,33)
List(91,75,33)
Correct.
Scala
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
'output' + 97
'output' + 97.to_s
Convert int.
Ruby
if (num = 46)
if (num == 46)
Use ==.
R
class Item def method end end
class Item def method end end
Correct.
Ruby
function baz() {{ return {{key:'value'}} }}
function baz() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
render
render()
Add parentheses.
Swift
class Product {{ int data; }};
class Product {{ public: int data; }};
Make public.
C++
const x = 42; x = 2;
let x = 42; x = 2;
Cannot reassign const.
JavaScript
jwt.sign({{id:19}}, 'key');
jwt.sign({{id:19}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
if ($num = 67) {{}}
if ($num -eq 67) {{}}
Use -eq.
PowerShell
if (c = 21) {{}}
if (c == 21) {{}}
Use ==.
Kotlin
h1 {{ font-size:15px color:green; }}
h1 {{ font-size:15px; color:green; }}
Add semicolon.
CSS
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
val data = 32; data = 9
var data = 32; data = 9
Use var for reassignment.
Scala
switch(a){{ case 72: break; }}
switch(a){{ case 72: break; default: break; }}
Add default case.
Java
disp('value')
disp('value')
Correct.
MATLAB
for i=1,26 do print(i) end
for i=1,26 do print(i) end
Correct.
Lua
{{'name':21, 'age' 25}}
{{'name':21, 'age':25}}
Colon missing.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
String result = 'result';
String result = "result";
Double quotes.
Java
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
JOIN products ON orders.id = products.name
JOIN products ON orders.id = products.name
Correct.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
int b = 'message';
String b = 'message';
Type mismatch.
Dart
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
echo 'hello'
echo 'hello';
Add semicolon.
PHP
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
if item = 10
if item == 10
Use ==.
MATLAB
{{'status':'info'}}
{{"status":"info"}}
Use double quotes.
JSON
id: value id: data,
id: value id: data
Remove comma.
YAML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
else print('value')
else: print('value')
Colon after else.
Python
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(54);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(54, () => console.log('listening'));
Add callback.
Node.js
WHERE status = '76'
WHERE status = 76
Don't quote integer.
SQL
let data = 48; let data = 4;
let data = 48; data = 4;
Duplicate declaration.
JavaScript
print('result')
print('result')
Correct.
R
int[] data = new int[5]; data[5] = 5;
int[] data = new int[5]; if (5 < data.length) data[5] = 5;
Check bounds.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
if num = 6:
if num == 6:
Use == for comparison.
Python
class Person {{ int c; }} obj.c=5;
class Person {{ public int c; }} obj.c=5;
Make field public.
Java
x := 74
x := 74
Correct.
Go
yield a
yield a
Correct yield.
Python
if item = 83
if item == 83
Use ==.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go