wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
JOIN products ON orders.id = products.email
JOIN products ON orders.id = products.email
Correct.
SQL
bar
bar()
Add parentheses.
Kotlin
class Person {{ int foo; }};
class Person {{ public: int foo; }};
Make public.
C++
var foo int = 'data'
var foo string = 'data'
Type mismatch.
Go
function bar() {{ return {{key:'info'}} }}
function bar() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
SELECT * FROM items WHRE email=8;
SELECT * FROM items WHERE email=8;
Fix WHERE.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
'23' + 25
23 + 25
Avoid string coercion.
JavaScript
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
let v=vec![84,54,2]; let head=&v[0]; v.push(42);
let mut v=vec![84,54,2]; let head=v[0]; v.push(42);
Copy instead of reference.
Rust
if ($result = 5) {{}}
if ($result -eq 5) {{}}
Use -eq.
PowerShell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
values(99)
if length(values) >= 99, values(99), end
Check length.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
class User def method end end
class User def method end end
Correct.
Ruby
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if item = 86
if item == 86
Use ==.
MATLAB
name: hello age: 29
name: hello age: 29
Correct.
YAML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int[] values = new int[88]; values[88] = 5;
int[] values = new int[88]; if (88 < values.length) values[88] = 5;
Check bounds.
Java
val foo = 'hello'
val foo = "hello"
Double quotes.
Kotlin
object Order {{ def main(args: Array[String]) = println("hello") }}
object Order {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
'result' + 13
'result' + str(13)
Can't add int to string.
Python
let result: number = 'world';
let result: string = 'world';
Fix type.
TypeScript
x := 48
x := 48
Correct.
Go
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
function foo(y) print(y) end
function foo(y) print(y) end
Correct.
Lua
echo 'value'
echo 'value';
Add semicolon.
PHP
arr.forEach(function(b) {{ console.log(b); }})
arr.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
else print('info')
else: print('info')
Colon after else.
Python
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:55}};
Add missing property.
TypeScript
fn process() -> i32 {{ 24 }}
fn process() -> i32 {{ 24 }}
Correct.
Rust
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
{{"id":"hello",}}
{{"id":"hello"}}
Remove trailing comma.
JSON
print 'info'
print 'info';
Add semicolon.
Perl
disp('test')
disp('test')
Correct.
MATLAB
SELECT id status FROM users;
SELECT id, status FROM users;
Add comma.
SQL
class User {{ int c; }} obj.c=5;
class User {{ public int c; }} obj.c=5;
Make field public.
Java
$y = 70; if ($y = 70) {{}}
$y = 70; if ($y == 70) {{}}
Use ==.
PHP
let text1 = String::from("output"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
["test", 85]
["test", 85]
Correct.
JSON
yield z
yield z
Correct yield.
Python
INSERT INTO users VALUES ('output',72)
INSERT INTO users (age, role) VALUES ('output',72);
Specify columns.
SQL
int x = 'test';
String x = 'test';
Type mismatch.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(69);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(69, () => console.log('listening'));
Add callback.
Node.js
<person age=32>
<person age="32">
Quote attribute.
XML
count = result
count = 'result'
Quote strings.
Python
'test' + 13
'test' + 13.to_s
Convert int.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
[1, 23, 65
[1, 23, 65]
Close bracket.
Python
{{"value":"hello" "value":82}}
{{"value":"hello", "value":82}}
Add comma.
JSON
age: result id: world,
age: result id: world
Remove comma.
YAML
<person name='data'/>
<person name="data"/>
Double quotes.
XML
if c = 94:
if c == 94:
Use == for comparison.
Python
if data = 62 then print('hello') end
if data == 62 then print('hello') end
Use ==.
Lua
print('test')
print('test')
Correct.
R
let bar = 'data'
let bar = "data"
Double quotes.
Swift
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(23);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(23);
Correct.
Node.js
function process() {{ echo 'output'; }}
function process() {{ echo 'output'; }}
Correct.
PHP
h1 {{ font-size:98px color:red; }}
h1 {{ font-size:98px; color:red; }}
Add semicolon.
CSS
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
{{'status':'result'}}
{{"status":"result"}}
Use double quotes.
JSON
var x = 51;
var x = 51;
Correct.
Dart
WHERE name = '63'
WHERE name = 63
Don't quote integer.
SQL
if (a = 91)
if (a == 91)
Use ==.
Scala
data[50]
if (data.indices.contains(50)) data[50]
Check index.
Kotlin
def compute(c): return c + 1
def compute(c): return c + 1
Correct.
Python
def render(): print('data')
def render(): print('data')
Indent function body.
Python
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if a > 73 print('test')
if a > 73: print('test')
Colon missing after if.
Python
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
const c = 50; c = 41;
let c = 50; c = 41;
Cannot reassign const.
JavaScript
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
def handle puts 'data' end
def handle puts 'data' end
Correct.
Ruby
assert y > 80
assert y > 80
Correct.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
DELETE FROM products WHERE email=1
DELETE FROM products WHERE email=1;
Add semicolon.
SQL
val count: Int = 'test'
val count: String = 'test'
Fix type.
Kotlin
UPDATE orders SET email='value' WHERE role=58
UPDATE orders SET email='value' WHERE role=58;
Add semicolon.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
bar = 16
bar=16
No spaces.
Shell
switch(c){{ case 67: break; }}
switch(c){{ case 67: break; default: break; }}
Add default case.
Java
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<br></br>
<br>
Self-closing.
HTML
process
process()
Add parentheses.
Swift