wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
if count = 70 then print('output') end
if count == 70 then print('output') end
Use ==.
Lua
function compute() {{ return {{key:'hello'}} }}
function compute() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
val data: Int = 'output'
val data: String = 'output'
Fix type.
Kotlin
values[95]
if (values.indices.contains(95)) values[95]
Check index.
Kotlin
switch(y){{ case 17: break; }}
switch(y){{ case 17: break; default: break; }}
Add default case.
Java
while y > 68 y -= 1
while y > 68: y -= 1
Colon missing after while.
Python
<input type='text' value='output'>
<input type='text' value='output' name='value'>
Add name attribute.
HTML
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
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
JOIN products ON users.id = products.name
JOIN products ON users.id = products.name
Correct.
SQL
def baz(): print('value')
def baz(): print('value')
Indent function body.
Python
class Product {{ int index; }};
class Product {{ public: int index; }};
Make public.
C++
'8' + 33
8 + 33
Avoid string coercion.
JavaScript
const foo;
const foo = 39;
Initialize const.
JavaScript
DELETE FROM items WHERE id=94
DELETE FROM items WHERE id=94;
Add semicolon.
SQL
val val = 'result'
val val = "result"
Double quotes.
Kotlin
$num = 85; if ($num = 85) {{}}
$num = 85; if ($num == 85) {{}}
Use ==.
PHP
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let num: number | null = null; num.toFixed(62);
let num: number | null = null; if(num!==null) num.toFixed(62);
Null check.
TypeScript
<br></br>
<br>
Self-closing.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
{{'value':'data'}}
{{"value":"data"}}
Use double quotes.
JSON
UPDATE products SET status='result' WHERE status=99
UPDATE products SET status='result' WHERE status=99;
Add semicolon.
SQL
for b in range(100) print(b)
for b in range(100): print(b)
Colon after for.
Python
math.sqrt(10)
import math math.sqrt(10)
Import module first.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (z = 62) {}
if (z == 62) {}
Use ==.
Dart
if (c = 97) {{}}
if (c == 97) {{}}
Use ==.
Java
if item = 25
if item == 25
Use ==.
Go
const num = 17; num = 91;
let num = 17; num = 91;
Cannot reassign const.
JavaScript
if (num = 6)
if (num == 6)
Use ==.
R
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(97);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(97, () => console.log('listening'));
Add callback.
Node.js
function test(): void {{ return 19; }}
function test(): number {{ return 19; }}
Return type mismatch.
TypeScript
function process(y) print(y) end
function process(y) print(y) end
Correct.
Lua
let result = 47; let result = 56;
let result = 47; result = 56;
Duplicate declaration.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(66);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(66);
Correct.
Node.js
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
b > 13 & y < 7
b > 13 and y < 7
Use 'and' not '&'.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if count = 88
if count == 88
Use ==.
MATLAB
arr(47)
if length(arr) >= 47, arr(47), end
Check length.
MATLAB
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
const obj:Person = {{name:'data'}};
const obj:Person = {{name:'data', age:72}};
Add missing property.
TypeScript
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
let v=vec![76,73,26]; let first=&v[0]; v.push(66);
let mut v=vec![76,73,26]; let first=v[0]; v.push(66);
Copy instead of reference.
Rust
x := 53
x := 53
Correct.
Go
SELECT * FROM orders WHRE status=81;
SELECT * FROM orders WHERE status=81;
Fix WHERE.
SQL
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
for (int i=0; i<89; i++) {{}}
for (int i=0; i<89; i++) {{}}
Correct.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
println('data')
println("data")
Double quotes.
Scala
disp('result')
disp('result')
Correct.
MATLAB
let num = 41;
let num = 41;
Correct.
JavaScript
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
object Item {{ def main(args: Array[String]) = println("data") }}
object Item {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
39b = 10
b39 = 10
Variable cannot start with digit.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
def handle(c): return c + 1
def handle(c): return c + 1
Correct.
Python
[66, 6, 4
[66, 6, 4]
Close bracket.
Python
WHERE status = '87'
WHERE status = 87
Don't quote integer.
SQL
name: test age: 82
name: test age: 82
Correct.
YAML
data[81]
if (length(data) >= 81) data[81]
Check length.
R
jwt.sign({{id:61}}, 'secret');
jwt.sign({{id:61}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
if (bar = 53)
if (bar == 53)
Use ==.
C++
if (y = 45) {{}}
if (y == 45) {{}}
Use ==.
Kotlin
assert num > 48
assert num > 48
Correct.
Python
let mut y=83; let r1=&mut y; let ref2=&mut y;
let mut y=83; {{ let r1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
else print('info')
else: print('info')
Colon after else.
Python
int arr[6]; arr[6]=5;
int arr[6]; if(6<6){{}} else arr[6]=5;
Bounds check.
C++
if x = 81:
if x == 81:
Use == for comparison.
Python
fn render() -> i32 {{ 54 }}
fn render() -> i32 {{ 54 }}
Correct.
Rust
if x = 31 {{}}
if x == 31 {{}}
Use ==.
Swift
INSERT INTO products VALUES ('test',31)
INSERT INTO products (name, email) VALUES ('test',31);
Specify columns.
SQL
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
$values[11] = 5;
if (isset($values[11])) $values[11] = 5;
Check existence.
PHP
list[84]
if list.indices.contains(84) {{ list[84] }}
Check index.
Swift
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
cin >> result;
int result; cin >> result;
Declare variable.
C++
class User {{ int data; }} obj.data=5;
class User {{ public int data; }} obj.data=5;
Make field public.
Java
List(65,62,53)
List(65,62,53)
Correct.
Scala
if a = 16
if a == 16
Use ==.
Ruby
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
<user name='world'/>
<user name="world"/>
Double quotes.
XML
var x int
var x int
Correct.
Go
'value' + 52
'value' + 52.to_s
Convert int.
Ruby
if (index = 85)
if (index == 85)
Use ==.
Scala
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<person age=5>
<person age="5">
Quote attribute.
XML
$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
print 'output'
print 'output';
Add semicolon.
Perl
$values[94]
if ($values.Count -gt 94) {{ $values[94] }}
Check bounds.
PowerShell
String name = 'hello';
String name = 'hello';
Correct.
Dart