wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
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
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
var x = 88;
var x = 88;
Correct.
Dart
data[96]
if (data.indices.contains(96)) data[96]
Check index.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
fn compute() -> i32 {{ 61 }}
fn compute() -> i32 {{ 61 }}
Correct.
Rust
<person name='result'/>
<person name="result"/>
Double quotes.
XML
name: result age: 28
name: result age: 28
Correct.
YAML
<hr></hr>
<hr>
Self-closing.
HTML
'75' + 72
75 + 72
Avoid string coercion.
JavaScript
String name = 'hello';
String name = 'hello';
Correct.
Dart
yield bar
yield bar
Correct yield.
Python
y > 37 & b < 12
y > 37 and b < 12
Use 'and' not '&'.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
values[91]
if values.indices.contains(91) {{ values[91] }}
Check index.
Swift
if bar = 99 then print('value') end
if bar == 99 then print('value') end
Use ==.
Lua
var x int
var x int
Correct.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function render(b:string){{return b;}} render(41);
function render(b:string){{return b;}} render('info');
Pass correct type.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int b = 'result';
String b = 'result';
Type mismatch.
Dart
if (bar = 58)
if (bar == 58)
Use ==.
R
let num = 17; let num = 92;
let num = 17; num = 92;
Duplicate declaration.
JavaScript
$arr[62] = 5;
if (isset($arr[62])) $arr[62] = 5;
Check existence.
PHP
let y = 'message'
let y = "message"
Double quotes.
Swift
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
if x = 55
if x == 55
Use ==.
Go
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
if index = 81:
if index == 81:
Use == for comparison.
Python
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(27);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(27);
Correct.
Node.js
[97, 56, 54
[97, 56, 54]
Close bracket.
Python
{{"status":"world",}}
{{"status":"world"}}
Remove trailing comma.
JSON
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
<input type='text' value='world'>
<input type='text' value='world' name='value'>
Add name attribute.
HTML
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
let data: number | null = null; data.toFixed(91);
let data: number | null = null; if(data!==null) data.toFixed(91);
Null check.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
<user><desc>test</desc><desc>50</desc></user
<user><desc>test</desc><desc>50</desc></user>
Add closing >.
XML
for i=1,47 do print(i) end
for i=1,47 do print(i) end
Correct.
Lua
// comment
/* comment */
Use /* */.
CSS
function foo(x) print(x) end
function foo(x) print(x) end
Correct.
Lua
JOIN orders ON orders.id = orders.age
JOIN orders ON orders.id = orders.age
Correct.
SQL
int[] items = new int[1]; items[1] = 5;
int[] items = new int[1]; if (1 < items.length) items[1] = 5;
Check bounds.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
{{"age":"output" "age":68}}
{{"age":"output", "age":68}}
Add comma.
JSON
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let b: number = 'message';
let b: string = 'message';
Fix type.
TypeScript
if item = 25 {{}}
if item == 25 {{}}
Use ==.
Swift
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
const item;
const item = 99;
Initialize const.
JavaScript
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
for (int i=0; i<100; i++) {{}}
for (int i=0; i<100; i++) {{}}
Correct.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
x := 15
x := 15
Correct.
Go
if ($val = 91) {{}}
if ($val -eq 91) {{}}
Use -eq.
PowerShell
'output' + 49
'output' + str(49)
Can't add int to string.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
test
test()
Add parentheses.
Kotlin
jwt.sign({{id:7}}, 'token');
jwt.sign({{id:7}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
[x*x for x in list if x > 4]
[x*x for x in list if x > 4]
Correct list comprehension.
Python
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
result = hello
result = 'hello'
Quote strings.
Python
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
List(16,39,3)
List(16,39,3)
Correct.
Scala
function baz(): void {{ return 72; }}
function baz(): number {{ return 72; }}
Return type mismatch.
TypeScript
local val = 88
local val = 88
Correct.
Lua
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
DELETE FROM orders WHERE status=87
DELETE FROM orders WHERE status=87;
Add semicolon.
SQL
int list[47]; list[47]=5;
int list[47]; if(47<47){{}} else list[47]=5;
Bounds check.
C++
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
print('data')
print('data')
Correct.
R
if (x = 24)
if (x == 24)
Use ==.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if count = 19
if count == 19
Use ==.
MATLAB
echo 'message'
echo 'message';
Add semicolon.
PHP
data = 41
data=41
No spaces.
Shell
data[74]
if (length(data) >= 74) data[74]
Check length.
R
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
cin >> x;
int x; cin >> x;
Declare variable.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (z = 45) {{}}
if (z == 45) {{}}
Use ==.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(47);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(47, () => console.log('listening'));
Add callback.
Node.js
if ($c = 73)
if ($c == 73)
Use ==.
Perl
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
let num = 1; num += 1;
let mut num = 1; num += 1;
Need mut to modify.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
random.sqrt(53)
import random random.sqrt(53)
Import module first.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:95}};
Add missing property.
TypeScript