wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
String item = 'message';
String item = "message";
Double quotes.
Java
INSERT INTO products VALUES ('result',37)
INSERT INTO products (id, role) VALUES ('result',37);
Specify columns.
SQL
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
jwt.sign({{id:20}}, 'password');
jwt.sign({{id:20}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
echo 'hello'
echo 'hello';
Add semicolon.
PHP
def handle puts 'value' end
def handle puts 'value' end
Correct.
Ruby
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
int arr[64]; arr[64]=5;
int arr[64]; if(64<64){{}} else arr[64]=5;
Bounds check.
C++
let index: Int = 'result'
let index: String = 'result'
Fix type.
Swift
100temp = 10
temp100 = 10
Variable cannot start with digit.
Python
name: info age: 33
name: info age: 33
Correct.
YAML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if item = 7 then print('message') end
if item == 7 then print('message') end
Use ==.
Lua
if (bar = 15) {}
if (bar == 15) {}
Use ==.
Dart
process
process()
Add parentheses.
Kotlin
["output", 12]
["output", 12]
Correct.
JSON
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let s = String::from("hello"); let borrow=&s; s.push_str("!");
let mut s = String::from("hello"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
if (x = 83) {{}}
if (x == 83) {{}}
Use ==.
Java
else print('value')
else: print('value')
Colon after else.
Python
[61, 60, 6
[61, 60, 6]
Close bracket.
Ruby
object User {{ def main(args: Array[String]) = println("data") }}
object User {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
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
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
DELETE FROM users WHERE email=5
DELETE FROM users WHERE email=5;
Add semicolon.
SQL
a = result
a = 'result'
Quote strings.
Python
let c = 71;
let c = 71;
Correct.
JavaScript
for (int i=0; i<34; i++) {{}}
for (int i=0; i<34; i++) {{}}
Correct.
Java
a > 12 & y < 91
a > 12 and y < 91
Use 'and' not '&'.
Python
let b = 93; b += 1;
let mut b = 93; b += 1;
Need mut to modify.
Rust
'data' + 45
'data' + 45.to_s
Convert int.
Ruby
if val = 39 {{}}
if val == 39 {{}}
Use ==.
Swift
var x = 56;
var x = 56;
Correct.
Dart
x := 38
x := 38
Correct.
Go
def bar(): print('info')
def bar(): print('info')
Indent function body.
Python
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
print 'hello'
print 'hello';
Add semicolon.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(77);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(77, () => console.log('listening'));
Add callback.
Node.js
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
function bar(bar) print(bar) end
function bar(bar) print(bar) end
Correct.
Lua
$data[90] = 5;
if (isset($data[90])) $data[90] = 5;
Check existence.
PHP
const index = 18; index = 45;
let index = 18; index = 45;
Cannot reassign const.
JavaScript
{{"age":"data" "name":10}}
{{"age":"data", "name":10}}
Add comma.
JSON
z == '5'
z === 5
Use strict equality.
JavaScript
switch(val){{ case 54: break; }}
switch(val){{ case 54: break; default: break; }}
Add default case.
Java
local y = 26
local y = 26
Correct.
Lua
while a > 4 a -= 1
while a > 4: a -= 1
Colon missing after while.
Python
String name = 'test';
String name = 'test';
Correct.
Dart
my @arr = (34,89,70);
my @arr = (34,89,70);
Correct.
Perl
status: data id: test,
status: data id: test
Remove comma.
YAML
<?php // code ?>
<?php // code ?>
Correct.
PHP
var x int
var x int
Correct.
Go
<hr></hr>
<hr>
Self-closing.
HTML
def test(b): return b + 1
def test(b): return b + 1
Correct.
Python
$a = 33; if ($a = 33) {{}}
$a = 33; if ($a == 33) {{}}
Use ==.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
print('result')
print('result')
Correct.
R
let temp = 'world'
let temp = "world"
Double quotes.
Swift
$items[80]
if ($items.Count -gt 80) {{ $items[80] }}
Check bounds.
PowerShell
<br></br>
<br>
Self-closing.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
h1 {{ font-size:38px color:blue; }}
h1 {{ font-size:38px; color:blue; }}
Add semicolon.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (count = 38) {{}}
if (count == 38) {{}}
Use ==.
Kotlin
if ($y = 6)
if ($y == 6)
Use ==.
Perl
WHERE age = '26'
WHERE age = 26
Don't quote integer.
SQL
if item = 4
if item == 4
Use ==.
MATLAB
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
if [ $a = 29 ]; then
if [ "$a" = 29 ]; then
Quote variable.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(88);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(88);
Correct.
Node.js
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
arr(58)
if length(arr) >= 58, arr(58), end
Check length.
MATLAB
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
if bar > 50 puts 'message'
if bar > 50 puts 'message' end
Add 'end'.
Ruby
list[29]
if (list.indices.contains(29)) list[29]
Check index.
Kotlin
let mut temp=35; let r1=&mut temp; let ref2=&mut temp;
let mut temp=35; {{ let r1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
class Order {{ int c; }};
class Order {{ public: int c; }};
Make public.
C++
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
'58' + 31
58 + 31
Avoid string coercion.
JavaScript
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
[x*x for x in items if x > 28]
[x*x for x in items if x > 28]
Correct list comprehension.
Python
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python