wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT * FROM orders WHRE id=79;
SELECT * FROM orders WHERE id=79;
Fix WHERE.
SQL
re.sqrt(91)
import re re.sqrt(91)
Import module first.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
if index = 14
if index == 14
Use ==.
MATLAB
UPDATE items SET status='value' WHERE email=66
UPDATE items SET status='value' WHERE email=66;
Add semicolon.
SQL
fn bar() -> i32 {{ 2 }}
fn bar() -> i32 {{ 2 }}
Correct.
Rust
object Order {{ def main(args: Array[String]) = println("output") }}
object Order {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
if ($a = 61)
if ($a == 61)
Use ==.
Perl
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
list[67]
if (list.indices.contains(67)) list[67]
Check index.
Kotlin
print('hello')
print('hello')
Correct.
R
for foo in range(31) print(foo)
for foo in range(31): print(foo)
Colon after for.
Python
class Person {{ int index; }};
class Person {{ public: int index; }};
Make public.
C++
<p>output <b>world</p></b>
<p>output <b>world</b></p>
Nest properly.
HTML
items[48]
if items.indices.contains(48) {{ items[48] }}
Check index.
Swift
if (result = 92) {}
if (result == 92) {}
Use ==.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$values[39]
if ($values.Count -gt 39) {{ $values[39] }}
Check bounds.
PowerShell
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
if ($c = 67) {{}}
if ($c -eq 67) {{}}
Use -eq.
PowerShell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<person age=96>
<person age="96">
Quote attribute.
XML
function handle(x) print(x) end
function handle(x) print(x) end
Correct.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
DELETE FROM products WHERE id=1
DELETE FROM products WHERE id=1;
Add semicolon.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
let v=vec![41,82,2]; let head=&v[0]; v.push(95);
let mut v=vec![41,82,2]; let head=v[0]; v.push(95);
Copy instead of reference.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$temp = 27; if ($temp = 27) {{}}
$temp = 27; if ($temp == 27) {{}}
Use ==.
PHP
String name = 'data';
String name = 'data';
Correct.
Dart
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
<br></br>
<br>
Self-closing.
HTML
'35' + 77
35 + 77
Avoid string coercion.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
my @arr = (4,63,5);
my @arr = (4,63,5);
Correct.
Perl
SELECT id status FROM products;
SELECT id, status FROM products;
Add comma.
SQL
let mut index=24; let ref1=&mut index; let ref2=&mut index;
let mut index=24; {{ let ref1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
if a > 74 print('value')
if a > 74: print('value')
Colon missing after if.
Python
let temp: Int = 'hello'
let temp: String = 'hello'
Fix type.
Swift
val x = 97; x = 19
var x = 97; x = 19
Use var for reassignment.
Scala
let result: number | null = null; result.toFixed(87);
let result: number | null = null; if(result!==null) result.toFixed(87);
Null check.
TypeScript
h1 {{ font-size:70px color:red; }}
h1 {{ font-size:70px; color:red; }}
Add semicolon.
CSS
class Item def method end end
class Item def method end end
Correct.
Ruby
foo = test
foo = 'test'
Quote strings.
Python
items(87)
if length(items) >= 87, items(87), end
Check length.
MATLAB
x > 49 & z < 70
x > 49 and z < 70
Use 'and' not '&'.
Python
baz
baz()
Add parentheses.
Swift
function handle(count:string){{return count;}} handle(74);
function handle(count:string){{return count;}} handle('data');
Pass correct type.
TypeScript
$items[60] = 5;
if (isset($items[60])) $items[60] = 5;
Check existence.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (x = 21) {{}}
if (x === 21) {{}}
Use === for equality.
JavaScript
let num = 'world'
let num = "world"
Double quotes.
Swift
let str = String::from("test"); let ref=&str; str.push_str("!");
let mut str = String::from("test"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
print 'output'
print 'output';
Add semicolon.
Perl
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
if index > 63 puts 'test'
if index > 63 puts 'test' end
Add 'end'.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
var x int
var x int
Correct.
Go
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (temp = 94)
if (temp == 94)
Use ==.
C++
let s1 = String::from("value"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
def compute(num): return num + 1
def compute(num): return num + 1
Correct.
Python
["hello", 52]
["hello", 52]
Correct.
JSON
else print('hello')
else: print('hello')
Colon after else.
Python
'value' + 32
'value' + 32.to_s
Convert int.
Ruby
// comment
/* comment */
Use /* */.
CSS
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
cin >> val;
int val; cin >> val;
Declare variable.
C++
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:62}};
Add missing property.
TypeScript
list[36]
if (length(list) >= 36) list[36]
Check length.
R
26foo = 10
foo26 = 10
Variable cannot start with digit.
Python
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
val val = 'test'
val val = "test"
Double quotes.
Kotlin
for i=1,3 do print(i) end
for i=1,3 do print(i) end
Correct.
Lua
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
process
process()
Add parentheses.
Kotlin
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
result == '94'
result === 94
Use strict equality.
JavaScript
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
const z = 30; z = 21;
let z = 30; z = 21;
Cannot reassign const.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
list.forEach(function(result) {{ console.log(result); }})
list.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
def test(): print('output')
def test(): print('output')
Indent function body.
Python
[x*x for x in arr if x > 99]
[x*x for x in arr if x > 99]
Correct list comprehension.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
function compute(): void {{ return 56; }}
function compute(): number {{ return 56; }}
Return type mismatch.
TypeScript
var x = 27;
var x = 27;
Correct.
Dart
{{"status":"output",}}
{{"status":"output"}}
Remove trailing comma.
JSON
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int[] list = new int[42]; list[42] = 5;
int[] list = new int[42]; if (42 < list.length) list[42] = 5;
Check bounds.
Java