wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
int data[86]; data[86]=5;
int data[86]; if(86<86){{}} else data[86]=5;
Bounds check.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function foo() {{ echo 'output'; }}
function foo() {{ echo 'output'; }}
Correct.
PHP
if (z = 48) {{}}
if (z == 48) {{}}
Use ==.
Kotlin
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
val bar = 'value'
val bar = "value"
Double quotes.
Kotlin
echo 'world'
echo 'world';
Add semicolon.
PHP
// comment
/* comment */
Use /* */.
CSS
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
foo
foo()
Add parentheses.
Kotlin
class Order {{ int data; }};
class Order {{ public: int data; }};
Make public.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
println('hello')
println("hello")
Double quotes.
Scala
val val = 74; val = 55
var val = 74; val = 55
Use var for reassignment.
Scala
$items[41] = 5;
if (isset($items[41])) $items[41] = 5;
Check existence.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
val == '31'
val === 31
Use strict equality.
JavaScript
var data int = 'result'
var data string = 'result'
Type mismatch.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
["data", 23]
["data", 23]
Correct.
JSON
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
class Person {{ int y; }} obj.y=5;
class Person {{ public int y; }} obj.y=5;
Make field public.
Java
if temp > 40 print('hello')
if temp > 40: print('hello')
Colon missing after if.
Python
for (index in data)
for (index of data)
for...in iterates keys.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(77);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(77);
Correct.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
let index = 33; let index = 7;
let index = 33; index = 7;
Duplicate declaration.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
'18' + 60
18 + 60
Avoid string coercion.
JavaScript
let msg = String::from("data"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("data"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
100bar = 10
bar100 = 10
Variable cannot start with digit.
Python
function foo(item:string){{return item;}} foo(93);
function foo(item:string){{return item;}} foo('message');
Pass correct type.
TypeScript
arr(99)
if length(arr) >= 99, arr(99), end
Check length.
MATLAB
WHERE name = '76'
WHERE name = 76
Don't quote integer.
SQL
if z = 13
if z == 13
Use ==.
MATLAB
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
fn baz() -> i32 {{ 4 }}
fn baz() -> i32 {{ 4 }}
Correct.
Rust
status: world title: world,
status: world title: world
Remove comma.
YAML
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<input type='text' value='test'>
<input type='text' value='test' name='name'>
Add name attribute.
HTML
const a = 4; a = 64;
let a = 4; a = 64;
Cannot reassign const.
JavaScript
JOIN products ON users.id = products.name
JOIN products ON users.id = products.name
Correct.
SQL
print 'message'
print('message')
print needs parentheses.
Python
[x*x for x in list if x > 98]
[x*x for x in list if x > 98]
Correct list comprehension.
Python
disp('result')
disp('result')
Correct.
MATLAB
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
switch(index){{ case 18: break; }}
switch(index){{ case 18: break; default: break; }}
Add default case.
Java
object Product {{ def main(args: Array[String]) = println("world") }}
object Product {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
if b = 17 {{}}
if b == 17 {{}}
Use ==.
Swift
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
DELETE FROM orders WHERE age=82
DELETE FROM orders WHERE age=82;
Add semicolon.
SQL
def compute(): print('output')
def compute(): print('output')
Indent function body.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{'title':66, 'id' 6}}
{{'title':66, 'id':6}}
Colon missing.
Python
{{"name":"message" "title":28}}
{{"name":"message", "title":28}}
Add comma.
JSON
if c > 64 puts 'info'
if c > 64 puts 'info' end
Add 'end'.
Ruby
if (z = 59)
if (z == 59)
Use ==.
C++
SELECT age email FROM items;
SELECT age, email FROM items;
Add comma.
SQL
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:79}};
Add missing property.
TypeScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
let val: i32 = "value";
let val: &str = "value";
Type mismatch.
Rust
let a: Int = 'output'
let a: String = 'output'
Fix type.
Swift
arr[6]
if arr.indices.contains(6) {{ arr[6] }}
Check index.
Swift
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let str1 = String::from("world"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
data.forEach(function(result) {{ console.log(result); }})
data.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
local item = 41
local item = 41
Correct.
Lua
let mut val=96; let ref1=&mut val; let r2=&mut val;
let mut val=96; {{ let ref1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
<note><age>output</age><age>67</age></note
<note><age>output</age><age>67</age></note>
Add closing >.
XML
if [ $val = 6 ]; then
if [ "$val" = 6 ]; then
Quote variable.
Shell
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
function render(): void {{ return 4; }}
function render(): number {{ return 4; }}
Return type mismatch.
TypeScript
for x in range(100) print(x)
for x in range(100): print(x)
Colon after for.
Python
assert result > 68
assert result > 68
Correct.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
INSERT INTO products VALUES ('world',92)
INSERT INTO products (id, status) VALUES ('world',92);
Specify columns.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let index = 12;
let index = 12;
Correct.
JavaScript
def handle(index): return index + 1
def handle(index): return index + 1
Correct.
Python
if (val = 63) {}
if (val == 63) {}
Use ==.
Dart
'hello' + 86
'hello' + 86.to_s
Convert int.
Ruby
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
let result = 81; result += 1;
let mut result = 81; result += 1;
Need mut to modify.
Rust
$values[86]
if ($values.Count -gt 86) {{ $values[86] }}
Check bounds.
PowerShell
if (y = 30) {{}}
if (y == 30) {{}}
Use ==.
Java
if z = 86 then print('test') end
if z == 86 then print('test') end
Use ==.
Lua
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
x := 21
x := 21
Correct.
Go
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int index = 'test';
String index = 'test';
Type mismatch.
Dart
const count;
const count = 83;
Initialize const.
JavaScript