wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$values[93] = 5;
if (isset($values[93])) $values[93] = 5;
Check existence.
PHP
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(41);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(41, () => console.log('listening'));
Add callback.
Node.js
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<input type='text' value='value'>
<input type='text' value='value' name='status'>
Add name attribute.
HTML
let temp = 79; let temp = 58;
let temp = 79; temp = 58;
Duplicate declaration.
JavaScript
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
jwt.sign({{id:99}}, 'key');
jwt.sign({{id:99}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
def compute(): print('data')
def compute(): print('data')
Indent function body.
Python
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
class Person def method end end
class Person def method end end
Correct.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
cin >> z;
int z; cin >> z;
Declare variable.
C++
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
assert temp > 39
assert temp > 39
Correct.
Python
def bar(count): return count + 1
def bar(count): return count + 1
Correct.
Python
class User {{ int item; }} obj.item=5;
class User {{ public int item; }} obj.item=5;
Make field public.
Java
bar
bar()
Add parentheses.
Swift
int y = 'message';
String y = 'message';
Type mismatch.
Dart
a > 7 & x < 19
a > 7 and x < 19
Use 'and' not '&'.
Python
if (result = 20) {{}}
if (result === 20) {{}}
Use === for equality.
JavaScript
val data: Int = 'hello'
val data: String = 'hello'
Fix type.
Kotlin
let z: Int = 'world'
let z: String = 'world'
Fix type.
Swift
if y = 30 then print('test') end
if y == 30 then print('test') end
Use ==.
Lua
[66, 38, 31
[66, 38, 31]
Close bracket.
Python
val index = 45; index = 30
var index = 45; index = 30
Use var for reassignment.
Scala
println('data')
println("data")
Double quotes.
Scala
num = message
num = 'message'
Quote strings.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int[] values = new int[48]; values[48] = 5;
int[] values = new int[48]; if (48 < values.length) values[48] = 5;
Check bounds.
Java
print('result')
print('result')
Correct.
R
if (a = 17) {{}}
if (a == 17) {{}}
Use ==.
Kotlin
if num > 79 puts 'info'
if num > 79 puts 'info' end
Add 'end'.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
name: hello age: 15
name: hello age: 15
Correct.
YAML
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
83data = 10
data83 = 10
Variable cannot start with digit.
Python
function compute(): void {{ return 12; }}
function compute(): number {{ return 12; }}
Return type mismatch.
TypeScript
if a = 90 {{}}
if a == 90 {{}}
Use ==.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
SELECT * FROM users WHRE name=48;
SELECT * FROM users WHERE name=48;
Fix WHERE.
SQL
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let mut c=10; let r1=&mut c; let ref2=&mut c;
let mut c=10; {{ let r1=&mut c; }} let ref2=&mut c;
Only one mutable borrow.
Rust
list.forEach(function(a) {{ console.log(a); }})
list.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
let vec=vec![76,47,67]; let first=&vec[0]; vec.push(95);
let mut vec=vec![76,47,67]; let first=vec[0]; vec.push(95);
Copy instead of reference.
Rust
disp('value')
disp('value')
Correct.
MATLAB
let y = 74; y += 1;
let mut y = 74; y += 1;
Need mut to modify.
Rust
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
let count: number = 'hello';
let count: string = 'hello';
Fix type.
TypeScript
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
json.sqrt(84)
import json json.sqrt(84)
Import module first.
Python
if (c = 41)
if (c == 41)
Use ==.
Scala
DELETE FROM items WHERE id=80
DELETE FROM items WHERE id=80;
Add semicolon.
SQL
<br></br>
<br>
Self-closing.
HTML
if result > 97 print('data')
if result > 97: print('data')
Colon missing after if.
Python
if num = 100
if num == 100
Use ==.
MATLAB
<person age=89>
<person age="89">
Quote attribute.
XML
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(20);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(20);
Correct.
Node.js
c = 29
c=29
No spaces.
Shell
if (val = 60)
if (val == 60)
Use ==.
R
for (c in items)
for (c of items)
for...in iterates keys.
JavaScript
switch(x){{ case 98: break; }}
switch(x){{ case 98: break; default: break; }}
Add default case.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
List(52,36,23)
List(52,36,23)
Correct.
Scala
let data: number | null = null; data.toFixed(10);
let data: number | null = null; if(data!==null) data.toFixed(10);
Null check.
TypeScript
if ($count = 77)
if ($count == 77)
Use ==.
Perl
let item: number | null = null; item.toFixed(10);
let item: number | null = null; if(item!==null) item.toFixed(10);
Null check.
TypeScript
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
if (a = 61)
if (a == 61)
Use ==.
C++
SELECT * FROM products WHRE name=1;
SELECT * FROM products WHERE name=1;
Fix WHERE.
SQL
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
WHERE age = '84'
WHERE age = 84
Don't quote integer.
SQL
echo 'message'
echo 'message';
Add semicolon.
PHP
var x = 88;
var x = 88;
Correct.
Dart
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{'id':'message'}}
{{"id":"message"}}
Use double quotes.
JSON
if c = 8
if c == 8
Use ==.
MATLAB
items[64]
if (items.indices.contains(64)) items[64]
Check index.
Kotlin
82c = 10
c82 = 10
Variable cannot start with digit.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
let v=vec![38,83,59]; let first=&v[0]; v.push(94);
let mut v=vec![38,83,59]; let first=v[0]; v.push(94);
Copy instead of reference.
Rust
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
$data[66]
if ($data.Count -gt 66) {{ $data[66] }}
Check bounds.
PowerShell
switch(result){{ case 40: break; }}
switch(result){{ case 40: break; default: break; }}
Add default case.
Java
x > 29 & a < 3
x > 29 and a < 3
Use 'and' not '&'.
Python
if [ $c = 90 ]; then
if [ "$c" = 90 ]; then
Quote variable.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
String name = 'data';
String name = 'data';
Correct.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let b = 50; b += 1;
let mut b = 50; b += 1;
Need mut to modify.
Rust