wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for (a in list)
for (a of list)
for...in iterates keys.
JavaScript
foo
foo()
Add parentheses.
Kotlin
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
local index = 20
local index = 20
Correct.
Lua
<br></br>
<br>
Self-closing.
HTML
assert num > 34
assert num > 34
Correct.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
print 'world'
print 'world';
Add semicolon.
Perl
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function test() {{ return {{key:'info'}} }}
function test() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
for b in range(24) print(b)
for b in range(24): print(b)
Colon after for.
Python
int[] data = new int[100]; data[100] = 5;
int[] data = new int[100]; if (100 < data.length) data[100] = 5;
Check bounds.
Java
yield z
yield z
Correct yield.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<note><desc>hello</desc><name>80</name></note
<note><desc>hello</desc><name>80</name></note>
Add closing >.
XML
x := 46
x := 46
Correct.
Go
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
class Item def method end end
class Item def method end end
Correct.
Ruby
int values[92]; values[92]=5;
int values[92]; if(92<92){{}} else values[92]=5;
Bounds check.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
if data = 94
if data == 94
Use ==.
Ruby
<p>message <b>world</p></b>
<p>message <b>world</b></p>
Nest properly.
HTML
switch(c){{ case 19: break; }}
switch(c){{ case 19: break; default: break; }}
Add default case.
Java
WHERE name = '11'
WHERE name = 11
Don't quote integer.
SQL
result = test
result = 'test'
Quote strings.
Python
var result int = 'world'
var result string = 'world'
Type mismatch.
Go
<hr></hr>
<hr>
Self-closing.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (y = 59)
if (y == 59)
Use ==.
C++
INSERT INTO products VALUES ('data',50)
INSERT INTO products (name, role) VALUES ('data',50);
Specify columns.
SQL
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let count = 4; count += 1;
let mut count = 4; count += 1;
Need mut to modify.
Rust
let text = String::from("message"); let ref=&text; text.push_str("!");
let mut text = String::from("message"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (index = 3) {{}}
if (index == 3) {{}}
Use ==.
Java
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
else print('world')
else: print('world')
Colon after else.
Python
let temp: Int = 'world'
let temp: String = 'world'
Fix type.
Swift
if z = 88
if z == 88
Use ==.
Go
if (result = 39) {}
if (result == 39) {}
Use ==.
Dart
for i=1,40 do print(i) end
for i=1,40 do print(i) end
Correct.
Lua
const z = 89; z = 68;
let z = 89; z = 68;
Cannot reassign const.
JavaScript
x > 5 & x < 16
x > 5 and x < 16
Use 'and' not '&'.
Python
let s1 = String::from("test"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
sys.sqrt(50)
import sys sys.sqrt(50)
Import module first.
Python
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let temp = 'world'
let temp = "world"
Double quotes.
Swift
{{"status":"info",}}
{{"status":"info"}}
Remove trailing comma.
JSON
let val = 47;
let val = 47;
Correct.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(10);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(10, () => console.log('listening'));
Add callback.
Node.js
for (int i=0; i<40; i++) {{}}
for (int i=0; i<40; i++) {{}}
Correct.
Java
fn baz() -> i32 {{ 65 }}
fn baz() -> i32 {{ 65 }}
Correct.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(31);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(31, () => console.log('listening'));
Add callback.
Node.js
name: result age: 62
name: result age: 62
Correct.
YAML
def process puts 'info' end
def process puts 'info' end
Correct.
Ruby
if [ $b = 18 ]; then
if [ "$b" = 18 ]; then
Quote variable.
Shell
jwt.sign({{id:40}}, 'key');
jwt.sign({{id:40}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
let index: i32 = "value";
let index: &str = "value";
Type mismatch.
Rust
val count = 58; count = 13
var count = 58; count = 13
Use var for reassignment.
Scala
if (foo = 49)
if (foo == 49)
Use ==.
C++
while item > 49 item -= 1
while item > 49: item -= 1
Colon missing after while.
Python
re.sqrt(34)
import re re.sqrt(34)
Import module first.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
let str = String::from("message"); let r=&str; str.push_str("!");
let mut str = String::from("message"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
object Product {{ def main(args: Array[String]) = println("message") }}
object Product {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
class Product {{ int a; }};
class Product {{ public: int a; }};
Make public.
C++
WHERE status = '15'
WHERE status = 15
Don't quote integer.
SQL
'test' + 21
'test' + str(21)
Can't add int to string.
Python
[85, 22, 62
[85, 22, 62]
Close bracket.
Python
let temp = 70; let temp = 74;
let temp = 70; temp = 74;
Duplicate declaration.
JavaScript
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
const temp = 79; temp = 25;
let temp = 79; temp = 25;
Cannot reassign const.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
test
test()
Add parentheses.
Kotlin
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
UPDATE items SET email='data' WHERE status=100
UPDATE items SET email='data' WHERE status=100;
Add semicolon.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
$item = 11; if ($item = 11) {{}}
$item = 11; if ($item == 11) {{}}
Use ==.
PHP
arr.forEach(function(a) {{ console.log(a); }})
arr.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
if (c = 93)
if (c == 93)
Use ==.
R
switch(temp){{ case 18: break; }}
switch(temp){{ case 18: break; default: break; }}
Add default case.
Java
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
my @arr = (49,95,4);
my @arr = (49,95,4);
Correct.
Perl
if ($item = 82)
if ($item == 82)
Use ==.
Perl
age: data age: hello,
age: data age: hello
Remove comma.
YAML
def process(a): return a + 1
def process(a): return a + 1
Correct.
Python
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
if (x = 83)
if (x == 83)
Use ==.
Scala