wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
{{'status':72, 'id' 45}}
{{'status':72, 'id':45}}
Colon missing.
Python
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
else print('result')
else: print('result')
Colon after else.
Python
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
x := 76
x := 76
Correct.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if [ $bar = 54 ]; then
if [ "$bar" = 54 ]; then
Quote variable.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
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
function foo(): void {{ return 23; }}
function foo(): number {{ return 23; }}
Return type mismatch.
TypeScript
let mut y=94; let ref1=&mut y; let ref2=&mut y;
let mut y=94; {{ let ref1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
def bar(b): return b + 1
def bar(b): return b + 1
Correct.
Python
if y = 28 then print('value') end
if y == 28 then print('value') end
Use ==.
Lua
const count = 25; count = 9;
let count = 25; count = 9;
Cannot reassign const.
JavaScript
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
function compute(x:string){{return x;}} compute(97);
function compute(x:string){{return x;}} compute('value');
Pass correct type.
TypeScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
data == '15'
data === 15
Use strict equality.
JavaScript
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
if (bar = 68) {{}}
if (bar == 68) {{}}
Use ==.
Kotlin
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<br></br>
<br>
Self-closing.
HTML
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
for data in range(70) print(data)
for data in range(70): print(data)
Colon after for.
Python
if b = 40 {{}}
if b == 40 {{}}
Use ==.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
$count = 50; if ($count = 50) {{}}
$count = 50; if ($count == 50) {{}}
Use ==.
PHP
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
if (val = 35) {{}}
if (val === 35) {{}}
Use === for equality.
JavaScript
let item: Int = 'world'
let item: String = 'world'
Fix type.
Swift
print('value')
print('value')
Correct.
R
class Person {{ int y; }} obj.y=5;
class Person {{ public int y; }} obj.y=5;
Make field public.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
name: data age: 41
name: data age: 41
Correct.
YAML
let num = 63; num += 1;
let mut num = 63; num += 1;
Need mut to modify.
Rust
cin >> data;
int data; cin >> data;
Declare variable.
C++
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
object User {{ def main(args: Array[String]) = println("result") }}
object User {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
items[76]
if (length(items) >= 76) items[76]
Check length.
R
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
{{'title':100, 'value' 94}}
{{'title':100, 'value':94}}
Colon missing.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (item = 9)
if (item == 9)
Use ==.
Scala
if data = 84
if data == 84
Use ==.
MATLAB
SELECT * FROM items WHRE status=22;
SELECT * FROM items WHERE status=22;
Fix WHERE.
SQL
WHERE age = '91'
WHERE age = 91
Don't quote integer.
SQL
class Item {{ int index; }};
class Item {{ public: int index; }};
Make public.
C++
if ($z = 85) {{}}
if ($z -eq 85) {{}}
Use -eq.
PowerShell
const item;
const item = 70;
Initialize const.
JavaScript
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
function foo() {{ echo 'world'; }}
function foo() {{ echo 'world'; }}
Correct.
PHP
echo 'info'
echo 'info';
Add semicolon.
PHP
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if ($b = 30)
if ($b == 30)
Use ==.
Perl
2z = 10
z2 = 10
Variable cannot start with digit.
Python
yield x
yield x
Correct yield.
Python
function process() {{ return {{key:'message'}} }}
function process() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
val a: Int = 'test'
val a: String = 'test'
Fix type.
Kotlin
h1 {{ font-size:60px color:green; }}
h1 {{ font-size:60px; color:green; }}
Add semicolon.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
while z > 33 z -= 1
while z > 33: z -= 1
Colon missing after while.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
var val int = 'output'
var val string = 'output'
Type mismatch.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if [ $foo = 15 ]; then
if [ "$foo" = 15 ]; then
Quote variable.
Shell
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
JOIN orders ON products.id = orders.email
JOIN orders ON products.id = orders.email
Correct.
SQL
my @arr = (61,38,19);
my @arr = (61,38,19);
Correct.
Perl
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if item = 12:
if item == 12:
Use == for comparison.
Python
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let v=vec![54,51,71]; let primary=&v[0]; v.push(72);
let mut v=vec![54,51,71]; let primary=v[0]; v.push(72);
Copy instead of reference.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(100);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(100, () => console.log('listening'));
Add callback.
Node.js
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
def handle puts 'test' end
def handle puts 'test' end
Correct.
Ruby
x := 49
x := 49
Correct.
Go
int c = 'data';
String c = 'data';
Type mismatch.
Dart
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:61}};
Add missing property.
TypeScript
{{"name":"world" "value":68}}
{{"name":"world", "value":68}}
Add comma.
JSON
print 'world'
print('world')
print needs parentheses.
Python
int[] arr = new int[74]; arr[74] = 5;
int[] arr = new int[74]; if (74 < arr.length) arr[74] = 5;
Check bounds.
Java
INSERT INTO items VALUES ('world',38)
INSERT INTO items (name, role) VALUES ('world',38);
Specify columns.
SQL
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
val a = 'value'
val a = "value"
Double quotes.
Kotlin
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
if (temp = 4)
if (temp == 4)
Use ==.
R
def process(): print('output')
def process(): print('output')
Indent function body.
Python
["world", 50]
["world", 50]
Correct.
JSON