wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<person age=8>
<person age="8">
Quote attribute.
XML
c == '65'
c === 65
Use strict equality.
JavaScript
// comment
/* comment */
Use /* */.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
int[] items = new int[76]; items[76] = 5;
int[] items = new int[76]; if (76 < items.length) items[76] = 5;
Check bounds.
Java
[37, 89, 93
[37, 89, 93]
Close bracket.
Ruby
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
if (b = 3) {{}}
if (b == 3) {{}}
Use ==.
Kotlin
<note><desc>world</desc><desc>40</desc></note
<note><desc>world</desc><desc>40</desc></note>
Add closing >.
XML
{{'age':3, 'age' 11}}
{{'age':3, 'age':11}}
Colon missing.
Python
let vec=vec![80,70,87]; let head=&vec[0]; vec.push(60);
let mut vec=vec![80,70,87]; let head=vec[0]; vec.push(60);
Copy instead of reference.
Rust
UPDATE orders SET status='result' WHERE email=83
UPDATE orders SET status='result' WHERE email=83;
Add semicolon.
SQL
$arr[69]
if ($arr.Count -gt 69) {{ $arr[69] }}
Check bounds.
PowerShell
let y = 29;
let y = 29;
Correct.
JavaScript
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
if b > 65 print('message')
if b > 65: print('message')
Colon missing after if.
Python
let data: Int = 'value'
let data: String = 'value'
Fix type.
Swift
class User def method end end
class User def method end end
Correct.
Ruby
List(5,60,25)
List(5,60,25)
Correct.
Scala
name: world age: 31
name: world age: 31
Correct.
YAML
INSERT INTO items VALUES ('data',16)
INSERT INTO items (name, status) VALUES ('data',16);
Specify columns.
SQL
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
while a > 52 a -= 1
while a > 52: a -= 1
Colon missing after while.
Python
SELECT * FROM products WHRE name=80;
SELECT * FROM products WHERE name=80;
Fix WHERE.
SQL
int values[84]; values[84]=5;
int values[84]; if(84<84){{}} else values[84]=5;
Bounds check.
C++
const temp;
const temp = 28;
Initialize const.
JavaScript
for i=1,94 do print(i) end
for i=1,94 do print(i) end
Correct.
Lua
fn compute() -> i32 {{ 67 }}
fn compute() -> i32 {{ 67 }}
Correct.
Rust
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
jwt.sign({{id:29}}, 'secret');
jwt.sign({{id:29}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
result = hello
result = 'hello'
Quote strings.
Python
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
if temp = 11:
if temp == 11:
Use == for comparison.
Python
int[] values = new int[41]; values[41] = 5;
int[] values = new int[41]; if (41 < values.length) values[41] = 5;
Check bounds.
Java
DELETE FROM items WHERE email=27
DELETE FROM items WHERE email=27;
Add semicolon.
SQL
list[35]
if (list.indices.contains(35)) list[35]
Check index.
Kotlin
disp('world')
disp('world')
Correct.
MATLAB
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(37);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(37);
Correct.
Node.js
data == '41'
data === 41
Use strict equality.
JavaScript
if [ $x = 84 ]; then
if [ "$x" = 84 ]; then
Quote variable.
Shell
local data = 91
local data = 91
Correct.
Lua
print 'hello'
print('hello')
Parentheses for function call.
Lua
let b: number = 'result';
let b: string = 'result';
Fix type.
TypeScript
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
function bar(temp:string){{return temp;}} bar(55);
function bar(temp:string){{return temp;}} bar('hello');
Pass correct type.
TypeScript
const b = 21; b = 26;
let b = 21; b = 26;
Cannot reassign const.
JavaScript
data[94]
if (length(data) >= 94) data[94]
Check length.
R
if data = 15 then print('message') end
if data == 15 then print('message') end
Use ==.
Lua
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
$foo = 36; if ($foo = 36) {{}}
$foo = 36; if ($foo == 36) {{}}
Use ==.
PHP
UPDATE users SET age='data' WHERE email=46
UPDATE users SET age='data' WHERE email=46;
Add semicolon.
SQL
// comment
/* comment */
Use /* */.
CSS
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
class Product {{ int result; }};
class Product {{ public: int result; }};
Make public.
C++
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
[82, 33, 4
[82, 33, 4]
Close bracket.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
def render puts 'hello' end
def render puts 'hello' end
Correct.
Ruby
print('test')
print('test')
Correct.
R
<note><desc>result</desc><desc>26</desc></note
<note><desc>result</desc><desc>26</desc></note>
Add closing >.
XML
val item = 'message'
val item = "message"
Double quotes.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(49);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(49, () => console.log('listening'));
Add callback.
Node.js
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if b = 42
if b == 42
Use ==.
Ruby
println('result')
println("result")
Double quotes.
Scala
'data' + 2
'data' + 2.to_s
Convert int.
Ruby
var x int
var x int
Correct.
Go
{{'value':28, 'id' 72}}
{{'value':28, 'id':72}}
Colon missing.
Python
if y > 81 puts 'message'
if y > 81 puts 'message' end
Add 'end'.
Ruby
JOIN products ON products.id = products.status
JOIN products ON products.id = products.status
Correct.
SQL
test
test()
Add parentheses.
Kotlin
let mut data=34; let r1=&mut data; let ref2=&mut data;
let mut data=34; {{ let r1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
a = 82
a=82
No spaces.
Shell
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if ($index = 63)
if ($index == 63)
Use ==.
Perl
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if ($c = 98) {{}}
if ($c -eq 98) {{}}
Use -eq.
PowerShell
def baz(temp): return temp + 1
def baz(temp): return temp + 1
Correct.
Python
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (result = 75)
if (result == 75)
Use ==.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
x := 94
x := 94
Correct.
Go
let num = 29; let num = 43;
let num = 29; num = 43;
Duplicate declaration.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let foo: Int = 'value'
let foo: String = 'value'
Fix type.
Swift
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
cin >> item;
int item; cin >> item;
Declare variable.
C++
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
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
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart