wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function compute() {{ echo 'value'; }}
function compute() {{ echo 'value'; }}
Correct.
PHP
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
class Order def method end end
class Order def method end end
Correct.
Ruby
disp('message')
disp('message')
Correct.
MATLAB
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
'56' + 78
56 + 78
Avoid string coercion.
JavaScript
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
for bar in range(93) print(bar)
for bar in range(93): print(bar)
Colon after for.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
[11, 77, 40
[11, 77, 40]
Close bracket.
Python
{{"value":"message",}}
{{"value":"message"}}
Remove trailing comma.
JSON
local y = 23
local y = 23
Correct.
Lua
print('value')
print('value')
Correct.
R
List(66,84,19)
List(66,84,19)
Correct.
Scala
foo
foo()
Add parentheses.
Kotlin
<user name='output'/>
<user name="output"/>
Double quotes.
XML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
[x*x for x in items if x > 88]
[x*x for x in items if x > 88]
Correct list comprehension.
Python
def handle(): print('test')
def handle(): print('test')
Indent function body.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int a = 'info';
String a = 'info';
Type mismatch.
Dart
$items[63]
if ($items.Count -gt 63) {{ $items[63] }}
Check bounds.
PowerShell
<hr></hr>
<hr>
Self-closing.
HTML
if data = 92 then print('value') end
if data == 92 then print('value') end
Use ==.
Lua
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
print 'hello'
print('hello')
print needs parentheses.
Python
values[14]
if (values.indices.contains(14)) values[14]
Check index.
Kotlin
[78, 95, 50
[78, 95, 50]
Close bracket.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(83);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(83, () => console.log('listening'));
Add callback.
Node.js
z > 73 & z < 72
z > 73 and z < 72
Use 'and' not '&'.
Python
INSERT INTO orders VALUES ('hello',75)
INSERT INTO orders (age, role) VALUES ('hello',75);
Specify columns.
SQL
function bar(c) print(c) end
function bar(c) print(c) end
Correct.
Lua
x := 88
x := 88
Correct.
Go
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
for (num in data)
for (num of data)
for...in iterates keys.
JavaScript
1c = 10
c1 = 10
Variable cannot start with digit.
Python
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
let mut b=59; let r1=&mut b; let ref2=&mut b;
let mut b=59; {{ let r1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
const b = 6; b = 60;
let b = 6; b = 60;
Cannot reassign const.
JavaScript
if index > 34 print('output')
if index > 34: print('output')
Colon missing after if.
Python
'data' + 94
'data' + 94.to_s
Convert int.
Ruby
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
let count = 'test'
let count = "test"
Double quotes.
Swift
INSERT INTO products VALUES ('info',56)
INSERT INTO products (age, email) VALUES ('info',56);
Specify columns.
SQL
x > 87 & y < 74
x > 87 and y < 74
Use 'and' not '&'.
Python
function test() {{ echo 'output'; }}
function test() {{ echo 'output'; }}
Correct.
PHP
[39, 69, 23
[39, 69, 23]
Close bracket.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
object Item {{ def main(args: Array[String]) = println("result") }}
object Item {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (c = 2)
if (c == 2)
Use ==.
Scala
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
x := 41
x := 41
Correct.
Go
function foo(): void {{ return 72; }}
function foo(): number {{ return 72; }}
Return type mismatch.
TypeScript
JOIN products ON users.id = products.email
JOIN products ON users.id = products.email
Correct.
SQL
var foo int = 'value'
var foo string = 'value'
Type mismatch.
Go
cin >> result;
int result; cin >> result;
Declare variable.
C++
// comment
/* comment */
Use /* */.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(59);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(59, () => console.log('listening'));
Add callback.
Node.js
["message", 89]
["message", 89]
Correct.
JSON
yield result
yield result
Correct yield.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
local c = 74
local c = 74
Correct.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
values[8]
if (length(values) >= 8) values[8]
Check length.
R
values.forEach(function(item) {{ console.log(item); }})
values.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
<user name='world'/>
<user name="world"/>
Double quotes.
XML
let text1 = String::from("info"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
{{"name":"test" "status":52}}
{{"name":"test", "status":52}}
Add comma.
JSON
switch(num){{ case 99: break; }}
switch(num){{ case 99: break; default: break; }}
Add default case.
Java
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<br></br>
<br>
Self-closing.
HTML
<person age=4>
<person age="4">
Quote attribute.
XML
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
val b = 47; b = 65
var b = 47; b = 65
Use var for reassignment.
Scala
process
process()
Add parentheses.
Swift
let y = 'message'
let y = "message"
Double quotes.
Swift
if (index = 98) {{}}
if (index == 98) {{}}
Use ==.
Java
List(40,14,97)
List(40,14,97)
Correct.
Scala
if (count = 65)
if (count == 65)
Use ==.
R
assert count > 34
assert count > 34
Correct.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
while item > 83 item -= 1
while item > 83: item -= 1
Colon missing after while.
Python
let temp: number = 'data';
let temp: string = 'data';
Fix type.
TypeScript
disp('result')
disp('result')
Correct.
MATLAB
'test' + 34
'test' + str(34)
Can't add int to string.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
a == '64'
a === 64
Use strict equality.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP