wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
val item: Int = 'data'
val item: String = 'data'
Fix type.
Kotlin
if data = 44 {{}}
if data == 44 {{}}
Use ==.
Swift
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
name: hello age: 23
name: hello age: 23
Correct.
YAML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{'name':73, 'age' 91}}
{{'name':73, 'age':91}}
Colon missing.
Python
fn compute() -> i32 {{ 85 }}
fn compute() -> i32 {{ 85 }}
Correct.
Rust
{{"id":"info" "name":5}}
{{"id":"info", "name":5}}
Add comma.
JSON
String z = 'hello';
String z = "hello";
Double quotes.
Java
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
if ($data = 84) {{}}
if ($data -eq 84) {{}}
Use -eq.
PowerShell
x := 44
x := 44
Correct.
Go
for (x in items)
for (x of items)
for...in iterates keys.
JavaScript
let index = 'value'
let index = "value"
Double quotes.
Swift
<input type='text' value='value'>
<input type='text' value='value' name='value'>
Add name attribute.
HTML
for i=1,13 do print(i) end
for i=1,13 do print(i) end
Correct.
Lua
my @arr = (79,8,27);
my @arr = (79,8,27);
Correct.
Perl
int foo = 'output';
String foo = 'output';
Type mismatch.
Dart
let temp = 69; temp += 1;
let mut temp = 69; temp += 1;
Need mut to modify.
Rust
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
33y = 10
y33 = 10
Variable cannot start with digit.
Python
if foo > 49 puts 'message'
if foo > 49 puts 'message' end
Add 'end'.
Ruby
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
arr[8]
if (arr.indices.contains(8)) arr[8]
Check index.
Kotlin
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
JOIN orders ON users.id = orders.id
JOIN orders ON users.id = orders.id
Correct.
SQL
if bar > 34 print('world')
if bar > 34: print('world')
Colon missing after if.
Python
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
if (c = 18) {{}}
if (c == 18) {{}}
Use ==.
Java
data(70)
if length(data) >= 70, data(70), end
Check length.
MATLAB
cin >> y;
int y; cin >> y;
Declare variable.
C++
values.forEach(function(item) {{ console.log(item); }})
values.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
render
render()
Add parentheses.
Kotlin
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
'result' + 25
'result' + 25.to_s
Convert int.
Ruby
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
def baz(a): return a + 1
def baz(a): return a + 1
Correct.
Python
let count = 63; let count = 5;
let count = 63; count = 5;
Duplicate declaration.
JavaScript
if (val = 16)
if (val == 16)
Use ==.
C++
def foo(): print('world')
def foo(): print('world')
Indent function body.
Python
disp('output')
disp('output')
Correct.
MATLAB
[52, 40, 22
[52, 40, 22]
Close bracket.
Python
assert y > 30
assert y > 30
Correct.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
function process() {{ echo 'test'; }}
function process() {{ echo 'test'; }}
Correct.
PHP
print 'hello'
print('hello')
Parentheses for function call.
Lua
if z = 21:
if z == 21:
Use == for comparison.
Python
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if [ $z = 64 ]; then
if [ "$z" = 64 ]; then
Quote variable.
Shell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
print 'info'
print 'info';
Add semicolon.
Perl
let s1 = String::from("data"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
var x = 37;
var x = 37;
Correct.
Dart
local c = 66
local c = 66
Correct.
Lua
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
index = 73
index=73
No spaces.
Shell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
baz
baz()
Add parentheses.
Swift
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
'value' + 72
'value' + str(72)
Can't add int to string.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
val result = 30; result = 20
var result = 30; result = 20
Use var for reassignment.
Scala
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
if (temp = 5) {}
if (temp == 5) {}
Use ==.
Dart
{{'status':'hello'}}
{{"status":"hello"}}
Use double quotes.
JSON
{{"status":"hello",}}
{{"status":"hello"}}
Remove trailing comma.
JSON
name: info status: hello,
name: info status: hello
Remove comma.
YAML
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
SELECT * FROM products WHRE status=54;
SELECT * FROM products WHERE status=54;
Fix WHERE.
SQL
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
class Item def method end end
class Item def method end end
Correct.
Ruby
var count int = 'data'
var count string = 'data'
Type mismatch.
Go
x > 99 & z < 13
x > 99 and z < 13
Use 'and' not '&'.
Python
INSERT INTO users VALUES ('info',54)
INSERT INTO users (age, status) VALUES ('info',54);
Specify columns.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
h1 {{ font-size:89px color:#333; }}
h1 {{ font-size:89px; color:#333; }}
Add semicolon.
CSS
if (a = 97)
if (a == 97)
Use ==.
R
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:68}};
Add missing property.
TypeScript
function compute(): void {{ return 70; }}
function compute(): number {{ return 70; }}
Return type mismatch.
TypeScript
yield y
yield y
Correct yield.
Python
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
if z = 90:
if z == 90:
Use == for comparison.
Python
WHERE status = '92'
WHERE status = 92
Don't quote integer.
SQL
var x int
var x int
Correct.
Go
if [ $foo = 62 ]; then
if [ "$foo" = 62 ]; then
Quote variable.
Shell
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
baz
baz()
Add parentheses.
Swift
class Order {{ int c; }} obj.c=5;
class Order {{ public int c; }} obj.c=5;
Make field public.
Java
[18, 19, 49
[18, 19, 49]
Close bracket.
Ruby