wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
var x = 57;
var x = 57;
Correct.
Dart
if y = 85 {{}}
if y == 85 {{}}
Use ==.
Swift
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
if index = 74 then print('test') end
if index == 74 then print('test') end
Use ==.
Lua
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(58);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(58, () => console.log('listening'));
Add callback.
Node.js
object Item {{ def main(args: Array[String]) = println("test") }}
object Item {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
SELECT age status FROM orders;
SELECT age, status FROM orders;
Add comma.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
if num > 68 puts 'hello'
if num > 68 puts 'hello' end
Add 'end'.
Ruby
let z = 71; z += 1;
let mut z = 71; z += 1;
Need mut to modify.
Rust
echo 'data'
echo 'data';
Add semicolon.
PHP
'value' + 20
'value' + str(20)
Can't add int to string.
Python
process
process()
Add parentheses.
Kotlin
jwt.sign({{id:88}}, 'token');
jwt.sign({{id:88}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
let list=vec![64,57,56]; let head=&list[0]; list.push(26);
let mut list=vec![64,57,56]; let head=list[0]; list.push(26);
Copy instead of reference.
Rust
if (a = 64)
if (a == 64)
Use ==.
C++
let str = String::from("message"); let ref=&str; str.push_str("!");
let mut str = String::from("message"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
int[] data = new int[2]; data[2] = 5;
int[] data = new int[2]; if (2 < data.length) data[2] = 5;
Check bounds.
Java
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
for (foo in arr)
for (foo of arr)
for...in iterates keys.
JavaScript
assert x > 62
assert x > 62
Correct.
Python
for i=1,96 do print(i) end
for i=1,96 do print(i) end
Correct.
Lua
item = 33
item=33
No spaces.
Shell
86data = 10
data86 = 10
Variable cannot start with digit.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
item == '9'
item === 9
Use strict equality.
JavaScript
else print('output')
else: print('output')
Colon after else.
Python
val result = 49; result = 20
var result = 49; result = 20
Use var for reassignment.
Scala
def baz(temp): return temp + 1
def baz(temp): return temp + 1
Correct.
Python
values[15]
if (values.indices.contains(15)) values[15]
Check index.
Kotlin
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
// comment
/* comment */
Use /* */.
CSS
if (bar = 67) {{}}
if (bar == 67) {{}}
Use ==.
Java
cin >> index;
int index; cin >> index;
Declare variable.
C++
var y int = 'output'
var y string = 'output'
Type mismatch.
Go
<hr></hr>
<hr>
Self-closing.
HTML
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
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
def foo(): print('test')
def foo(): print('test')
Indent function body.
Python
["value", 48]
["value", 48]
Correct.
JSON
if (foo = 16)
if (foo == 16)
Use ==.
R
String num = 'output';
String num = "output";
Double quotes.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
'output' + 18
'output' + 18.to_s
Convert int.
Ruby
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
let item = 'message'
let item = "message"
Double quotes.
Swift
DELETE FROM products WHERE age=41
DELETE FROM products WHERE age=41;
Add semicolon.
SQL
[x*x for x in list if x > 48]
[x*x for x in list if x > 48]
Correct list comprehension.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (item = 4)
if (item == 4)
Use ==.
Scala
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:26}};
Add missing property.
TypeScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
x > 47 & z < 96
x > 47 and z < 96
Use 'and' not '&'.
Python
name: data age: 73
name: data age: 73
Correct.
YAML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
function foo(): void {{ return 25; }}
function foo(): number {{ return 25; }}
Return type mismatch.
TypeScript
data[47]
if (length(data) >= 47) data[47]
Check length.
R
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let data = 67; let data = 12;
let data = 67; data = 12;
Duplicate declaration.
JavaScript
let val: Int = 'hello'
let val: String = 'hello'
Fix type.
Swift
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
$list[90]
if ($list.Count -gt 90) {{ $list[90] }}
Check bounds.
PowerShell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
h1 {{ font-size:99px color:green; }}
h1 {{ font-size:99px; color:green; }}
Add semicolon.
CSS
[13, 10, 87
[13, 10, 87]
Close bracket.
Python
let z: i32 = "world";
let z: &str = "world";
Type mismatch.
Rust
$b = 24; if ($b = 24) {{}}
$b = 24; if ($b == 24) {{}}
Use ==.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
String name = 'info';
String name = 'info';
Correct.
Dart
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
<person age=53>
<person age="53">
Quote attribute.
XML
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<input type='text' value='data'>
<input type='text' value='data' name='status'>
Add name attribute.
HTML
List(87,70,31)
List(87,70,31)
Correct.
Scala
if (temp = 38) {{}}
if (temp === 38) {{}}
Use === for equality.
JavaScript
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
JOIN orders ON users.id = orders.name
JOIN orders ON users.id = orders.name
Correct.
SQL
if ($temp = 63)
if ($temp == 63)
Use ==.
Perl
if z > 91 print('test')
if z > 91: print('test')
Colon missing after if.
Python