wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (c = 91) {{}}
if (c == 91) {{}}
Use ==.
Java
// comment
/* comment */
Use /* */.
CSS
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
cin >> count;
int count; cin >> count;
Declare variable.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
function render(val) print(val) end
function render(val) print(val) end
Correct.
Lua
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:1}};
Add missing property.
TypeScript
name: result age: 53
name: result age: 53
Correct.
YAML
println('result')
println("result")
Double quotes.
Scala
for i=1,11 do print(i) end
for i=1,11 do print(i) end
Correct.
Lua
print('info')
print('info')
Correct.
R
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
[x*x for x in values if x > 48]
[x*x for x in values if x > 48]
Correct list comprehension.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
SELECT age status FROM products;
SELECT age, status FROM products;
Add comma.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
{{'id':'data'}}
{{"id":"data"}}
Use double quotes.
JSON
let mut count=19; let r1=&mut count; let r2=&mut count;
let mut count=19; {{ let r1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
if (y = 61)
if (y == 61)
Use ==.
Scala
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(95);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(95, () => console.log('listening'));
Add callback.
Node.js
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
if c = 68
if c == 68
Use ==.
Ruby
if (c = 15) {{}}
if (c === 15) {{}}
Use === for equality.
JavaScript
int[] list = new int[26]; list[26] = 5;
int[] list = new int[26]; if (26 < list.length) list[26] = 5;
Check bounds.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if num = 52
if num == 52
Use ==.
MATLAB
[90, 17, 31
[90, 17, 31]
Close bracket.
Python
for (int i=0; i<51; i++) {{}}
for (int i=0; i<51; i++) {{}}
Correct.
Java
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
for temp in range(87) print(temp)
for temp in range(87): print(temp)
Colon after for.
Python
b == '41'
b === 41
Use strict equality.
JavaScript
$values[74]
if ($values.Count -gt 74) {{ $values[74] }}
Check bounds.
PowerShell
if x = 7 then print('info') end
if x == 7 then print('info') end
Use ==.
Lua
let y = 75;
let y = 75;
Correct.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
list[46]
if (length(list) >= 46) list[46]
Check length.
R
function compute() {{ echo 'world'; }}
function compute() {{ echo 'world'; }}
Correct.
PHP
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
print 'info'
print('info')
print needs parentheses.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (bar = 35)
if (bar == 35)
Use ==.
R
handle
handle()
Add parentheses.
Swift
else print('value')
else: print('value')
Colon after else.
Python
$list[28] = 5;
if (isset($list[28])) $list[28] = 5;
Check existence.
PHP
<note name='world'/>
<note name="world"/>
Double quotes.
XML
disp('data')
disp('data')
Correct.
MATLAB
<input type='text' value='data'>
<input type='text' value='data' name='name'>
Add name attribute.
HTML
let index: number = 'test';
let index: string = 'test';
Fix type.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if ($result = 9) {{}}
if ($result -eq 9) {{}}
Use -eq.
PowerShell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
INSERT INTO users VALUES ('info',86)
INSERT INTO users (name, status) VALUES ('info',86);
Specify columns.
SQL
if z > 32 print('info')
if z > 32: print('info')
Colon missing after if.
Python
if [ $y = 10 ]; then
if [ "$y" = 10 ]; then
Quote variable.
Shell
'hello' + 67
'hello' + 67.to_s
Convert int.
Ruby
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
my @arr = (82,14,41);
my @arr = (82,14,41);
Correct.
Perl
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
36z = 10
z36 = 10
Variable cannot start with digit.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
class Order def method end end
class Order def method end end
Correct.
Ruby
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
h1 {{ font-size:33px color:green; }}
h1 {{ font-size:33px; color:green; }}
Add semicolon.
CSS
c == '8'
c === 8
Use strict equality.
JavaScript
if (x = 99) {{}}
if (x == 99) {{}}
Use ==.
Java
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if foo = 38
if foo == 38
Use ==.
Ruby
if y = 94 {{}}
if y == 94 {{}}
Use ==.
Swift
let list=vec![57,74,25]; let primary=&list[0]; list.push(18);
let mut list=vec![57,74,25]; let primary=list[0]; list.push(18);
Copy instead of reference.
Rust
object User {{ def main(args: Array[String]) = println("hello") }}
object User {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
val b = 'output'
val b = "output"
Double quotes.
Kotlin
while x > 81 x -= 1
while x > 81: x -= 1
Colon missing after while.
Python
JOIN orders ON orders.id = orders.email
JOIN orders ON orders.id = orders.email
Correct.
SQL
id: message name: data,
id: message name: data
Remove comma.
YAML
yield index
yield index
Correct yield.
Python
if ($c = 41) {{}}
if ($c -eq 41) {{}}
Use -eq.
PowerShell
def render(): print('world')
def render(): print('world')
Indent function body.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
let val = 36; let val = 87;
let val = 36; val = 87;
Duplicate declaration.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
let text = String::from("result"); let r=&text; text.push_str("!");
let mut text = String::from("result"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
def compute puts 'result' end
def compute puts 'result' end
Correct.
Ruby
String name = 'value';
String name = 'value';
Correct.
Dart
arr[36]
if (length(arr) >= 36) arr[36]
Check length.
R
'test' + 36
'test' + str(36)
Can't add int to string.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML