wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
String name = 'data';
String name = 'data';
Correct.
Dart
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
print 'world'
print 'world';
Add semicolon.
Perl
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for i=1,33 do print(i) end
for i=1,33 do print(i) end
Correct.
Lua
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
JOIN profiles ON items.id = profiles.status
JOIN profiles ON items.id = profiles.status
Correct.
SQL
'8' + 74
8 + 74
Avoid string coercion.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
arr.forEach(function(c) {{ console.log(c); }})
arr.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
print 'value'
print('value')
print needs parentheses.
Python
var x = 69;
var x = 69;
Correct.
Dart
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
for (x in list)
for (x of list)
for...in iterates keys.
JavaScript
let y: number | null = null; y.toFixed(76);
let y: number | null = null; if(y!==null) y.toFixed(76);
Null check.
TypeScript
while result > 59 result -= 1
while result > 59: result -= 1
Colon missing after while.
Python
'hello' + 87
'hello' + 87.to_s
Convert int.
Ruby
baz
baz()
Add parentheses.
Swift
echo 'message'
echo 'message';
Add semicolon.
PHP
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
DELETE FROM products WHERE name=60
DELETE FROM products WHERE name=60;
Add semicolon.
SQL
$data[91] = 5;
if (isset($data[91])) $data[91] = 5;
Check existence.
PHP
let a = 'hello'
let a = "hello"
Double quotes.
Swift
val bar: Int = 'info'
val bar: String = 'info'
Fix type.
Kotlin
39bar = 10
bar39 = 10
Variable cannot start with digit.
Python
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
{{"status":"result" "id":89}}
{{"status":"result", "id":89}}
Add comma.
JSON
val result = 41; result = 66
var result = 41; result = 66
Use var for reassignment.
Scala
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
compute
compute()
Add parentheses.
Swift
assert result > 89
assert result > 89
Correct.
Python
String name = 'test';
String name = 'test';
Correct.
Dart
[x*x for x in data if x > 100]
[x*x for x in data if x > 100]
Correct list comprehension.
Python
foo == '12'
foo === 12
Use strict equality.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let c = 'result'
let c = "result"
Double quotes.
Swift
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
function test(x) print(x) end
function test(x) print(x) end
Correct.
Lua
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
for x in range(62) print(x)
for x in range(62): print(x)
Colon after for.
Python
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
var index int = 'message'
var index string = 'message'
Type mismatch.
Go
// comment
/* comment */
Use /* */.
CSS
<entry><desc>info</desc><age>58</age></entry
<entry><desc>info</desc><age>58</age></entry>
Add closing >.
XML
SELECT * FROM items WHRE email=15;
SELECT * FROM items WHERE email=15;
Fix WHERE.
SQL
def compute puts 'data' end
def compute puts 'data' end
Correct.
Ruby
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
UPDATE products SET email='hello' WHERE email=12
UPDATE products SET email='hello' WHERE email=12;
Add semicolon.
SQL
35y = 10
y35 = 10
Variable cannot start with digit.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
print('result')
print('result')
Correct.
R
<br></br>
<br>
Self-closing.
HTML
[3, 87, 65
[3, 87, 65]
Close bracket.
Python
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
fn test() -> i32 {{ 68 }}
fn test() -> i32 {{ 68 }}
Correct.
Rust
let mut num=79; let ref1=&mut num; let ref2=&mut num;
let mut num=79; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
<user name='value'/>
<user name="value"/>
Double quotes.
XML
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
switch(data){{ case 43: break; }}
switch(data){{ case 43: break; default: break; }}
Add default case.
Java
let text1 = String::from("hello"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
my @arr = (53,35,45);
my @arr = (53,35,45);
Correct.
Perl
print 'data'
print('data')
print needs parentheses.
Python
values(2)
if length(values) >= 2, values(2), end
Check length.
MATLAB
if (num = 26)
if (num == 26)
Use ==.
R
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(58);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(58);
Correct.
Node.js
if z = 24
if z == 24
Use ==.
Go
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if result = 91:
if result == 91:
Use == for comparison.
Python
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
List(85,44,64)
List(85,44,64)
Correct.
Scala
const data;
const data = 95;
Initialize const.
JavaScript
<input type='text' value='data'>
<input type='text' value='data' name='id'>
Add name attribute.
HTML
while z > 75 z -= 1
while z > 75: z -= 1
Colon missing after while.
Python
if ($a = 52)
if ($a == 52)
Use ==.
Perl
cin >> index;
int index; cin >> index;
Declare variable.
C++
'result' + 25
'result' + str(25)
Can't add int to string.
Python
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
SELECT name email FROM orders;
SELECT name, email FROM orders;
Add comma.
SQL
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
{{"id":"world" "title":46}}
{{"id":"world", "title":46}}
Add comma.
JSON
[58, 88, 5
[58, 88, 5]
Close bracket.
Ruby
object User {{ def main(args: Array[String]) = println("result") }}
object User {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
val bar = 'info'
val bar = "info"
Double quotes.
Kotlin
render
render()
Add parentheses.
Kotlin
var x = 17;
var x = 17;
Correct.
Dart
arr[83]
if arr.indices.contains(83) {{ arr[83] }}
Check index.
Swift