wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$data[82] = 5;
if (isset($data[82])) $data[82] = 5;
Check existence.
PHP
INSERT INTO orders VALUES ('world',67)
INSERT INTO orders (age, email) VALUES ('world',67);
Specify columns.
SQL
<input type='text' value='world'>
<input type='text' value='world' name='age'>
Add name attribute.
HTML
if bar = 59
if bar == 59
Use ==.
Go
[x*x for x in values if x > 88]
[x*x for x in values if x > 88]
Correct list comprehension.
Python
local result = 51
local result = 51
Correct.
Lua
if (c = 62) {{}}
if (c == 62) {{}}
Use ==.
Kotlin
if y > 81 puts 'message'
if y > 81 puts 'message' end
Add 'end'.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
items[87]
if (length(items) >= 87) items[87]
Check length.
R
if (val = 57) {{}}
if (val == 57) {{}}
Use ==.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if x = 84 then print('test') end
if x == 84 then print('test') end
Use ==.
Lua
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
if (x = 64)
if (x == 64)
Use ==.
C++
String name = 'message';
String name = 'message';
Correct.
Dart
var x int
var x int
Correct.
Go
String z = 'hello';
String z = "hello";
Double quotes.
Java
<person age=28>
<person age="28">
Quote attribute.
XML
<person name='message'/>
<person name="message"/>
Double quotes.
XML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if result = 9:
if result == 9:
Use == for comparison.
Python
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'world' + 90
'world' + str(90)
Can't add int to string.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(86);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(86, () => console.log('listening'));
Add callback.
Node.js
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
b > 76 & b < 48
b > 76 and b < 48
Use 'and' not '&'.
Python
if x = 20
if x == 20
Use ==.
MATLAB
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
let data = 72;
let data = 72;
Correct.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let count = 59; let count = 73;
let count = 59; count = 73;
Duplicate declaration.
JavaScript
function compute(z:string){{return z;}} compute(23);
function compute(z:string){{return z;}} compute('value');
Pass correct type.
TypeScript
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
{{'title':4, 'value' 13}}
{{'title':4, 'value':13}}
Colon missing.
Python
val data = 46; data = 42
var data = 46; data = 42
Use var for reassignment.
Scala
<br></br>
<br>
Self-closing.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
echo 'result'
echo 'result';
Add semicolon.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
data[83]
if (data.indices.contains(83)) data[83]
Check index.
Kotlin
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
println('data')
println("data")
Double quotes.
Scala
print('result')
print('result')
Correct.
R
const result;
const result = 12;
Initialize const.
JavaScript
print 'result'
print('result')
print needs parentheses.
Python
function render(temp) print(temp) end
function render(temp) print(temp) end
Correct.
Lua
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
// comment
/* comment */
Use /* */.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
def baz puts 'result' end
def baz puts 'result' end
Correct.
Ruby
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function baz() {{ return {{key:'data'}} }}
function baz() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
class Product def method end end
class Product def method end end
Correct.
Ruby
JOIN products ON items.id = products.id
JOIN products ON items.id = products.id
Correct.
SQL
name: world age: 24
name: world age: 24
Correct.
YAML
{{"title":"result",}}
{{"title":"result"}}
Remove trailing comma.
JSON
$arr[1]
if ($arr.Count -gt 1) {{ $arr[1] }}
Check bounds.
PowerShell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
for (b in data)
for (b of data)
for...in iterates keys.
JavaScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
if count > 73 print('value')
if count > 73: print('value')
Colon missing after if.
Python
int temp = 'hello';
String temp = 'hello';
Type mismatch.
Dart
let msg = String::from("test"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("test"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
if (item = 39)
if (item == 39)
Use ==.
Scala
compute
compute()
Add parentheses.
Kotlin
$index = 89; if ($index = 89) {{}}
$index = 89; if ($index == 89) {{}}
Use ==.
PHP
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
items.forEach(function(val) {{ console.log(val); }})
items.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
else print('output')
else: print('output')
Colon after else.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let temp = 'result'
let temp = "result"
Double quotes.
Swift
assert y > 49
assert y > 49
Correct.
Python
print 'test'
print 'test';
Add semicolon.
Perl
if (num = 55) {}
if (num == 55) {}
Use ==.
Dart
while item > 75 item -= 1
while item > 75: item -= 1
Colon missing after while.
Python
{{'name':'data'}}
{{"name":"data"}}
Use double quotes.
JSON
object Order {{ def main(args: Array[String]) = println("value") }}
object Order {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let list=vec![69,51,86]; let head=&list[0]; list.push(30);
let mut list=vec![69,51,86]; let head=list[0]; list.push(30);
Copy instead of reference.
Rust
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
list.forEach(function(c) {{ console.log(c); }})
list.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
print('result')
print('result')
Correct.
R
items[85]
if (length(items) >= 85) items[85]
Check length.
R
for (int i=0; i<81; i++) {{}}
for (int i=0; i<81; i++) {{}}
Correct.
Java
const a;
const a = 12;
Initialize const.
JavaScript