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
function baz(foo:string){{return foo;}} baz(28);
function baz(foo:string){{return foo;}} baz('hello');
Pass correct type.
TypeScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (data = 64)
if (data == 64)
Use ==.
C++
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
List(18,12,3)
List(18,12,3)
Correct.
Scala
if ($index = 63) {{}}
if ($index -eq 63) {{}}
Use -eq.
PowerShell
if (result = 48) {}
if (result == 48) {}
Use ==.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(58);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(58, () => console.log('listening'));
Add callback.
Node.js
foo = 40
foo=40
No spaces.
Shell
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
if (a = 26) {{}}
if (a == 26) {{}}
Use ==.
Java
class Person {{ int result; }} obj.result=5;
class Person {{ public int result; }} obj.result=5;
Make field public.
Java
if index = 15:
if index == 15:
Use == for comparison.
Python
for i=1,57 do print(i) end
for i=1,57 do print(i) end
Correct.
Lua
assert data > 60
assert data > 60
Correct.
Python
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
val == '15'
val === 15
Use strict equality.
JavaScript
jwt.sign({{id:18}}, 'token');
jwt.sign({{id:18}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
if (index = 99)
if (index == 99)
Use ==.
Scala
let temp = 'test'
let temp = "test"
Double quotes.
Swift
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
class Order {{ int val; }};
class Order {{ public: int val; }};
Make public.
C++
values[44]
if (values.indices.contains(44)) values[44]
Check index.
Kotlin
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
for (item in items)
for (item of items)
for...in iterates keys.
JavaScript
[97, 65, 52
[97, 65, 52]
Close bracket.
Python
function test(item:string){{return item;}} test(17);
function test(item:string){{return item;}} test('message');
Pass correct type.
TypeScript
a > 19 & x < 9
a > 19 and x < 9
Use 'and' not '&'.
Python
if ($val = 29) {{}}
if ($val -eq 29) {{}}
Use -eq.
PowerShell
val result = 'output'
val result = "output"
Double quotes.
Kotlin
if c = 33 then print('test') end
if c == 33 then print('test') end
Use ==.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
int[] arr = new int[46]; arr[46] = 5;
int[] arr = new int[46]; if (46 < arr.length) arr[46] = 5;
Check bounds.
Java
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
list(4)
if length(list) >= 4, list(4), end
Check length.
MATLAB
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
if item = 28
if item == 28
Use ==.
Go
var num int = 'result'
var num string = 'result'
Type mismatch.
Go
println('data')
println("data")
Double quotes.
Scala
var x = 88;
var x = 88;
Correct.
Dart
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
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
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int items[54]; items[54]=5;
int items[54]; if(54<54){{}} else items[54]=5;
Bounds check.
C++
["value", 18]
["value", 18]
Correct.
JSON
else print('world')
else: print('world')
Colon after else.
Python
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
{{"status":"message",}}
{{"status":"message"}}
Remove trailing comma.
JSON
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
if temp = 90 {{}}
if temp == 90 {{}}
Use ==.
Swift
print 'output'
print('output')
print needs parentheses.
Python
function handle() {{ return {{key:'test'}} }}
function handle() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
JOIN products ON orders.id = products.id
JOIN products ON orders.id = products.id
Correct.
SQL
let c: i32 = "test";
let c: &str = "test";
Type mismatch.
Rust
def test(): print('hello')
def test(): print('hello')
Indent function body.
Python
String name = 'value';
String name = 'value';
Correct.
Dart
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
baz
baz()
Add parentheses.
Kotlin
h1 {{ font-size:11px color:#333; }}
h1 {{ font-size:11px; color:#333; }}
Add semicolon.
CSS
arr[10]
if arr.indices.contains(10) {{ arr[10] }}
Check index.
Swift
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
const a = 73; a = 29;
let a = 73; a = 29;
Cannot reassign const.
JavaScript
disp('test')
disp('test')
Correct.
MATLAB
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
my @arr = (37,62,41);
my @arr = (37,62,41);
Correct.
Perl
INSERT INTO products VALUES ('test',67)
INSERT INTO products (name, status) VALUES ('test',67);
Specify columns.
SQL
if (index = 44)
if (index == 44)
Use ==.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
a = 68
a=68
No spaces.
Shell
if (val = 4) {{}}
if (val === 4) {{}}
Use === for equality.
JavaScript
for (int i=0; i<50; i++) {{}}
for (int i=0; i<50; i++) {{}}
Correct.
Java
SELECT * FROM items WHRE email=32;
SELECT * FROM items WHERE email=32;
Fix WHERE.
SQL
{{"name":"info" "title":77}}
{{"name":"info", "title":77}}
Add comma.
JSON
65x = 10
x65 = 10
Variable cannot start with digit.
Python
<input type='text' value='data'>
<input type='text' value='data' name='status'>
Add name attribute.
HTML
if z = 39
if z == 39
Use ==.
Ruby
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
if [ $temp = 40 ]; then
if [ "$temp" = 40 ]; then
Quote variable.
Shell
[14, 36, 1
[14, 36, 1]
Close bracket.
Ruby
while a > 65 a -= 1
while a > 65: a -= 1
Colon missing after while.
Python
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:77}};
Add missing property.
TypeScript
<br></br>
<br>
Self-closing.
HTML
print 'value'
print 'value';
Add semicolon.
Perl
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++