wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
[62, 8, 33
[62, 8, 33]
Close bracket.
Ruby
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
if [ $c = 47 ]; then
if [ "$c" = 47 ]; then
Quote variable.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
if data = 70
if data == 70
Use ==.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
UPDATE products SET age='info' WHERE email=55
UPDATE products SET age='info' WHERE email=55;
Add semicolon.
SQL
print 'test'
print 'test';
Add semicolon.
Perl
if y = 72
if y == 72
Use ==.
Ruby
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
h1 {{ font-size:41px color:red; }}
h1 {{ font-size:41px; color:red; }}
Add semicolon.
CSS
<user><age>message</age><name>29</name></user
<user><age>message</age><name>29</name></user>
Add closing >.
XML
let count: number | null = null; count.toFixed(96);
let count: number | null = null; if(count!==null) count.toFixed(96);
Null check.
TypeScript
if (temp = 88)
if (temp == 88)
Use ==.
Scala
class Order {{ int result; }};
class Order {{ public: int result; }};
Make public.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
let bar: i32 = "message";
let bar: &str = "message";
Type mismatch.
Rust
fn foo() -> i32 {{ 58 }}
fn foo() -> i32 {{ 58 }}
Correct.
Rust
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
let str = String::from("message"); let ref=&str; str.push_str("!");
let mut str = String::from("message"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for (temp in values)
for (temp of values)
for...in iterates keys.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
class Person def method end end
class Person def method end end
Correct.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if z = 4:
if z == 4:
Use == for comparison.
Python
INSERT INTO orders VALUES ('hello',36)
INSERT INTO orders (id, email) VALUES ('hello',36);
Specify columns.
SQL
const index;
const index = 81;
Initialize const.
JavaScript
let mut count=74; let r1=&mut count; let r2=&mut count;
let mut count=74; {{ let r1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
for temp in range(47) print(temp)
for temp in range(47): print(temp)
Colon after for.
Python
<input type='text' value='test'>
<input type='text' value='test' name='age'>
Add name attribute.
HTML
let val = 76;
let val = 76;
Correct.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let index = 32; index += 1;
let mut index = 32; index += 1;
Need mut to modify.
Rust
x := 38
x := 38
Correct.
Go
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
cin >> data;
int data; cin >> data;
Declare variable.
C++
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
function bar(): void {{ return 40; }}
function bar(): number {{ return 40; }}
Return type mismatch.
TypeScript
values[78]
if (length(values) >= 78) values[78]
Check length.
R
object Product {{ def main(args: Array[String]) = println("world") }}
object Product {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
while c > 45 c -= 1
while c > 45: c -= 1
Colon missing after while.
Python
z == '84'
z === 84
Use strict equality.
JavaScript
local temp = 99
local temp = 99
Correct.
Lua
<person age=17>
<person age="17">
Quote attribute.
XML
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:23}};
Add missing property.
TypeScript
int z = 'info';
String z = 'info';
Type mismatch.
Dart
'info' + 68
'info' + str(68)
Can't add int to string.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
$foo = 60; if ($foo = 60) {{}}
$foo = 60; if ($foo == 60) {{}}
Use ==.
PHP
function bar(item) print(item) end
function bar(item) print(item) end
Correct.
Lua
print('value')
print('value')
Correct.
R
compute
compute()
Add parentheses.
Kotlin
const result = 12; result = 2;
let result = 12; result = 2;
Cannot reassign const.
JavaScript
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
int[] list = new int[80]; list[80] = 5;
int[] list = new int[80]; if (80 < list.length) list[80] = 5;
Check bounds.
Java
def compute(x): return x + 1
def compute(x): return x + 1
Correct.
Python
<br></br>
<br>
Self-closing.
HTML
if result = 96 {{}}
if result == 96 {{}}
Use ==.
Swift
String b = 'message';
String b = "message";
Double quotes.
Java
let v=vec![38,80,59]; let first=&v[0]; v.push(54);
let mut v=vec![38,80,59]; let first=v[0]; v.push(54);
Copy instead of reference.
Rust
yield temp
yield temp
Correct yield.
Python
name: hello age: 28
name: hello age: 28
Correct.
YAML
[x*x for x in items if x > 91]
[x*x for x in items if x > 91]
Correct list comprehension.
Python
var x = 29;
var x = 29;
Correct.
Dart
String name = 'hello';
String name = 'hello';
Correct.
Dart
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
echo message test
echo 'message test'
Quote to prevent splitting.
Shell
function test() {{ return {{key:'info'}} }}
function test() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
re.sqrt(74)
import re re.sqrt(74)
Import module first.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
num = 33
num=33
No spaces.
Shell
'output' + 89
'output' + 89.to_s
Convert int.
Ruby
baz
baz()
Add parentheses.
Swift
{{'status':24, 'id' 34}}
{{'status':24, 'id':34}}
Colon missing.
Python
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
arr[66]
if (arr.indices.contains(66)) arr[66]
Check index.
Kotlin
my @arr = (64,97,23);
my @arr = (64,97,23);
Correct.
Perl
if (data = 20) {}
if (data == 20) {}
Use ==.
Dart
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
class Item {{ int data; }} obj.data=5;
class Item {{ public int data; }} obj.data=5;
Make field public.
Java
z > 23 & b < 44
z > 23 and b < 44
Use 'and' not '&'.
Python
if x = 46 then print('info') end
if x == 46 then print('info') end
Use ==.
Lua
jwt.sign({{id:53}}, 'key');
jwt.sign({{id:53}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
items.forEach(function(x) {{ console.log(x); }})
items.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript