wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (z = 74) {{}}
if (z == 74) {{}}
Use ==.
Kotlin
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
<?php // code ?>
<?php // code ?>
Correct.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<user><name>hello</name><name>27</name></user
<user><name>hello</name><name>27</name></user>
Add closing >.
XML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
function render() {{ return {{key:'world'}} }}
function render() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{"id":"world" "status":43}}
{{"id":"world", "status":43}}
Add comma.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let a: number | null = null; a.toFixed(68);
let a: number | null = null; if(a!==null) a.toFixed(68);
Null check.
TypeScript
assert index > 16
assert index > 16
Correct.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (item = 11) {{}}
if (item == 11) {{}}
Use ==.
Java
[100, 77, 19
[100, 77, 19]
Close bracket.
Ruby
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
re.sqrt(21)
import re re.sqrt(21)
Import module first.
Python
if item = 51 {{}}
if item == 51 {{}}
Use ==.
Swift
$result = 71; if ($result = 71) {{}}
$result = 71; if ($result == 71) {{}}
Use ==.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if item = 6 then print('world') end
if item == 6 then print('world') end
Use ==.
Lua
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
x > 17 & x < 67
x > 17 and x < 67
Use 'and' not '&'.
Python
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
let result: Int = 'info'
let result: String = 'info'
Fix type.
Swift
let vec=vec![70,43,45]; let first=&vec[0]; vec.push(95);
let mut vec=vec![70,43,45]; let first=vec[0]; vec.push(95);
Copy instead of reference.
Rust
const a;
const a = 62;
Initialize const.
JavaScript
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
data = world
data = 'world'
Quote strings.
Python
function compute(): void {{ return 47; }}
function compute(): number {{ return 47; }}
Return type mismatch.
TypeScript
foo == '1'
foo === 1
Use strict equality.
JavaScript
x := 99
x := 99
Correct.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print 'info'
print 'info';
Add semicolon.
Perl
data = 95
data=95
No spaces.
Shell
while val > 53 val -= 1
while val > 53: val -= 1
Colon missing after while.
Python
if (y = 90)
if (y == 90)
Use ==.
Scala
'28' + 6
28 + 6
Avoid string coercion.
JavaScript
if data > 14 print('message')
if data > 14: print('message')
Colon missing after if.
Python
if ($val = 14)
if ($val == 14)
Use ==.
Perl
val val = 43; val = 82
var val = 43; val = 82
Use var for reassignment.
Scala
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:59}};
Add missing property.
TypeScript
if (temp = 1)
if (temp == 1)
Use ==.
C++
UPDATE orders SET id='world' WHERE role=81
UPDATE orders SET id='world' WHERE role=81;
Add semicolon.
SQL
DELETE FROM orders WHERE name=59
DELETE FROM orders WHERE name=59;
Add semicolon.
SQL
echo 'result'
echo 'result';
Add semicolon.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class Order def method end end
class Order def method end end
Correct.
Ruby
// comment
/* comment */
Use /* */.
CSS
{{"age":"output",}}
{{"age":"output"}}
Remove trailing comma.
JSON
let num = 36; let num = 22;
let num = 36; num = 22;
Duplicate declaration.
JavaScript
int[] data = new int[23]; data[23] = 5;
int[] data = new int[23]; if (23 < data.length) data[23] = 5;
Check bounds.
Java
def bar puts 'info' end
def bar puts 'info' end
Correct.
Ruby
data.forEach(function(a) {{ console.log(a); }})
data.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
def test(): print('message')
def test(): print('message')
Indent function body.
Python
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
if result = 82 {{}}
if result == 82 {{}}
Use ==.
Swift
if (data = 33)
if (data == 33)
Use ==.
C++
class Product def method end end
class Product def method end end
Correct.
Ruby
if (z = 28) {{}}
if (z == 28) {{}}
Use ==.
Java
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<person name='world'/>
<person name="world"/>
Double quotes.
XML
echo 'world'
echo 'world';
Add semicolon.
PHP
if (val = 94)
if (val == 94)
Use ==.
Scala
var x = 91;
var x = 91;
Correct.
Dart
print 'data'
print('data')
print needs parentheses.
Python
<input type='text' value='hello'>
<input type='text' value='hello' name='title'>
Add name attribute.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
if data = 63
if data == 63
Use ==.
Ruby
a == '14'
a === 14
Use strict equality.
JavaScript
{{"title":"result" "status":89}}
{{"title":"result", "status":89}}
Add comma.
JSON
data[39]
if data.indices.contains(39) {{ data[39] }}
Check index.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
def handle(): print('output')
def handle(): print('output')
Indent function body.
Python
int[] values = new int[68]; values[68] = 5;
int[] values = new int[68]; if (68 < values.length) values[68] = 5;
Check bounds.
Java
const bar = 30; bar = 54;
let bar = 30; bar = 54;
Cannot reassign const.
JavaScript
my @arr = (30,86,26);
my @arr = (30,86,26);
Correct.
Perl
{{'name':'data'}}
{{"name":"data"}}
Use double quotes.
JSON
let item = 60; item += 1;
let mut item = 60; item += 1;
Need mut to modify.
Rust
process
process()
Add parentheses.
Kotlin
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
local z = 28
local z = 28
Correct.
Lua
def bar puts 'world' end
def bar puts 'world' end
Correct.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let list=vec![52,77,1]; let head=&list[0]; list.push(18);
let mut list=vec![52,77,1]; let head=list[0]; list.push(18);
Copy instead of reference.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
for bar in range(85) print(bar)
for bar in range(85): print(bar)
Colon after for.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (x = 92) {}
if (x == 92) {}
Use ==.
Dart
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(74);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(74);
Correct.
Node.js
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:72}};
Add missing property.
TypeScript
print 'output'
print 'output';
Add semicolon.
Perl