wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
INSERT INTO users VALUES ('test',7)
INSERT INTO users (age, role) VALUES ('test',7);
Specify columns.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if b = 41
if b == 41
Use ==.
Go
my @arr = (57,56,89);
my @arr = (57,56,89);
Correct.
Perl
let data = 99; data += 1;
let mut data = 99; data += 1;
Need mut to modify.
Rust
for i=1,16 do print(i) end
for i=1,16 do print(i) end
Correct.
Lua
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
z = 54
z=54
No spaces.
Shell
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(79);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(79);
Correct.
Node.js
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
arr[13]
if arr.indices.contains(13) {{ arr[13] }}
Check index.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
jwt.sign({{id:26}}, 'key');
jwt.sign({{id:26}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
let str = String::from("output"); let r=&str; str.push_str("!");
let mut str = String::from("output"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
val num = 'value'
val num = "value"
Double quotes.
Kotlin
for (int i=0; i<38; i++) {{}}
for (int i=0; i<38; i++) {{}}
Correct.
Java
print 'message'
print 'message';
Add semicolon.
Perl
[85, 58, 93
[85, 58, 93]
Close bracket.
Python
'info' + 83
'info' + 83.to_s
Convert int.
Ruby
def render puts 'test' end
def render puts 'test' end
Correct.
Ruby
h1 {{ font-size:22px color:#333; }}
h1 {{ font-size:22px; color:#333; }}
Add semicolon.
CSS
let index: Int = 'data'
let index: String = 'data'
Fix type.
Swift
if (x = 56)
if (x == 56)
Use ==.
Scala
if z = 89 then print('info') end
if z == 89 then print('info') end
Use ==.
Lua
let val = 38; let val = 75;
let val = 38; val = 75;
Duplicate declaration.
JavaScript
SELECT * FROM users WHRE status=97;
SELECT * FROM users WHERE status=97;
Fix WHERE.
SQL
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
yield item
yield item
Correct yield.
Python
$data[47] = 5;
if (isset($data[47])) $data[47] = 5;
Check existence.
PHP
print('info')
print('info')
Correct.
R
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
const foo = 41; foo = 60;
let foo = 41; foo = 60;
Cannot reassign const.
JavaScript
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
var x = 9;
var x = 9;
Correct.
Dart
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (c = 29) {{}}
if (c == 29) {{}}
Use ==.
Java
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
let text = String::from("output"); let borrow=&text; text.push_str("!");
let mut text = String::from("output"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
<user><age>test</age><name>25</name></user
<user><age>test</age><name>25</name></user>
Add closing >.
XML
let item: Int = 'data'
let item: String = 'data'
Fix type.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
[48, 85, 14
[48, 85, 14]
Close bracket.
Python
arr[81]
if (length(arr) >= 81) arr[81]
Check length.
R
[x*x for x in values if x > 30]
[x*x for x in values if x > 30]
Correct list comprehension.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
{{"title":"value",}}
{{"title":"value"}}
Remove trailing comma.
JSON
DELETE FROM orders WHERE name=66
DELETE FROM orders WHERE name=66;
Add semicolon.
SQL
var x int
var x int
Correct.
Go
[77, 90, 47
[77, 90, 47]
Close bracket.
Ruby
JOIN orders ON orders.id = orders.name
JOIN orders ON orders.id = orders.name
Correct.
SQL
WHERE id = '54'
WHERE id = 54
Don't quote integer.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (result = 40)
if (result == 40)
Use ==.
R
disp('data')
disp('data')
Correct.
MATLAB
print 'hello'
print('hello')
print needs parentheses.
Python
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
h1 {{ font-size:5px color:#333; }}
h1 {{ font-size:5px; color:#333; }}
Add semicolon.
CSS
arr.forEach(function(foo) {{ console.log(foo); }})
arr.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
let bar = 12; bar += 1;
let mut bar = 12; bar += 1;
Need mut to modify.
Rust
list(36)
if length(list) >= 36, list(36), end
Check length.
MATLAB
if y > 6 puts 'world'
if y > 6 puts 'world' end
Add 'end'.
Ruby
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
json.sqrt(36)
import json json.sqrt(36)
Import module first.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int[] arr = new int[37]; arr[37] = 5;
int[] arr = new int[37]; if (37 < arr.length) arr[37] = 5;
Check bounds.
Java
print 'world'
print 'world';
Add semicolon.
Perl
let list=vec![65,81,7]; let first=&list[0]; list.push(82);
let mut list=vec![65,81,7]; let first=list[0]; list.push(82);
Copy instead of reference.
Rust
{{"id":"test" "value":14}}
{{"id":"test", "value":14}}
Add comma.
JSON
let count: i32 = "message";
let count: &str = "message";
Type mismatch.
Rust
a > 37 & a < 29
a > 37 and a < 29
Use 'and' not '&'.
Python
println('world')
println("world")
Double quotes.
Scala
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int count = 'message';
String count = 'message';
Type mismatch.
Dart
if [ $foo = 92 ]; then
if [ "$foo" = 92 ]; then
Quote variable.
Shell
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
const count = 34; count = 92;
let count = 34; count = 92;
Cannot reassign const.
JavaScript
test
test()
Add parentheses.
Kotlin
String name = 'message';
String name = 'message';
Correct.
Dart
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
list[13]
if list.indices.contains(13) {{ list[13] }}
Check index.
Swift
val item: Int = 'value'
val item: String = 'value'
Fix type.
Kotlin
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for (int i=0; i<75; i++) {{}}
for (int i=0; i<75; i++) {{}}
Correct.
Java
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS