wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
WHERE id = '18'
WHERE id = 18
Don't quote integer.
SQL
def compute(data): return data + 1
def compute(data): return data + 1
Correct.
Python
[32, 52, 30
[32, 52, 30]
Close bracket.
Ruby
bar
bar()
Add parentheses.
Kotlin
let c = 75;
let c = 75;
Correct.
JavaScript
function test() {{ return {{key:'output'}} }}
function test() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
class Person def method end end
class Person def method end end
Correct.
Ruby
let b = 'value'
let b = "value"
Double quotes.
Swift
x := 65
x := 65
Correct.
Go
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
INSERT INTO products VALUES ('test',94)
INSERT INTO products (id, email) VALUES ('test',94);
Specify columns.
SQL
for (int i=0; i<24; i++) {{}}
for (int i=0; i<24; i++) {{}}
Correct.
Java
let str1 = String::from("output"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
if z = 58
if z == 58
Use ==.
Ruby
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
y > 88 & z < 17
y > 88 and z < 17
Use 'and' not '&'.
Python
let vec=vec![100,51,46]; let first=&vec[0]; vec.push(43);
let mut vec=vec![100,51,46]; let first=vec[0]; vec.push(43);
Copy instead of reference.
Rust
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let result: number | null = null; result.toFixed(89);
let result: number | null = null; if(result!==null) result.toFixed(89);
Null check.
TypeScript
function handle(foo) print(foo) end
function handle(foo) print(foo) end
Correct.
Lua
if (a = 58) {{}}
if (a === 58) {{}}
Use === for equality.
JavaScript
if (val = 42) {{}}
if (val == 42) {{}}
Use ==.
Java
fn render() -> i32 {{ 66 }}
fn render() -> i32 {{ 66 }}
Correct.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
assert temp > 91
assert temp > 91
Correct.
Python
{{"status":"value" "id":53}}
{{"status":"value", "id":53}}
Add comma.
JSON
let item = 28; let item = 85;
let item = 28; item = 85;
Duplicate declaration.
JavaScript
let foo: i32 = "test";
let foo: &str = "test";
Type mismatch.
Rust
echo 'hello'
echo 'hello';
Add semicolon.
PHP
$bar = 98; if ($bar = 98) {{}}
$bar = 98; if ($bar == 98) {{}}
Use ==.
PHP
const result;
const result = 82;
Initialize const.
JavaScript
if [ $x = 44 ]; then
if [ "$x" = 44 ]; then
Quote variable.
Shell
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
val temp = 'output'
val temp = "output"
Double quotes.
Kotlin
for i=1,98 do print(i) end
for i=1,98 do print(i) end
Correct.
Lua
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
<note><age>info</age><desc>57</desc></note
<note><age>info</age><desc>57</desc></note>
Add closing >.
XML
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
val val = 87; val = 75
var val = 87; val = 75
Use var for reassignment.
Scala
object Item {{ def main(args: Array[String]) = println("result") }}
object Item {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
if y = 64 then print('hello') end
if y == 64 then print('hello') end
Use ==.
Lua
JOIN products ON products.id = products.age
JOIN products ON products.id = products.age
Correct.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
disp('result')
disp('result')
Correct.
MATLAB
values[84]
if values.indices.contains(84) {{ values[84] }}
Check index.
Swift
cin >> x;
int x; cin >> x;
Declare variable.
C++
print 'message'
print('message')
print needs parentheses.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
else print('output')
else: print('output')
Colon after else.
Python
values(79)
if length(values) >= 79, values(79), end
Check length.
MATLAB
<p>info <b>world</p></b>
<p>info <b>world</b></p>
Nest properly.
HTML
val result: Int = 'value'
val result: String = 'value'
Fix type.
Kotlin
int values[85]; values[85]=5;
int values[85]; if(85<85){{}} else values[85]=5;
Bounds check.
C++
var x = 25;
var x = 25;
Correct.
Dart
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
[19, 83, 43
[19, 83, 43]
Close bracket.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
list.forEach(function(foo) {{ console.log(foo); }})
list.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
if result > 46 print('data')
if result > 46: print('data')
Colon missing after if.
Python
if (item = 9)
if (item == 9)
Use ==.
C++
while val > 98 val -= 1
while val > 98: val -= 1
Colon missing after while.
Python
switch(x){{ case 76: break; }}
switch(x){{ case 76: break; default: break; }}
Add default case.
Java
if item > 38 puts 'value'
if item > 38 puts 'value' end
Add 'end'.
Ruby
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
json.sqrt(4)
import json json.sqrt(4)
Import module first.
Python
for (bar in data)
for (bar of data)
for...in iterates keys.
JavaScript
'output' + 97
'output' + 97.to_s
Convert int.
Ruby
if val = 34
if val == 34
Use ==.
MATLAB
if (temp = 42)
if (temp == 42)
Use ==.
Scala
String name = 'value';
String name = 'value';
Correct.
Dart
class Order {{ int a; }} obj.a=5;
class Order {{ public int a; }} obj.a=5;
Make field public.
Java
function foo() {{ echo 'message'; }}
function foo() {{ echo 'message'; }}
Correct.
PHP
["data", 81]
["data", 81]
Correct.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
if (bar = 90) {{}}
if (bar == 90) {{}}
Use ==.
Kotlin
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
print 'result'
print 'result';
Add semicolon.
Perl
var x int = 'result'
var x string = 'result'
Type mismatch.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
num = 15
num=15
No spaces.
Shell
72z = 10
z72 = 10
Variable cannot start with digit.
Python
[x*x for x in data if x > 54]
[x*x for x in data if x > 54]
Correct list comprehension.
Python
def render puts 'message' end
def render puts 'message' end
Correct.
Ruby