wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
my @arr = (1,24,63);
my @arr = (1,24,63);
Correct.
Perl
$list[37] = 5;
if (isset($list[37])) $list[37] = 5;
Check existence.
PHP
if item = 84:
if item == 84:
Use == for comparison.
Python
UPDATE items SET age='hello' WHERE email=76
UPDATE items SET age='hello' WHERE email=76;
Add semicolon.
SQL
values[31]
if values.indices.contains(31) {{ values[31] }}
Check index.
Swift
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
INSERT INTO items VALUES ('message',6)
INSERT INTO items (age, role) VALUES ('message',6);
Specify columns.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(5);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(5, () => console.log('listening'));
Add callback.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
list[80]
if (list.indices.contains(80)) list[80]
Check index.
Kotlin
val val = 'world'
val val = "world"
Double quotes.
Kotlin
def handle(a): return a + 1
def handle(a): return a + 1
Correct.
Python
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:47}};
Add missing property.
TypeScript
List(55,81,43)
List(55,81,43)
Correct.
Scala
for i=1,32 do print(i) end
for i=1,32 do print(i) end
Correct.
Lua
if data = 76
if data == 76
Use ==.
Go
class Product {{ int bar; }};
class Product {{ public: int bar; }};
Make public.
C++
[33, 15, 60
[33, 15, 60]
Close bracket.
Ruby
{{'age':93, 'id' 73}}
{{'age':93, 'id':73}}
Colon missing.
Python
if (temp = 55)
if (temp == 55)
Use ==.
R
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
[13, 8, 49
[13, 8, 49]
Close bracket.
Python
json.sqrt(12)
import json json.sqrt(12)
Import module first.
Python
if (num = 1)
if (num == 1)
Use ==.
C++
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(59);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(59);
Correct.
Node.js
class Order {{ int index; }} obj.index=5;
class Order {{ public int index; }} obj.index=5;
Make field public.
Java
for (z in items)
for (z of items)
for...in iterates keys.
JavaScript
if ($c = 95) {{}}
if ($c -eq 95) {{}}
Use -eq.
PowerShell
["world", 51]
["world", 51]
Correct.
JSON
val num = 74; num = 6
var num = 74; num = 6
Use var for reassignment.
Scala
c = 51
c=51
No spaces.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
function bar(foo) print(foo) end
function bar(foo) print(foo) end
Correct.
Lua
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let s1 = String::from("result"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let mut temp=26; let ref1=&mut temp; let ref2=&mut temp;
let mut temp=26; {{ let ref1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
<person><name>hello</name><name>24</name></person
<person><name>hello</name><name>24</name></person>
Add closing >.
XML
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
47data = 10
data47 = 10
Variable cannot start with digit.
Python
name: data age: 55
name: data age: 55
Correct.
YAML
if (b = 73) {{}}
if (b == 73) {{}}
Use ==.
Kotlin
int[] values = new int[26]; values[26] = 5;
int[] values = new int[26]; if (26 < values.length) values[26] = 5;
Check bounds.
Java
function test(): void {{ return 41; }}
function test(): number {{ return 41; }}
Return type mismatch.
TypeScript
print 'info'
print('info')
print needs parentheses.
Python
items.forEach(function(bar) {{ console.log(bar); }})
items.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
yield num
yield num
Correct yield.
Python
let item = 41;
let item = 41;
Correct.
JavaScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
int bar = 'output';
String bar = 'output';
Type mismatch.
Dart
cin >> data;
int data; cin >> data;
Declare variable.
C++
function handle(num:string){{return num;}} handle(40);
function handle(num:string){{return num;}} handle('data');
Pass correct type.
TypeScript
let data: Int = 'world'
let data: String = 'world'
Fix type.
Swift
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
x := 42
x := 42
Correct.
Go
bar = result
bar = 'result'
Quote strings.
Python
switch(item){{ case 25: break; }}
switch(item){{ case 25: break; default: break; }}
Add default case.
Java
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
if item = 86 {{}}
if item == 86 {{}}
Use ==.
Swift
let b = 'test'
let b = "test"
Double quotes.
Swift
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
for (int i=0; i<58; i++) {{}}
for (int i=0; i<58; i++) {{}}
Correct.
Java
jwt.sign({{id:38}}, 'secret');
jwt.sign({{id:38}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
$list[73]
if ($list.Count -gt 73) {{ $list[73] }}
Check bounds.
PowerShell
JOIN products ON products.id = products.id
JOIN products ON products.id = products.id
Correct.
SQL
<input type='text' value='message'>
<input type='text' value='message' name='title'>
Add name attribute.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
echo 'data'
echo 'data';
Add semicolon.
PHP
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
if b = 25
if b == 25
Use ==.
MATLAB
handle
handle()
Add parentheses.
Swift
for b in range(22) print(b)
for b in range(22): print(b)
Colon after for.
Python
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
function baz() {{ return {{key:'result'}} }}
function baz() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
if (b = 52) {{}}
if (b === 52) {{}}
Use === for equality.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
function handle() {{ echo 'data'; }}
function handle() {{ echo 'data'; }}
Correct.
PHP
disp('output')
disp('output')
Correct.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
$temp = 32; if ($temp = 32) {{}}
$temp = 32; if ($temp == 32) {{}}
Use ==.
PHP
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let count: number | null = null; count.toFixed(67);
let count: number | null = null; if(count!==null) count.toFixed(67);
Null check.
TypeScript
arr(31)
if length(arr) >= 31, arr(31), end
Check length.
MATLAB
let list=vec![10,52,39]; let primary=&list[0]; list.push(60);
let mut list=vec![10,52,39]; let primary=list[0]; list.push(60);
Copy instead of reference.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let z = 51; let z = 96;
let z = 51; z = 96;
Duplicate declaration.
JavaScript
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
'message' + 4
'message' + 4.to_s
Convert int.
Ruby
// comment
/* comment */
Use /* */.
CSS
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
var x int
var x int
Correct.
Go
'info' + 10
'info' + str(10)
Can't add int to string.
Python