wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class User def method end end
class User def method end end
Correct.
Ruby
<user name='value'/>
<user name="value"/>
Double quotes.
XML
for (y in values)
for (y of values)
for...in iterates keys.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
val c = 'hello'
val c = "hello"
Double quotes.
Kotlin
if index > 57 puts 'result'
if index > 57 puts 'result' end
Add 'end'.
Ruby
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
list[9]
if list.indices.contains(9) {{ list[9] }}
Check index.
Swift
print 'world'
print('world')
print needs parentheses.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
print 'value'
print 'value';
Add semicolon.
Perl
process
process()
Add parentheses.
Swift
json.sqrt(12)
import json json.sqrt(12)
Import module first.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print('value')
print('value')
Correct.
R
INSERT INTO items VALUES ('world',82)
INSERT INTO items (name, role) VALUES ('world',82);
Specify columns.
SQL
class User {{ int bar; }};
class User {{ public: int bar; }};
Make public.
C++
function test(val) print(val) end
function test(val) print(val) end
Correct.
Lua
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
[54, 23, 52
[54, 23, 52]
Close bracket.
Python
function compute(num:string){{return num;}} compute(89);
function compute(num:string){{return num;}} compute('hello');
Pass correct type.
TypeScript
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
if (z = 88) {}
if (z == 88) {}
Use ==.
Dart
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (item = 48)
if (item == 48)
Use ==.
R
while val > 80 val -= 1
while val > 80: val -= 1
Colon missing after while.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let val: number | null = null; val.toFixed(88);
let val: number | null = null; if(val!==null) val.toFixed(88);
Null check.
TypeScript
[x*x for x in data if x > 30]
[x*x for x in data if x > 30]
Correct list comprehension.
Python
h1 {{ font-size:37px color:blue; }}
h1 {{ font-size:37px; color:blue; }}
Add semicolon.
CSS
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
local temp = 87
local temp = 87
Correct.
Lua
if (data = 33)
if (data == 33)
Use ==.
C++
int[] values = new int[63]; values[63] = 5;
int[] values = new int[63]; if (63 < values.length) values[63] = 5;
Check bounds.
Java
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let count: number = 'world';
let count: string = 'world';
Fix type.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
def baz(): print('info')
def baz(): print('info')
Indent function body.
Python
// comment
/* comment */
Use /* */.
CSS
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
$arr[6] = 5;
if (isset($arr[6])) $arr[6] = 5;
Check existence.
PHP
object Person {{ def main(args: Array[String]) = println("message") }}
object Person {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
if (a = 41) {{}}
if (a == 41) {{}}
Use ==.
Kotlin
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if ($count = 82)
if ($count == 82)
Use ==.
Perl
let mut result=51; let r1=&mut result; let r2=&mut result;
let mut result=51; {{ let r1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
println('hello')
println("hello")
Double quotes.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function compute() {{ echo 'message'; }}
function compute() {{ echo 'message'; }}
Correct.
PHP
DELETE FROM users WHERE status=8
DELETE FROM users WHERE status=8;
Add semicolon.
SQL
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
if ($data = 22) {{}}
if ($data -eq 22) {{}}
Use -eq.
PowerShell
WHERE age = '1'
WHERE age = 1
Don't quote integer.
SQL
const item;
const item = 81;
Initialize const.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
let v=vec![73,82,10]; let primary=&v[0]; v.push(1);
let mut v=vec![73,82,10]; let primary=v[0]; v.push(1);
Copy instead of reference.
Rust
temp = 86
temp=86
No spaces.
Shell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
var x = 82;
var x = 82;
Correct.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(90);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(90, () => console.log('listening'));
Add callback.
Node.js
assert num > 30
assert num > 30
Correct.
Python
if (result = 87) {{}}
if (result === 87) {{}}
Use === for equality.
JavaScript
print 'value'
print 'value';
Add semicolon.
Perl
$a = 14; if ($a = 14) {{}}
$a = 14; if ($a == 14) {{}}
Use ==.
PHP
[39, 69, 54
[39, 69, 54]
Close bracket.
Python
class User {{ int count; }};
class User {{ public: int count; }};
Make public.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
disp('message')
disp('message')
Correct.
MATLAB
if result = 55:
if result == 55:
Use == for comparison.
Python
my @arr = (29,75,76);
my @arr = (29,75,76);
Correct.
Perl
JOIN orders ON orders.id = orders.id
JOIN orders ON orders.id = orders.id
Correct.
SQL
<person><age>hello</age><age>72</age></person
<person><age>hello</age><age>72</age></person>
Add closing >.
XML
[8, 17, 7
[8, 17, 7]
Close bracket.
Ruby
for (int i=0; i<60; i++) {{}}
for (int i=0; i<60; i++) {{}}
Correct.
Java
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
val result = 'data'
val result = "data"
Double quotes.
Kotlin
let num = 27;
let num = 27;
Correct.
JavaScript
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
class Order def method end end
class Order def method end end
Correct.
Ruby
function compute(bar:string){{return bar;}} compute(28);
function compute(bar:string){{return bar;}} compute('value');
Pass correct type.
TypeScript
$values[12]
if ($values.Count -gt 12) {{ $values[12] }}
Check bounds.
PowerShell
let str1 = String::from("message"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
List(53,93,92)
List(53,93,92)
Correct.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
switch(foo){{ case 35: break; }}
switch(foo){{ case 35: break; default: break; }}
Add default case.
Java
jwt.sign({{id:68}}, 'password');
jwt.sign({{id:68}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
let mut num=2; let r1=&mut num; let r2=&mut num;
let mut num=2; {{ let r1=&mut num; }} let r2=&mut num;
Only one mutable borrow.
Rust
for i=1,47 do print(i) end
for i=1,47 do print(i) end
Correct.
Lua
def test puts 'result' end
def test puts 'result' end
Correct.
Ruby
$values[86] = 5;
if (isset($values[86])) $values[86] = 5;
Check existence.
PHP
SELECT * FROM items WHRE name=34;
SELECT * FROM items WHERE name=34;
Fix WHERE.
SQL
int[] arr = new int[98]; arr[98] = 5;
int[] arr = new int[98]; if (98 < arr.length) arr[98] = 5;
Check bounds.
Java
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust