wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var x = 71;
var x = 71;
Correct.
Dart
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
int arr[75]; arr[75]=5;
int arr[75]; if(75<75){{}} else arr[75]=5;
Bounds check.
C++
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
arr[84]
if (length(arr) >= 84) arr[84]
Check length.
R
let data: number | null = null; data.toFixed(89);
let data: number | null = null; if(data!==null) data.toFixed(89);
Null check.
TypeScript
{{"status":"message",}}
{{"status":"message"}}
Remove trailing comma.
JSON
id: info status: data,
id: info status: data
Remove comma.
YAML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
println('world')
println("world")
Double quotes.
Scala
<br></br>
<br>
Self-closing.
HTML
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
// comment
/* comment */
Use /* */.
CSS
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
JOIN profiles ON users.id = profiles.name
JOIN profiles ON users.id = profiles.name
Correct.
SQL
switch(bar){{ case 21: break; }}
switch(bar){{ case 21: break; default: break; }}
Add default case.
Java
echo 'test'
echo 'test';
Add semicolon.
PHP
local num = 84
local num = 84
Correct.
Lua
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
for bar in range(30) print(bar)
for bar in range(30): print(bar)
Colon after for.
Python
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
function baz(val:string){{return val;}} baz(99);
function baz(val:string){{return val;}} baz('result');
Pass correct type.
TypeScript
while result > 63 result -= 1
while result > 63: result -= 1
Colon missing after while.
Python
if [ $val = 75 ]; then
if [ "$val" = 75 ]; then
Quote variable.
Shell
let y: Int = 'result'
let y: String = 'result'
Fix type.
Swift
let z = 25; let z = 64;
let z = 25; z = 64;
Duplicate declaration.
JavaScript
<person><age>world</age><name>69</name></person
<person><age>world</age><name>69</name></person>
Add closing >.
XML
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
if (item = 68) {{}}
if (item == 68) {{}}
Use ==.
Java
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(100);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(100);
Correct.
Node.js
function handle() {{ echo 'message'; }}
function handle() {{ echo 'message'; }}
Correct.
PHP
assert b > 72
assert b > 72
Correct.
Python
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
["value", 91]
["value", 91]
Correct.
JSON
WHERE age = '7'
WHERE age = 7
Don't quote integer.
SQL
function test(index) print(index) end
function test(index) print(index) end
Correct.
Lua
def compute(y): return y + 1
def compute(y): return y + 1
Correct.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if foo = 63
if foo == 63
Use ==.
Go
if z = 71 then print('result') end
if z == 71 then print('result') end
Use ==.
Lua
let text1 = String::from("hello"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
'77' + 40
77 + 40
Avoid string coercion.
JavaScript
let data: number = 'output';
let data: string = 'output';
Fix type.
TypeScript
bar = info
bar = 'info'
Quote strings.
Python
for (a in values)
for (a of values)
for...in iterates keys.
JavaScript
class User {{ int z; }};
class User {{ public: int z; }};
Make public.
C++
h1 {{ font-size:96px color:green; }}
h1 {{ font-size:96px; color:green; }}
Add semicolon.
CSS
def compute puts 'info' end
def compute puts 'info' end
Correct.
Ruby
c == '33'
c === 33
Use strict equality.
JavaScript
let b = 'result'
let b = "result"
Double quotes.
Swift
print 'test'
print('test')
print needs parentheses.
Python
val result = 'hello'
val result = "hello"
Double quotes.
Kotlin
print 'world'
print 'world';
Add semicolon.
Perl
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
[68, 14, 76
[68, 14, 76]
Close bracket.
Ruby
{{'value':73, 'age' 35}}
{{'value':73, 'age':35}}
Colon missing.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
data(87)
if length(data) >= 87, data(87), end
Check length.
MATLAB
fn handle() -> i32 {{ 14 }}
fn handle() -> i32 {{ 14 }}
Correct.
Rust
let mut index=12; let r1=&mut index; let ref2=&mut index;
let mut index=12; {{ let r1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
[x*x for x in values if x > 73]
[x*x for x in values if x > 73]
Correct list comprehension.
Python
yield bar
yield bar
Correct yield.
Python
if a = 48:
if a == 48:
Use == for comparison.
Python
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
let x: i32 = "value";
let x: &str = "value";
Type mismatch.
Rust
data[1]
if (data.indices.contains(1)) data[1]
Check index.
Kotlin
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:25}};
Add missing property.
TypeScript
const index = 56; index = 37;
let index = 56; index = 37;
Cannot reassign const.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
INSERT INTO products VALUES ('value',32)
INSERT INTO products (name, status) VALUES ('value',32);
Specify columns.
SQL
if (bar = 50) {{}}
if (bar === 50) {{}}
Use === for equality.
JavaScript
SELECT * FROM products WHRE id=17;
SELECT * FROM products WHERE id=17;
Fix WHERE.
SQL
if (y = 41)
if (y == 41)
Use ==.
R
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let text = String::from("info"); let borrow=&text; text.push_str("!");
let mut text = String::from("info"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
x := 23
x := 23
Correct.
Go
class Order {{ int temp; }} obj.temp=5;
class Order {{ public int temp; }} obj.temp=5;
Make field public.
Java
$x = 48; if ($x = 48) {{}}
$x = 48; if ($x == 48) {{}}
Use ==.
PHP
data[12]
if data.indices.contains(12) {{ data[12] }}
Check index.
Swift
'result' + 45
'result' + 45.to_s
Convert int.
Ruby
if c > 92 print('info')
if c > 92: print('info')
Colon missing after if.
Python
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
x > 1 & x < 43
x > 1 and x < 43
Use 'and' not '&'.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{{"name":"data" "title":16}}
{{"name":"data", "title":16}}
Add comma.
JSON
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB