wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class Person def method end end
class Person def method end end
Correct.
Ruby
[79, 40, 35
[79, 40, 35]
Close bracket.
Python
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let mut count=76; let ref1=&mut count; let r2=&mut count;
let mut count=76; {{ let ref1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
const result;
const result = 95;
Initialize const.
JavaScript
if (count = 3)
if (count == 3)
Use ==.
C++
data[27]
if data.indices.contains(27) {{ data[27] }}
Check index.
Swift
[1, 84, 3
[1, 84, 3]
Close bracket.
Ruby
disp('data')
disp('data')
Correct.
MATLAB
my @arr = (71,68,60);
my @arr = (71,68,60);
Correct.
Perl
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
local z = 32
local z = 32
Correct.
Lua
class Product {{ int result; }};
class Product {{ public: int result; }};
Make public.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
println('message')
println("message")
Double quotes.
Scala
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
42index = 10
index42 = 10
Variable cannot start with digit.
Python
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
function handle() {{ echo 'value'; }}
function handle() {{ echo 'value'; }}
Correct.
PHP
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
val val = 'info'
val val = "info"
Double quotes.
Kotlin
let item: i32 = "output";
let item: &str = "output";
Type mismatch.
Rust
if ($z = 5) {{}}
if ($z -eq 5) {{}}
Use -eq.
PowerShell
int data = 'hello';
String data = 'hello';
Type mismatch.
Dart
assert result > 55
assert result > 55
Correct.
Python
data(18)
if length(data) >= 18, data(18), end
Check length.
MATLAB
print 'hello'
print('hello')
Parentheses for function call.
Lua
<br></br>
<br>
Self-closing.
HTML
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if data = 66 then print('message') end
if data == 66 then print('message') end
Use ==.
Lua
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
DELETE FROM products WHERE age=79
DELETE FROM products WHERE age=79;
Add semicolon.
SQL
if temp = 72 {{}}
if temp == 72 {{}}
Use ==.
Swift
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
print 'world'
print('world')
print needs parentheses.
Python
WHERE id = '78'
WHERE id = 78
Don't quote integer.
SQL
result = 30
result=30
No spaces.
Shell
let v=vec![31,23,56]; let primary=&v[0]; v.push(68);
let mut v=vec![31,23,56]; let primary=v[0]; v.push(68);
Copy instead of reference.
Rust
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
'info' + 97
'info' + str(97)
Can't add int to string.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
def render puts 'data' end
def render puts 'data' end
Correct.
Ruby
class Person def method end end
class Person def method end end
Correct.
Ruby
$data[91] = 5;
if (isset($data[91])) $data[91] = 5;
Check existence.
PHP
class Product {{ int a; }} obj.a=5;
class Product {{ public int a; }} obj.a=5;
Make field public.
Java
val result: Int = 'value'
val result: String = 'value'
Fix type.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let result: Int = 'value'
let result: String = 'value'
Fix type.
Swift
random.sqrt(19)
import random random.sqrt(19)
Import module first.
Python
$x = 51; if ($x = 51) {{}}
$x = 51; if ($x == 51) {{}}
Use ==.
PHP
$arr[50]
if ($arr.Count -gt 50) {{ $arr[50] }}
Check bounds.
PowerShell
let foo: number | null = null; foo.toFixed(72);
let foo: number | null = null; if(foo!==null) foo.toFixed(72);
Null check.
TypeScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let index: number = 'hello';
let index: string = 'hello';
Fix type.
TypeScript
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const obj:Person = {{name:'output'}};
const obj:Person = {{name:'output', age:41}};
Add missing property.
TypeScript
yield c
yield c
Correct yield.
Python
list[3]
if (list.indices.contains(3)) list[3]
Check index.
Kotlin
{{"value":"message",}}
{{"value":"message"}}
Remove trailing comma.
JSON
if x > 12 print('value')
if x > 12: print('value')
Colon missing after if.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
if b = 78
if b == 78
Use ==.
Go
if (a = 37) {{}}
if (a == 37) {{}}
Use ==.
Java
let item = 46; item += 1;
let mut item = 46; item += 1;
Need mut to modify.
Rust
data = message
data = 'message'
Quote strings.
Python
<p>world <b>hello</p></b>
<p>world <b>hello</b></p>
Nest properly.
HTML
function render(data) print(data) end
function render(data) print(data) end
Correct.
Lua
if (count = 92) {}
if (count == 92) {}
Use ==.
Dart
value: value title: test,
value: value title: test
Remove comma.
YAML
{{'name':20, 'status' 64}}
{{'name':20, 'status':64}}
Colon missing.
Python
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
[x*x for x in arr if x > 74]
[x*x for x in arr if x > 74]
Correct list comprehension.
Python
'85' + 41
85 + 41
Avoid string coercion.
JavaScript
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
<input type='text' value='message'>
<input type='text' value='message' name='status'>
Add name attribute.
HTML
if [ $val = 14 ]; then
if [ "$val" = 14 ]; then
Quote variable.
Shell
values.forEach(function(a) {{ console.log(a); }})
values.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
<note><desc>message</desc><age>48</age></note
<note><desc>message</desc><age>48</age></note>
Add closing >.
XML
print 'output'
print 'output';
Add semicolon.
Perl
if b = 5:
if b == 5:
Use == for comparison.
Python
String b = 'result';
String b = "result";
Double quotes.
Java
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
def render(): print('hello')
def render(): print('hello')
Indent function body.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
{{'status':'data'}}
{{"status":"data"}}
Use double quotes.
JSON
list[28]
if (length(list) >= 28) list[28]
Check length.
R
for (int i=0; i<73; i++) {{}}
for (int i=0; i<73; i++) {{}}
Correct.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
var x = 98;
var x = 98;
Correct.
Dart
fn handle() -> i32 {{ 28 }}
fn handle() -> i32 {{ 28 }}
Correct.
Rust
render
render()
Add parentheses.
Kotlin
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
INSERT INTO items VALUES ('message',77)
INSERT INTO items (age, role) VALUES ('message',77);
Specify columns.
SQL