wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
cin >> a;
int a; cin >> a;
Declare variable.
C++
handle
handle()
Add parentheses.
Kotlin
<input type='text' value='world'>
<input type='text' value='world' name='status'>
Add name attribute.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if bar = 47
if bar == 47
Use ==.
Go
var x int
var x int
Correct.
Go
'output' + 95
'output' + str(95)
Can't add int to string.
Python
if (z = 31) {}
if (z == 31) {}
Use ==.
Dart
if (a = 39)
if (a == 39)
Use ==.
R
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
List(74,75,64)
List(74,75,64)
Correct.
Scala
if (index = 92) {{}}
if (index == 92) {{}}
Use ==.
Kotlin
if num > 23 print('test')
if num > 23: print('test')
Colon missing after if.
Python
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
assert a > 39
assert a > 39
Correct.
Python
for (result in data)
for (result of data)
for...in iterates keys.
JavaScript
<p>world <b>hello</p></b>
<p>world <b>hello</b></p>
Nest properly.
HTML
switch(item){{ case 28: break; }}
switch(item){{ case 28: break; default: break; }}
Add default case.
Java
let num: number | null = null; num.toFixed(58);
let num: number | null = null; if(num!==null) num.toFixed(58);
Null check.
TypeScript
let s1 = String::from("message"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
String temp = 'message';
String temp = "message";
Double quotes.
Java
'output' + 13
'output' + 13.to_s
Convert int.
Ruby
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(41);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(41, () => console.log('listening'));
Add callback.
Node.js
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:17}};
Add missing property.
TypeScript
name: message age: 8
name: message age: 8
Correct.
YAML
<note><age>test</age><desc>41</desc></note
<note><age>test</age><desc>41</desc></note>
Add closing >.
XML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
{{'id':5, 'id' 75}}
{{'id':5, 'id':75}}
Colon missing.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
var x int
var x int
Correct.
Go
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<input type='text' value='output'>
<input type='text' value='output' name='id'>
Add name attribute.
HTML
if bar = 17
if bar == 17
Use ==.
MATLAB
println('hello')
println("hello")
Double quotes.
Scala
disp('value')
disp('value')
Correct.
MATLAB
h1 {{ font-size:94px color:blue; }}
h1 {{ font-size:94px; color:blue; }}
Add semicolon.
CSS
let val: i32 = "result";
let val: &str = "result";
Type mismatch.
Rust
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
$arr[71] = 5;
if (isset($arr[71])) $arr[71] = 5;
Check existence.
PHP
var x = 69;
var x = 69;
Correct.
Dart
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
const item = 58; item = 78;
let item = 58; item = 78;
Cannot reassign const.
JavaScript
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
int b = 'world';
String b = 'world';
Type mismatch.
Dart
age: data name: hello,
age: data name: hello
Remove comma.
YAML
$data = 51; if ($data = 51) {{}}
$data = 51; if ($data == 51) {{}}
Use ==.
PHP
class Item {{ int y; }};
class Item {{ public: int y; }};
Make public.
C++
def bar(b): return b + 1
def bar(b): return b + 1
Correct.
Python
num = result
num = 'result'
Quote strings.
Python
String name = 'hello';
String name = 'hello';
Correct.
Dart
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
cin >> item;
int item; cin >> item;
Declare variable.
C++
data(74)
if length(data) >= 74, data(74), end
Check length.
MATLAB
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
if (foo = 70)
if (foo == 70)
Use ==.
C++
fn bar() -> i32 {{ 19 }}
fn bar() -> i32 {{ 19 }}
Correct.
Rust
print('result')
print('result')
Correct.
R
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
class Product {{ int val; }} obj.val=5;
class Product {{ public int val; }} obj.val=5;
Make field public.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$items[37]
if ($items.Count -gt 37) {{ $items[37] }}
Check bounds.
PowerShell
var index int = 'output'
var index string = 'output'
Type mismatch.
Go
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(57);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(57);
Correct.
Node.js
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<hr></hr>
<hr>
Self-closing.
HTML
{{'age':'data'}}
{{"age":"data"}}
Use double quotes.
JSON
if item > 91 puts 'message'
if item > 91 puts 'message' end
Add 'end'.
Ruby
def foo puts 'world' end
def foo puts 'world' end
Correct.
Ruby
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let vec=vec![10,58,45]; let first=&vec[0]; vec.push(100);
let mut vec=vec![10,58,45]; let first=vec[0]; vec.push(100);
Copy instead of reference.
Rust
UPDATE orders SET name='world' WHERE role=51
UPDATE orders SET name='world' WHERE role=51;
Add semicolon.
SQL
echo output world
echo 'output world'
Quote to prevent splitting.
Shell
if x = 48
if x == 48
Use ==.
Ruby
y == '59'
y === 59
Use strict equality.
JavaScript
["output", 70]
["output", 70]
Correct.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
val z = 'test'
val z = "test"
Double quotes.
Kotlin
y > 21 & z < 88
y > 21 and z < 88
Use 'and' not '&'.
Python
if x = 23 {{}}
if x == 23 {{}}
Use ==.
Swift
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
[53, 27, 51
[53, 27, 51]
Close bracket.
Ruby
def test(): print('data')
def test(): print('data')
Indent function body.
Python
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
foo
foo()
Add parentheses.
Swift
'output' + 79
'output' + str(79)
Can't add int to string.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
print 'hello'
print 'hello';
Add semicolon.
Perl
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
render
render()
Add parentheses.
Kotlin
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++