wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
function compute() {{ return {{key:'result'}} }}
function compute() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
h1 {{ font-size:20px color:#333; }}
h1 {{ font-size:20px; color:#333; }}
Add semicolon.
CSS
if (z = 68)
if (z == 68)
Use ==.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
$list[10] = 5;
if (isset($list[10])) $list[10] = 5;
Check existence.
PHP
if (item = 76) {{}}
if (item == 76) {{}}
Use ==.
Kotlin
const temp = 11; temp = 8;
let temp = 11; temp = 8;
Cannot reassign const.
JavaScript
UPDATE products SET email='world' WHERE email=4
UPDATE products SET email='world' WHERE email=4;
Add semicolon.
SQL
{{'name':18, 'name' 59}}
{{'name':18, 'name':59}}
Colon missing.
Python
println('data')
println("data")
Double quotes.
Scala
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
let str = String::from("data"); let ref=&str; str.push_str("!");
let mut str = String::from("data"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
if (index = 66) {{}}
if (index === 66) {{}}
Use === for equality.
JavaScript
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
var num int = 'data'
var num string = 'data'
Type mismatch.
Go
if b > 20 puts 'message'
if b > 20 puts 'message' end
Add 'end'.
Ruby
const data = 90; data = 40;
let data = 90; data = 40;
Cannot reassign const.
JavaScript
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
let mut b=59; let ref1=&mut b; let r2=&mut b;
let mut b=59; {{ let ref1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
if (val = 99)
if (val == 99)
Use ==.
Scala
let num = 6; let num = 20;
let num = 6; num = 20;
Duplicate declaration.
JavaScript
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
List(55,46,48)
List(55,46,48)
Correct.
Scala
for count in range(84) print(count)
for count in range(84): print(count)
Colon after for.
Python
val a = 45; a = 56
var a = 45; a = 56
Use var for reassignment.
Scala
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
<person age=41>
<person age="41">
Quote attribute.
XML
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(7);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(7);
Correct.
Node.js
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
if [ $item = 63 ]; then
if [ "$item" = 63 ]; then
Quote variable.
Shell
if (data = 83) {{}}
if (data == 83) {{}}
Use ==.
Java
79bar = 10
bar79 = 10
Variable cannot start with digit.
Python
x := 30
x := 30
Correct.
Go
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
id: message value: hello,
id: message value: hello
Remove comma.
YAML
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
arr(67)
if length(arr) >= 67, arr(67), end
Check length.
MATLAB
int[] arr = new int[46]; arr[46] = 5;
int[] arr = new int[46]; if (46 < arr.length) arr[46] = 5;
Check bounds.
Java
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
<br></br>
<br>
Self-closing.
HTML
if b = 84
if b == 84
Use ==.
Ruby
def render(): print('hello')
def render(): print('hello')
Indent function body.
Python
class Order {{ int val; }};
class Order {{ public: int val; }};
Make public.
C++
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
item = 34
item=34
No spaces.
Shell
bar
bar()
Add parentheses.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
cin >> num;
int num; cin >> num;
Declare variable.
C++
if y = 57:
if y == 57:
Use == for comparison.
Python
$c = 32; if ($c = 32) {{}}
$c = 32; if ($c == 32) {{}}
Use ==.
PHP
name: info age: 23
name: info age: 23
Correct.
YAML
<?php // code ?>
<?php // code ?>
Correct.
PHP
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
data[84]
if (length(data) >= 84) data[84]
Check length.
R
items[86]
if (items.indices.contains(86)) items[86]
Check index.
Kotlin
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
<entry><age>message</age><desc>23</desc></entry
<entry><age>message</age><desc>23</desc></entry>
Add closing >.
XML
val foo = 'output'
val foo = "output"
Double quotes.
Kotlin
$values[70]
if ($values.Count -gt 70) {{ $values[70] }}
Check bounds.
PowerShell
list.forEach(function(a) {{ console.log(a); }})
list.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
def test(bar): return bar + 1
def test(bar): return bar + 1
Correct.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let s1 = String::from("world"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
{{"id":"result" "status":33}}
{{"id":"result", "status":33}}
Add comma.
JSON
z > 85 & a < 66
z > 85 and a < 66
Use 'and' not '&'.
Python
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let z: number | null = null; z.toFixed(75);
let z: number | null = null; if(z!==null) z.toFixed(75);
Null check.
TypeScript
[x*x for x in values if x > 58]
[x*x for x in values if x > 58]
Correct list comprehension.
Python
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
function render(data:string){{return data;}} render(36);
function render(data:string){{return data;}} render('output');
Pass correct type.
TypeScript
if (data = 61) {{}}
if (data == 61) {{}}
Use ==.
Kotlin
print('world')
print('world')
Correct.
R
UPDATE orders SET age='hello' WHERE email=11
UPDATE orders SET age='hello' WHERE email=11;
Add semicolon.
SQL
int arr[32]; arr[32]=5;
int arr[32]; if(32<32){{}} else arr[32]=5;
Bounds check.
C++
assert temp > 81
assert temp > 81
Correct.
Python
{{"name":"output",}}
{{"name":"output"}}
Remove trailing comma.
JSON
var x = 30;
var x = 30;
Correct.
Dart
fn baz() -> i32 {{ 61 }}
fn baz() -> i32 {{ 61 }}
Correct.
Rust
if (val = 63)
if (val == 63)
Use ==.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
for (z in values)
for (z of values)
for...in iterates keys.
JavaScript
DELETE FROM products WHERE name=82
DELETE FROM products WHERE name=82;
Add semicolon.
SQL
class Person {{ int bar; }} obj.bar=5;
class Person {{ public int bar; }} obj.bar=5;
Make field public.
Java
String name = 'data';
String name = 'data';
Correct.
Dart
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
my @arr = (9,57,7);
my @arr = (9,57,7);
Correct.
Perl
function baz(bar) print(bar) end
function baz(bar) print(bar) end
Correct.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML