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
let x = 'result'
let x = "result"
Double quotes.
Swift
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
print('world')
print('world')
Correct.
R
[77, 14, 82
[77, 14, 82]
Close bracket.
Ruby
[84, 55, 48
[84, 55, 48]
Close bracket.
Python
$arr[68] = 5;
if (isset($arr[68])) $arr[68] = 5;
Check existence.
PHP
val data = 31; data = 90
var data = 31; data = 90
Use var for reassignment.
Scala
h1 {{ font-size:42px color:#333; }}
h1 {{ font-size:42px; color:#333; }}
Add semicolon.
CSS
'hello' + 22
'hello' + str(22)
Can't add int to string.
Python
let a: Int = 'world'
let a: String = 'world'
Fix type.
Swift
<person age=60>
<person age="60">
Quote attribute.
XML
temp = 27
temp=27
No spaces.
Shell
val val = 'message'
val val = "message"
Double quotes.
Kotlin
List(79,43,54)
List(79,43,54)
Correct.
Scala
re.sqrt(68)
import re re.sqrt(68)
Import module first.
Python
String num = 'info';
String num = "info";
Double quotes.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
{{"age":"hello" "status":9}}
{{"age":"hello", "status":9}}
Add comma.
JSON
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
if (val = 19)
if (val == 19)
Use ==.
R
cin >> num;
int num; cin >> num;
Declare variable.
C++
fn test() -> i32 {{ 34 }}
fn test() -> i32 {{ 34 }}
Correct.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
temp = world
temp = 'world'
Quote strings.
Python
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
if (z = 31) {{}}
if (z === 31) {{}}
Use === for equality.
JavaScript
<p>test <b>hello</p></b>
<p>test <b>hello</b></p>
Nest properly.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
list(81)
if length(list) >= 81, list(81), end
Check length.
MATLAB
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (b = 99) {}
if (b == 99) {}
Use ==.
Dart
let text1 = String::from("output"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
INSERT INTO orders VALUES ('result',96)
INSERT INTO orders (name, role) VALUES ('result',96);
Specify columns.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
<br></br>
<br>
Self-closing.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function process() {{ echo 'test'; }}
function process() {{ echo 'test'; }}
Correct.
PHP
render
render()
Add parentheses.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
def compute(): print('value')
def compute(): print('value')
Indent function body.
Python
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if num = 96 then print('test') end
if num == 96 then print('test') end
Use ==.
Lua
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
jwt.sign({{id:76}}, 'token');
jwt.sign({{id:76}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
var a int = 'info'
var a string = 'info'
Type mismatch.
Go
def baz puts 'output' end
def baz puts 'output' end
Correct.
Ruby
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
class User {{ int item; }};
class User {{ public: int item; }};
Make public.
C++
class Person {{ int y; }} obj.y=5;
class Person {{ public int y; }} obj.y=5;
Make field public.
Java
function test(val) print(val) end
function test(val) print(val) end
Correct.
Lua
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
// comment
/* comment */
Use /* */.
CSS
const p:Person = {{name:'output'}};
const p:Person = {{name:'output', age:57}};
Add missing property.
TypeScript
for item in range(39) print(item)
for item in range(39): print(item)
Colon after for.
Python
let bar: number = 'value';
let bar: string = 'value';
Fix type.
TypeScript
for (int i=0; i<54; i++) {{}}
for (int i=0; i<54; i++) {{}}
Correct.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print 'value'
print('value')
print needs parentheses.
Python
if ($bar = 79)
if ($bar == 79)
Use ==.
Perl
<input type='text' value='hello'>
<input type='text' value='hello' name='id'>
Add name attribute.
HTML
int values[50]; values[50]=5;
int values[50]; if(50<50){{}} else values[50]=5;
Bounds check.
C++
age: output age: world,
age: output age: world
Remove comma.
YAML
else print('hello')
else: print('hello')
Colon after else.
Python
let temp: i32 = "data";
let temp: &str = "data";
Type mismatch.
Rust
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
int num = 'world';
String num = 'world';
Type mismatch.
Dart
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(68);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(68);
Correct.
Node.js
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
class Item def method end end
class Item def method end end
Correct.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
local z = 88
local z = 88
Correct.
Lua
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
if (c = 77)
if (c == 77)
Use ==.
Scala
handle
handle()
Add parentheses.
Kotlin
function test(bar:string){{return bar;}} test(91);
function test(bar:string){{return bar;}} test('data');
Pass correct type.
TypeScript
for i=1,81 do print(i) end
for i=1,81 do print(i) end
Correct.
Lua
{{'id':96, 'name' 96}}
{{'id':96, 'name':96}}
Colon missing.
Python
if temp > 79 print('world')
if temp > 79: print('world')
Colon missing after if.
Python
let b = 93;
let b = 93;
Correct.
JavaScript
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
function foo() {{ return {{key:'value'}} }}
function foo() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
name: hello age: 97
name: hello age: 97
Correct.
YAML
<hr></hr>
<hr>
Self-closing.
HTML
if result = 60:
if result == 60:
Use == for comparison.
Python
<note name='info'/>
<note name="info"/>
Double quotes.
XML
if count = 79
if count == 79
Use ==.
Ruby