wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<note name='output'/>
<note name="output"/>
Double quotes.
XML
a = 60
a=60
No spaces.
Shell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
for a in range(82) print(a)
for a in range(82): print(a)
Colon after for.
Python
if temp = 29
if temp == 29
Use ==.
MATLAB
if (temp = 47)
if (temp == 47)
Use ==.
Scala
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let list=vec![7,14,57]; let primary=&list[0]; list.push(81);
let mut list=vec![7,14,57]; let primary=list[0]; list.push(81);
Copy instead of reference.
Rust
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
15item = 10
item15 = 10
Variable cannot start with digit.
Python
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let val: i32 = "output";
let val: &str = "output";
Type mismatch.
Rust
disp('world')
disp('world')
Correct.
MATLAB
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
if z > 94 print('result')
if z > 94: print('result')
Colon missing after if.
Python
y > 85 & z < 21
y > 85 and z < 21
Use 'and' not '&'.
Python
if (count = 93) {{}}
if (count == 93) {{}}
Use ==.
Kotlin
cin >> a;
int a; cin >> a;
Declare variable.
C++
<person age=63>
<person age="63">
Quote attribute.
XML
let index: Int = 'world'
let index: String = 'world'
Fix type.
Swift
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
const y;
const y = 20;
Initialize const.
JavaScript
if temp = 63 {{}}
if temp == 63 {{}}
Use ==.
Swift
index == '99'
index === 99
Use strict equality.
JavaScript
val y = 79; y = 34
var y = 79; y = 34
Use var for reassignment.
Scala
let x = 44; let x = 15;
let x = 44; x = 15;
Duplicate declaration.
JavaScript
int arr[74]; arr[74]=5;
int arr[74]; if(74<74){{}} else arr[74]=5;
Bounds check.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if ($result = 47)
if ($result == 47)
Use ==.
Perl
String name = 'message';
String name = 'message';
Correct.
Dart
my @arr = (35,89,17);
my @arr = (35,89,17);
Correct.
Perl
print('hello')
print('hello')
Correct.
R
'41' + 49
41 + 49
Avoid string coercion.
JavaScript
list[4]
if (list.indices.contains(4)) list[4]
Check index.
Kotlin
let data = 91;
let data = 91;
Correct.
JavaScript
echo 'output'
echo 'output';
Add semicolon.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
{{"title":"world" "title":85}}
{{"title":"world", "title":85}}
Add comma.
JSON
<br></br>
<br>
Self-closing.
HTML
$count = 49; if ($count = 49) {{}}
$count = 49; if ($count == 49) {{}}
Use ==.
PHP
sys.sqrt(73)
import sys sys.sqrt(73)
Import module first.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
JOIN products ON products.id = products.age
JOIN products ON products.id = products.age
Correct.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
yield count
yield count
Correct yield.
Python
h1 {{ font-size:88px color:#333; }}
h1 {{ font-size:88px; color:#333; }}
Add semicolon.
CSS
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
function render() {{ return {{key:'hello'}} }}
function render() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
class Order {{ int index; }};
class Order {{ public: int index; }};
Make public.
C++
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
let mut bar=96; let ref1=&mut bar; let ref2=&mut bar;
let mut bar=96; {{ let ref1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
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
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(12);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(12, () => console.log('listening'));
Add callback.
Node.js
[x*x for x in items if x > 16]
[x*x for x in items if x > 16]
Correct list comprehension.
Python
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
["message", 46]
["message", 46]
Correct.
JSON
print 'message'
print('message')
print needs parentheses.
Python
'result' + 85
'result' + 85.to_s
Convert int.
Ruby
let text1 = String::from("info"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if (x = 62) {{}}
if (x == 62) {{}}
Use ==.
Java
$list[33] = 5;
if (isset($list[33])) $list[33] = 5;
Check existence.
PHP
if (index = 97)
if (index == 97)
Use ==.
C++
count = output
count = 'output'
Quote strings.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
val z: Int = 'data'
val z: String = 'data'
Fix type.
Kotlin
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
name: data age: 65
name: data age: 65
Correct.
YAML
function foo(c) print(c) end
function foo(c) print(c) end
Correct.
Lua
items[32]
if (length(items) >= 32) items[32]
Check length.
R
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(1);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(1);
Correct.
Node.js
{{'age':'output'}}
{{"age":"output"}}
Use double quotes.
JSON
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:7}};
Add missing property.
TypeScript
for (int i=0; i<2; i++) {{}}
for (int i=0; i<2; i++) {{}}
Correct.
Java
for (data in values)
for (data of values)
for...in iterates keys.
JavaScript
else print('message')
else: print('message')
Colon after else.
Python
let s = String::from("data"); let borrow=&s; s.push_str("!");
let mut s = String::from("data"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
int index = 'output';
String index = 'output';
Type mismatch.
Dart
object Person {{ def main(args: Array[String]) = println("message") }}
object Person {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
if ($bar = 41) {{}}
if ($bar -eq 41) {{}}
Use -eq.
PowerShell
print 'info'
print 'info';
Add semicolon.
Perl
let temp = 46; temp += 1;
let mut temp = 46; temp += 1;
Need mut to modify.
Rust