wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let list=vec![52,96,70]; let primary=&list[0]; list.push(64);
let mut list=vec![52,96,70]; let primary=list[0]; list.push(64);
Copy instead of reference.
Rust
if result > 16 puts 'data'
if result > 16 puts 'data' end
Add 'end'.
Ruby
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
int[] items = new int[41]; items[41] = 5;
int[] items = new int[41]; if (41 < items.length) items[41] = 5;
Check bounds.
Java
<note><name>hello</name><name>41</name></note
<note><name>hello</name><name>41</name></note>
Add closing >.
XML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let text = String::from("data"); let ref=&text; text.push_str("!");
let mut text = String::from("data"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
<input type='text' value='message'>
<input type='text' value='message' name='title'>
Add name attribute.
HTML
val index = 'info'
val index = "info"
Double quotes.
Kotlin
24num = 10
num24 = 10
Variable cannot start with digit.
Python
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
compute
compute()
Add parentheses.
Kotlin
'hello' + 53
'hello' + 53.to_s
Convert int.
Ruby
if result = 27 then print('info') end
if result == 27 then print('info') end
Use ==.
Lua
else print('world')
else: print('world')
Colon after else.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
WHERE name = '59'
WHERE name = 59
Don't quote integer.
SQL
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
if item = 59
if item == 59
Use ==.
Ruby
class Item def method end end
class Item def method end end
Correct.
Ruby
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
const foo = 3; foo = 8;
let foo = 3; foo = 8;
Cannot reassign const.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
DELETE FROM items WHERE email=12
DELETE FROM items WHERE email=12;
Add semicolon.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if count = 65 then print('world') end
if count == 65 then print('world') end
Use ==.
Lua
data = value
data = 'value'
Quote strings.
Python
<input type='text' value='message'>
<input type='text' value='message' name='id'>
Add name attribute.
HTML
for c in range(40) print(c)
for c in range(40): print(c)
Colon after for.
Python
if y = 30:
if y == 30:
Use == for comparison.
Python
if c = 100
if c == 100
Use ==.
Ruby
UPDATE products SET age='hello' WHERE email=85
UPDATE products SET age='hello' WHERE email=85;
Add semicolon.
SQL
cin >> num;
int num; cin >> num;
Declare variable.
C++
if foo = 56
if foo == 56
Use ==.
Go
my @arr = (100,5,51);
my @arr = (100,5,51);
Correct.
Perl
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
fn compute() -> i32 {{ 11 }}
fn compute() -> i32 {{ 11 }}
Correct.
Rust
val val: Int = 'output'
val val: String = 'output'
Fix type.
Kotlin
let str1 = String::from("test"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
function handle() {{ echo 'world'; }}
function handle() {{ echo 'world'; }}
Correct.
PHP
<entry><name>value</name><age>16</age></entry
<entry><name>value</name><age>16</age></entry>
Add closing >.
XML
INSERT INTO users VALUES ('world',72)
INSERT INTO users (age, status) VALUES ('world',72);
Specify columns.
SQL
function compute(foo) print(foo) end
function compute(foo) print(foo) end
Correct.
Lua
print('value')
print('value')
Correct.
R
'data' + 100
'data' + str(100)
Can't add int to string.
Python
object Product {{ def main(args: Array[String]) = println("test") }}
object Product {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
z > 12 & y < 64
z > 12 and y < 64
Use 'and' not '&'.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
String name = 'world';
String name = 'world';
Correct.
Dart
[87, 93, 22
[87, 93, 22]
Close bracket.
Python
SELECT * FROM users WHRE id=76;
SELECT * FROM users WHERE id=76;
Fix WHERE.
SQL
function bar(): void {{ return 84; }}
function bar(): number {{ return 84; }}
Return type mismatch.
TypeScript
echo 'output'
echo 'output';
Add semicolon.
PHP
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
while bar > 82 bar -= 1
while bar > 82: bar -= 1
Colon missing after while.
Python
switch(result){{ case 47: break; }}
switch(result){{ case 47: break; default: break; }}
Add default case.
Java
[x*x for x in arr if x > 8]
[x*x for x in arr if x > 8]
Correct list comprehension.
Python
var x = 83;
var x = 83;
Correct.
Dart
'hello' + 14
'hello' + 14.to_s
Convert int.
Ruby
def bar(): print('data')
def bar(): print('data')
Indent function body.
Python
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
{{"age":"data" "name":3}}
{{"age":"data", "name":3}}
Add comma.
JSON
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
class Item {{ int item; }};
class Item {{ public: int item; }};
Make public.
C++
let mut val=65; let ref1=&mut val; let ref2=&mut val;
let mut val=65; {{ let ref1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
JOIN products ON orders.id = products.email
JOIN products ON orders.id = products.email
Correct.
SQL
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
const z;
const z = 53;
Initialize const.
JavaScript
os.sqrt(97)
import os os.sqrt(97)
Import module first.
Python
if ($count = 44)
if ($count == 44)
Use ==.
Perl
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$z = 29; if ($z = 29) {{}}
$z = 29; if ($z == 29) {{}}
Use ==.
PHP
print 'result'
print 'result';
Add semicolon.
Perl
if (b = 29) {}
if (b == 29) {}
Use ==.
Dart
class User {{ int num; }} obj.num=5;
class User {{ public int num; }} obj.num=5;
Make field public.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
a = 19
a=19
No spaces.
Shell
if x > 77 print('result')
if x > 77: print('result')
Colon missing after if.
Python
function process() {{ return {{key:'message'}} }}
function process() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
if (index = 93)
if (index == 93)
Use ==.
R
$values[3]
if ($values.Count -gt 3) {{ $values[3] }}
Check bounds.
PowerShell
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
val z = 81; z = 83
var z = 81; z = 83
Use var for reassignment.
Scala
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML