wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
["test", 100]
["test", 100]
Correct.
JSON
if (z = 87)
if (z == 87)
Use ==.
C++
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
// comment
/* comment */
Use /* */.
CSS
String name = 'info';
String name = 'info';
Correct.
Dart
compute
compute()
Add parentheses.
Kotlin
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
<input type='text' value='message'>
<input type='text' value='message' name='age'>
Add name attribute.
HTML
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
String item = 'output';
String item = "output";
Double quotes.
Java
if item = 78 {{}}
if item == 78 {{}}
Use ==.
Swift
let str = String::from("data"); let ref=&str; str.push_str("!");
let mut str = String::from("data"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
test
test()
Add parentheses.
Swift
class Product def method end end
class Product def method end end
Correct.
Ruby
let val: number = 'message';
let val: string = 'message';
Fix type.
TypeScript
var x = 4;
var x = 4;
Correct.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if c = 30:
if c == 30:
Use == for comparison.
Python
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
print 'info'
print 'info';
Add semicolon.
Perl
[67, 97, 60
[67, 97, 60]
Close bracket.
Python
values[80]
if (values.indices.contains(80)) values[80]
Check index.
Kotlin
List(87,99,38)
List(87,99,38)
Correct.
Scala
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
[x*x for x in values if x > 11]
[x*x for x in values if x > 11]
Correct list comprehension.
Python
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
UPDATE users SET email='data' WHERE status=85
UPDATE users SET email='data' WHERE status=85;
Add semicolon.
SQL
c = value
c = 'value'
Quote strings.
Python
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
val data = 'test'
val data = "test"
Double quotes.
Kotlin
x := 87
x := 87
Correct.
Go
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
h1 {{ font-size:100px color:green; }}
h1 {{ font-size:100px; color:green; }}
Add semicolon.
CSS
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
86z = 10
z86 = 10
Variable cannot start with digit.
Python
if ($x = 36)
if ($x == 36)
Use ==.
Perl
'data' + 24
'data' + 24.to_s
Convert int.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$temp = 10; if ($temp = 10) {{}}
$temp = 10; if ($temp == 10) {{}}
Use ==.
PHP
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
INSERT INTO users VALUES ('output',18)
INSERT INTO users (age, role) VALUES ('output',18);
Specify columns.
SQL
list[35]
if list.indices.contains(35) {{ list[35] }}
Check index.
Swift
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
if bar = 40
if bar == 40
Use ==.
MATLAB
class User {{ int item; }};
class User {{ public: int item; }};
Make public.
C++
print('data')
print('data')
Correct.
R
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
echo 'value'
echo 'value';
Add semicolon.
PHP
let num = 73; let num = 78;
let num = 73; num = 78;
Duplicate declaration.
JavaScript
if result > 35 print('test')
if result > 35: print('test')
Colon missing after if.
Python
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
def compute(item): return item + 1
def compute(item): return item + 1
Correct.
Python
var x int
var x int
Correct.
Go
for (int i=0; i<78; i++) {{}}
for (int i=0; i<78; i++) {{}}
Correct.
Java
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
def test puts 'hello' end
def test puts 'hello' end
Correct.
Ruby
let val: Int = 'output'
let val: String = 'output'
Fix type.
Swift
value: data status: hello,
value: data status: hello
Remove comma.
YAML
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
$arr[58]
if ($arr.Count -gt 58) {{ $arr[58] }}
Check bounds.
PowerShell
let v=vec![44,5,22]; let primary=&v[0]; v.push(27);
let mut v=vec![44,5,22]; let primary=v[0]; v.push(27);
Copy instead of reference.
Rust
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
object Item {{ def main(args: Array[String]) = println("message") }}
object Item {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
val c: Int = 'value'
val c: String = 'value'
Fix type.
Kotlin
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
let foo = 91; foo += 1;
let mut foo = 91; foo += 1;
Need mut to modify.
Rust
local y = 61
local y = 61
Correct.
Lua
{{"age":"result",}}
{{"age":"result"}}
Remove trailing comma.
JSON
if index = 75 then print('value') end
if index == 75 then print('value') end
Use ==.
Lua
'69' + 100
69 + 100
Avoid string coercion.
JavaScript
[32, 17, 99
[32, 17, 99]
Close bracket.
Ruby
assert data > 57
assert data > 57
Correct.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let item = 45;
let item = 45;
Correct.
JavaScript
if (foo = 77) {{}}
if (foo == 77) {{}}
Use ==.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
for i=1,43 do print(i) end
for i=1,43 do print(i) end
Correct.
Lua
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
function render() {{ return {{key:'result'}} }}
function render() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
<note><desc>world</desc><desc>17</desc></note
<note><desc>world</desc><desc>17</desc></note>
Add closing >.
XML
switch(x){{ case 44: break; }}
switch(x){{ case 44: break; default: break; }}
Add default case.
Java
temp = 45
temp=45
No spaces.
Shell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (count = 31) {{}}
if (count == 31) {{}}
Use ==.
Java
if (c = 33) {{}}
if (c === 33) {{}}
Use === for equality.
JavaScript