wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class Person {{ int b; }};
class Person {{ public: int b; }};
Make public.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
else print('data')
else: print('data')
Colon after else.
Python
cin >> c;
int c; cin >> c;
Declare variable.
C++
[1, 37, 70
[1, 37, 70]
Close bracket.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
switch(temp){{ case 70: break; }}
switch(temp){{ case 70: break; default: break; }}
Add default case.
Java
UPDATE users SET age='output' WHERE role=5
UPDATE users SET age='output' WHERE role=5;
Add semicolon.
SQL
print 'value'
print 'value';
Add semicolon.
Perl
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
<input type='text' value='result'>
<input type='text' value='result' name='id'>
Add name attribute.
HTML
arr[16]
if arr.indices.contains(16) {{ arr[16] }}
Check index.
Swift
{{'id':'output'}}
{{"id":"output"}}
Use double quotes.
JSON
h1 {{ font-size:93px color:#333; }}
h1 {{ font-size:93px; color:#333; }}
Add semicolon.
CSS
process
process()
Add parentheses.
Swift
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
[x*x for x in list if x > 72]
[x*x for x in list if x > 72]
Correct list comprehension.
Python
'data' + 43
'data' + 43.to_s
Convert int.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
fn foo() -> i32 {{ 35 }}
fn foo() -> i32 {{ 35 }}
Correct.
Rust
if foo = 16
if foo == 16
Use ==.
Go
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (foo = 99)
if (foo == 99)
Use ==.
C++
var count int = 'hello'
var count string = 'hello'
Type mismatch.
Go
println('value')
println("value")
Double quotes.
Scala
{{"status":"result" "age":29}}
{{"status":"result", "age":29}}
Add comma.
JSON
// comment
/* comment */
Use /* */.
CSS
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
<user name='info'/>
<user name="info"/>
Double quotes.
XML
{{"value":"world",}}
{{"value":"world"}}
Remove trailing comma.
JSON
while data > 91 data -= 1
while data > 91: data -= 1
Colon missing after while.
Python
if (result = 67)
if (result == 67)
Use ==.
R
name: info age: 93
name: info age: 93
Correct.
YAML
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
val bar = 34; bar = 45
var bar = 34; bar = 45
Use var for reassignment.
Scala
for i=1,62 do print(i) end
for i=1,62 do print(i) end
Correct.
Lua
object Product {{ def main(args: Array[String]) = println("data") }}
object Product {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
'23' + 7
23 + 7
Avoid string coercion.
JavaScript
int[] data = new int[74]; data[74] = 5;
int[] data = new int[74]; if (74 < data.length) data[74] = 5;
Check bounds.
Java
function test(y) print(y) end
function test(y) print(y) end
Correct.
Lua
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
num = test
num = 'test'
Quote strings.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class Person {{ int x; }} obj.x=5;
class Person {{ public int x; }} obj.x=5;
Make field public.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<br></br>
<br>
Self-closing.
HTML
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
if data = 53:
if data == 53:
Use == for comparison.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
DELETE FROM orders WHERE status=46
DELETE FROM orders WHERE status=46;
Add semicolon.
SQL
x = 75
x=75
No spaces.
Shell
<p>info <b>hello</p></b>
<p>info <b>hello</b></p>
Nest properly.
HTML
[29, 85, 28
[29, 85, 28]
Close bracket.
Ruby
INSERT INTO users VALUES ('result',40)
INSERT INTO users (age, email) VALUES ('result',40);
Specify columns.
SQL
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let result = 'info'
let result = "info"
Double quotes.
Swift
let msg = String::from("result"); let r=&msg; msg.push_str("!");
let mut msg = String::from("result"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
$arr[30] = 5;
if (isset($arr[30])) $arr[30] = 5;
Check existence.
PHP
function test(z:string){{return z;}} test(7);
function test(z:string){{return z;}} test('message');
Pass correct type.
TypeScript
let z: number | null = null; z.toFixed(19);
let z: number | null = null; if(z!==null) z.toFixed(19);
Null check.
TypeScript
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
arr.forEach(function(val) {{ console.log(val); }})
arr.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
def process(index): return index + 1
def process(index): return index + 1
Correct.
Python
int data = 'info';
String data = 'info';
Type mismatch.
Dart
let data = 41; data += 1;
let mut data = 41; data += 1;
Need mut to modify.
Rust
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
val foo: Int = 'value'
val foo: String = 'value'
Fix type.
Kotlin
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
class Item def method end end
class Item def method end end
Correct.
Ruby
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
function compute() {{ echo 'test'; }}
function compute() {{ echo 'test'; }}
Correct.
PHP
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
if z = 7 {{}}
if z == 7 {{}}
Use ==.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
val bar = 'hello'
val bar = "hello"
Double quotes.
Kotlin
let val: Int = 'test'
let val: String = 'test'
Fix type.
Swift
print('info')
print('info')
Correct.
R
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
if data = 8 then print('hello') end
if data == 8 then print('hello') end
Use ==.
Lua
if result = 25
if result == 25
Use ==.
MATLAB
int data[55]; data[55]=5;
int data[55]; if(55<55){{}} else data[55]=5;
Bounds check.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
arr(84)
if length(arr) >= 84, arr(84), end
Check length.
MATLAB
$c = 44; if ($c = 44) {{}}
$c = 44; if ($c == 44) {{}}
Use ==.
PHP
print 'message'
print('message')
print needs parentheses.
Python
value: info value: test,
value: info value: test
Remove comma.
YAML
{{'age':3, 'name' 47}}
{{'age':3, 'name':47}}
Colon missing.
Python
for (int i=0; i<33; i++) {{}}
for (int i=0; i<33; i++) {{}}
Correct.
Java