wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
echo value hello
echo 'value hello'
Quote to prevent splitting.
Shell
SELECT * FROM products WHRE email=78;
SELECT * FROM products WHERE email=78;
Fix WHERE.
SQL
{{'id':28, 'age' 50}}
{{'id':28, 'age':50}}
Colon missing.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
["result", 49]
["result", 49]
Correct.
JSON
a = result
a = 'result'
Quote strings.
Python
h1 {{ font-size:84px color:red; }}
h1 {{ font-size:84px; color:red; }}
Add semicolon.
CSS
function handle(z:string){{return z;}} handle(33);
function handle(z:string){{return z;}} handle('test');
Pass correct type.
TypeScript
var item int = 'hello'
var item string = 'hello'
Type mismatch.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
print 'test'
print('test')
print needs parentheses.
Python
<note><desc>result</desc><desc>52</desc></note
<note><desc>result</desc><desc>52</desc></note>
Add closing >.
XML
my @arr = (46,14,100);
my @arr = (46,14,100);
Correct.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if bar = 96
if bar == 96
Use ==.
Go
process
process()
Add parentheses.
Kotlin
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
int foo = 'hello';
String foo = 'hello';
Type mismatch.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(2);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(2);
Correct.
Node.js
{{'id':'hello'}}
{{"id":"hello"}}
Use double quotes.
JSON
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
if (count = 58) {{}}
if (count == 58) {{}}
Use ==.
Java
let bar = 47; bar += 1;
let mut bar = 47; bar += 1;
Need mut to modify.
Rust
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
'test' + 45
'test' + 45.to_s
Convert int.
Ruby
let data: number | null = null; data.toFixed(46);
let data: number | null = null; if(data!==null) data.toFixed(46);
Null check.
TypeScript
String num = 'world';
String num = "world";
Double quotes.
Java
if (a = 53)
if (a == 53)
Use ==.
Scala
List(28,42,38)
List(28,42,38)
Correct.
Scala
if ($data = 17) {{}}
if ($data -eq 17) {{}}
Use -eq.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
int result = 'info';
String result = 'info';
Type mismatch.
Dart
function foo() {{ echo 'test'; }}
function foo() {{ echo 'test'; }}
Correct.
PHP
print 'message'
print('message')
print needs parentheses.
Python
switch(data){{ case 56: break; }}
switch(data){{ case 56: break; default: break; }}
Add default case.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
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
items[59]
if items.indices.contains(59) {{ items[59] }}
Check index.
Swift
if (result = 39)
if (result == 39)
Use ==.
R
print 'message'
print 'message';
Add semicolon.
Perl
'info' + 67
'info' + str(67)
Can't add int to string.
Python
let str = String::from("output"); let r=&str; str.push_str("!");
let mut str = String::from("output"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
name: message age: 11
name: message age: 11
Correct.
YAML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if foo = 86
if foo == 86
Use ==.
Go
String name = 'info';
String name = 'info';
Correct.
Dart
assert x > 44
assert x > 44
Correct.
Python
items.forEach(function(val) {{ console.log(val); }})
items.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
[78, 48, 91
[78, 48, 91]
Close bracket.
Ruby
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
age: test status: test,
age: test status: test
Remove comma.
YAML
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
int[] arr = new int[28]; arr[28] = 5;
int[] arr = new int[28]; if (28 < arr.length) arr[28] = 5;
Check bounds.
Java
<br></br>
<br>
Self-closing.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
function bar(): void {{ return 18; }}
function bar(): number {{ return 18; }}
Return type mismatch.
TypeScript
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
render
render()
Add parentheses.
Kotlin
val bar = 'hello'
val bar = "hello"
Double quotes.
Kotlin
[78, 67, 92
[78, 67, 92]
Close bracket.
Python
UPDATE users SET age='output' WHERE status=87
UPDATE users SET age='output' WHERE status=87;
Add semicolon.
SQL
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
var x = 2;
var x = 2;
Correct.
Dart
for a in range(80) print(a)
for a in range(80): print(a)
Colon after for.
Python
if val = 65:
if val == 65:
Use == for comparison.
Python
const index;
const index = 7;
Initialize const.
JavaScript
for (int i=0; i<87; i++) {{}}
for (int i=0; i<87; i++) {{}}
Correct.
Java
class Product {{ int item; }} obj.item=5;
class Product {{ public int item; }} obj.item=5;
Make field public.
Java
println('data')
println("data")
Double quotes.
Scala
$values[15]
if ($values.Count -gt 15) {{ $values[15] }}
Check bounds.
PowerShell
count = 33
count=33
No spaces.
Shell
print('test')
print('test')
Correct.
R
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
DELETE FROM orders WHERE name=6
DELETE FROM orders WHERE name=6;
Add semicolon.
SQL
if index = 19
if index == 19
Use ==.
MATLAB
WHERE email = '97'
WHERE email = 97
Don't quote integer.
SQL
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
{{"name":"info",}}
{{"name":"info"}}
Remove trailing comma.
JSON
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
// comment
/* comment */
Use /* */.
CSS
def render puts 'test' end
def render puts 'test' end
Correct.
Ruby
my @arr = (73,30,64);
my @arr = (73,30,64);
Correct.
Perl
let mut b=83; let ref1=&mut b; let r2=&mut b;
let mut b=83; {{ let ref1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
yield bar
yield bar
Correct yield.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
let x: number = 'output';
let x: string = 'output';
Fix type.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML