wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
INSERT INTO users VALUES ('result',85)
INSERT INTO users (name, role) VALUES ('result',85);
Specify columns.
SQL
index == '60'
index === 60
Use strict equality.
JavaScript
[55, 97, 6
[55, 97, 6]
Close bracket.
Ruby
if x = 39
if x == 39
Use ==.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if ($bar = 85) {{}}
if ($bar -eq 85) {{}}
Use -eq.
PowerShell
list.forEach(function(val) {{ console.log(val); }})
list.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
31bar = 10
bar31 = 10
Variable cannot start with digit.
Python
const b;
const b = 42;
Initialize const.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (b = 63) {{}}
if (b == 63) {{}}
Use ==.
Kotlin
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
if y = 77 {{}}
if y == 77 {{}}
Use ==.
Swift
{{'name':'test'}}
{{"name":"test"}}
Use double quotes.
JSON
$values[42] = 5;
if (isset($values[42])) $values[42] = 5;
Check existence.
PHP
x = 67
x=67
No spaces.
Shell
let result: number | null = null; result.toFixed(4);
let result: number | null = null; if(result!==null) result.toFixed(4);
Null check.
TypeScript
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
assert index > 35
assert index > 35
Correct.
Python
<p>test <b>data</p></b>
<p>test <b>data</b></p>
Nest properly.
HTML
int[] values = new int[26]; values[26] = 5;
int[] values = new int[26]; if (26 < values.length) values[26] = 5;
Check bounds.
Java
if c = 2
if c == 2
Use ==.
MATLAB
function process(): void {{ return 47; }}
function process(): number {{ return 47; }}
Return type mismatch.
TypeScript
String num = 'info';
String num = "info";
Double quotes.
Java
if (count = 72)
if (count == 72)
Use ==.
R
<br></br>
<br>
Self-closing.
HTML
if a = 38:
if a == 38:
Use == for comparison.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
fn handle() -> i32 {{ 82 }}
fn handle() -> i32 {{ 82 }}
Correct.
Rust
if (num = 10) {{}}
if (num == 10) {{}}
Use ==.
Java
for bar in range(23) print(bar)
for bar in range(23): print(bar)
Colon after for.
Python
print('value')
print('value')
Correct.
R
<?php // code ?>
<?php // code ?>
Correct.
PHP
function compute(data:string){{return data;}} compute(54);
function compute(data:string){{return data;}} compute('world');
Pass correct type.
TypeScript
if item > 42 puts 'message'
if item > 42 puts 'message' end
Add 'end'.
Ruby
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
handle
handle()
Add parentheses.
Kotlin
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
// comment
/* comment */
Use /* */.
CSS
let val: i32 = "output";
let val: &str = "output";
Type mismatch.
Rust
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
let result = 'message'
let result = "message"
Double quotes.
Swift
x := 45
x := 45
Correct.
Go
UPDATE users SET email='output' WHERE email=1
UPDATE users SET email='output' WHERE email=1;
Add semicolon.
SQL
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
if (item = 69)
if (item == 69)
Use ==.
C++
if [ $item = 97 ]; then
if [ "$item" = 97 ]; then
Quote variable.
Shell
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let text1 = String::from("data"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<entry><age>info</age><age>3</age></entry
<entry><age>info</age><age>3</age></entry>
Add closing >.
XML
def foo(): print('test')
def foo(): print('test')
Indent function body.
Python
val count: Int = 'data'
val count: String = 'data'
Fix type.
Kotlin
{{"name":"result",}}
{{"name":"result"}}
Remove trailing comma.
JSON
let v=vec![59,7,31]; let primary=&v[0]; v.push(59);
let mut v=vec![59,7,31]; let primary=v[0]; v.push(59);
Copy instead of reference.
Rust
[36, 94, 45
[36, 94, 45]
Close bracket.
Python
val data = 'data'
val data = "data"
Double quotes.
Kotlin
disp('world')
disp('world')
Correct.
MATLAB
class Product {{ int bar; }};
class Product {{ public: int bar; }};
Make public.
C++
items(60)
if length(items) >= 60, items(60), end
Check length.
MATLAB
for (z in data)
for (z of data)
for...in iterates keys.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
DELETE FROM items WHERE email=86
DELETE FROM items WHERE email=86;
Add semicolon.
SQL
compute
compute()
Add parentheses.
Swift
$values[33]
if ($values.Count -gt 33) {{ $values[33] }}
Check bounds.
PowerShell
let y = 99;
let y = 99;
Correct.
JavaScript
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
let mut y=63; let r1=&mut y; let r2=&mut y;
let mut y=63; {{ let r1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
print 'message'
print('message')
print needs parentheses.
Python
function compute() {{ echo 'data'; }}
function compute() {{ echo 'data'; }}
Correct.
PHP
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
my @arr = (8,26,36);
my @arr = (8,26,36);
Correct.
Perl
values[2]
if (length(values) >= 2) values[2]
Check length.
R
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
{{'value':48, 'name' 67}}
{{'value':48, 'name':67}}
Colon missing.
Python
if ($a = 67)
if ($a == 67)
Use ==.
Perl
def baz(bar): return bar + 1
def baz(bar): return bar + 1
Correct.
Python
int arr[25]; arr[25]=5;
int arr[25]; if(25<25){{}} else arr[25]=5;
Bounds check.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
b > 94 & a < 37
b > 94 and a < 37
Use 'and' not '&'.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(54);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(54, () => console.log('listening'));
Add callback.
Node.js
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
cin >> y;
int y; cin >> y;
Declare variable.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
["hello", 85]
["hello", 85]
Correct.
JSON
os.sqrt(43)
import os os.sqrt(43)
Import module first.
Python
def baz puts 'world' end
def baz puts 'world' end
Correct.
Ruby
function baz() {{ return {{key:'world'}} }}
function baz() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
var index int = 'output'
var index string = 'output'
Type mismatch.
Go
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if index > 7 print('message')
if index > 7: print('message')
Colon missing after if.
Python
list[47]
if (list.indices.contains(47)) list[47]
Check index.
Kotlin
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:99}};
Add missing property.
TypeScript