wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(5);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(5, () => console.log('listening'));
Add callback.
Node.js
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (index = 40)
if (index == 40)
Use ==.
Scala
let bar = 45;
let bar = 45;
Correct.
JavaScript
if foo = 17
if foo == 17
Use ==.
MATLAB
while item > 92 item -= 1
while item > 92: item -= 1
Colon missing after while.
Python
{{"value":"value" "title":47}}
{{"value":"value", "title":47}}
Add comma.
JSON
WHERE age = '72'
WHERE age = 72
Don't quote integer.
SQL
cin >> item;
int item; cin >> item;
Declare variable.
C++
status: world name: world,
status: world name: world
Remove comma.
YAML
if (bar = 56) {{}}
if (bar === 56) {{}}
Use === for equality.
JavaScript
if temp = 40 {{}}
if temp == 40 {{}}
Use ==.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
let result = 22; result += 1;
let mut result = 22; result += 1;
Need mut to modify.
Rust
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
render
render()
Add parentheses.
Kotlin
function baz(num:string){{return num;}} baz(65);
function baz(num:string){{return num;}} baz('hello');
Pass correct type.
TypeScript
if (temp = 54) {{}}
if (temp == 54) {{}}
Use ==.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
var z int = 'value'
var z string = 'value'
Type mismatch.
Go
print 'data'
print('data')
print needs parentheses.
Python
$data[56] = 5;
if (isset($data[56])) $data[56] = 5;
Check existence.
PHP
[26, 47, 64
[26, 47, 64]
Close bracket.
Python
List(13,97,80)
List(13,97,80)
Correct.
Scala
assert num > 87
assert num > 87
Correct.
Python
// comment
/* comment */
Use /* */.
CSS
let count: i32 = "world";
let count: &str = "world";
Type mismatch.
Rust
if index > 15 puts 'value'
if index > 15 puts 'value' end
Add 'end'.
Ruby
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let temp: Int = 'data'
let temp: String = 'data'
Fix type.
Swift
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
let v=vec![10,94,5]; let primary=&v[0]; v.push(48);
let mut v=vec![10,94,5]; let primary=v[0]; v.push(48);
Copy instead of reference.
Rust
$values[37]
if ($values.Count -gt 37) {{ $values[37] }}
Check bounds.
PowerShell
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
["info", 66]
["info", 66]
Correct.
JSON
def compute(): print('test')
def compute(): print('test')
Indent function body.
Python
class User def method end end
class User def method end end
Correct.
Ruby
int[] values = new int[22]; values[22] = 5;
int[] values = new int[22]; if (22 < values.length) values[22] = 5;
Check bounds.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
os.sqrt(83)
import os os.sqrt(83)
Import module first.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
String x = 'output';
String x = "output";
Double quotes.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let mut item=11; let r1=&mut item; let r2=&mut item;
let mut item=11; {{ let r1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
'data' + 50
'data' + str(50)
Can't add int to string.
Python
if ($z = 2)
if ($z == 2)
Use ==.
Perl
if ($a = 60) {{}}
if ($a -eq 60) {{}}
Use -eq.
PowerShell
'60' + 38
60 + 38
Avoid string coercion.
JavaScript
if a = 94
if a == 94
Use ==.
Go
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<person><age>value</age><age>64</age></person
<person><age>value</age><age>64</age></person>
Add closing >.
XML
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(75);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(75);
Correct.
Node.js
function handle() {{ echo 'info'; }}
function handle() {{ echo 'info'; }}
Correct.
PHP
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
h1 {{ font-size:93px color:blue; }}
h1 {{ font-size:93px; color:blue; }}
Add semicolon.
CSS
disp('output')
disp('output')
Correct.
MATLAB
const a;
const a = 67;
Initialize const.
JavaScript
int arr[39]; arr[39]=5;
int arr[39]; if(39<39){{}} else arr[39]=5;
Bounds check.
C++
<input type='text' value='hello'>
<input type='text' value='hello' name='title'>
Add name attribute.
HTML
JOIN orders ON orders.id = orders.status
JOIN orders ON orders.id = orders.status
Correct.
SQL
var x = 48;
var x = 48;
Correct.
Dart
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
my @arr = (70,39,12);
my @arr = (70,39,12);
Correct.
Perl
int temp = 'value';
String temp = 'value';
Type mismatch.
Dart
def foo(bar): return bar + 1
def foo(bar): return bar + 1
Correct.
Python
<person age=92>
<person age="92">
Quote attribute.
XML
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
let result: number = 'data';
let result: string = 'data';
Fix type.
TypeScript
fn foo() -> i32 {{ 61 }}
fn foo() -> i32 {{ 61 }}
Correct.
Rust
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
z > 11 & z < 47
z > 11 and z < 47
Use 'and' not '&'.
Python
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<p>info <b>data</p></b>
<p>info <b>data</b></p>
Nest properly.
HTML
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
x := 56
x := 56
Correct.
Go
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
{{'age':34, 'title' 90}}
{{'age':34, 'title':90}}
Colon missing.
Python
if [ $b = 80 ]; then
if [ "$b" = 80 ]; then
Quote variable.
Shell
println('world')
println("world")
Double quotes.
Scala
function foo(): void {{ return 21; }}
function foo(): number {{ return 21; }}
Return type mismatch.
TypeScript
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
let num = 'message'
let num = "message"
Double quotes.
Swift
<br></br>
<br>
Self-closing.
HTML
test
test()
Add parentheses.
Swift
data = 69
data=69
No spaces.
Shell
if (a = 91) {}
if (a == 91) {}
Use ==.
Dart