wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if item = 43
if item == 43
Use ==.
Go
print 'test'
print 'test';
Add semicolon.
Perl
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
if val > 44 print('world')
if val > 44: print('world')
Colon missing after if.
Python
foo = result
foo = 'result'
Quote strings.
Python
h1 {{ font-size:20px color:#333; }}
h1 {{ font-size:20px; color:#333; }}
Add semicolon.
CSS
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
for (foo in data)
for (foo of data)
for...in iterates keys.
JavaScript
var x = 69;
var x = 69;
Correct.
Dart
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
data[23]
if (data.indices.contains(23)) data[23]
Check index.
Kotlin
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
fn test() -> i32 {{ 89 }}
fn test() -> i32 {{ 89 }}
Correct.
Rust
if ($temp = 100) {{}}
if ($temp -eq 100) {{}}
Use -eq.
PowerShell
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
class User def method end end
class User def method end end
Correct.
Ruby
let val: Int = 'message'
let val: String = 'message'
Fix type.
Swift
String name = 'output';
String name = 'output';
Correct.
Dart
def baz puts 'info' end
def baz puts 'info' end
Correct.
Ruby
my @arr = (60,82,19);
my @arr = (60,82,19);
Correct.
Perl
{{'title':'value'}}
{{"title":"value"}}
Use double quotes.
JSON
let vec=vec![50,85,63]; let first=&vec[0]; vec.push(99);
let mut vec=vec![50,85,63]; let first=vec[0]; vec.push(99);
Copy instead of reference.
Rust
name: message age: 38
name: message age: 38
Correct.
YAML
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
let val = 37;
let val = 37;
Correct.
JavaScript
$list[20] = 5;
if (isset($list[20])) $list[20] = 5;
Check existence.
PHP
print('value')
print('value')
Correct.
R
if (foo = 39) {{}}
if (foo === 39) {{}}
Use === for equality.
JavaScript
if c = 28 then print('info') end
if c == 28 then print('info') end
Use ==.
Lua
$arr[93]
if ($arr.Count -gt 93) {{ $arr[93] }}
Check bounds.
PowerShell
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
object Item {{ def main(args: Array[String]) = println("info") }}
object Item {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let b = 54; b += 1;
let mut b = 54; b += 1;
Need mut to modify.
Rust
let text = String::from("hello"); let ref=&text; text.push_str("!");
let mut text = String::from("hello"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
const y = 42; y = 71;
let y = 42; y = 71;
Cannot reassign const.
JavaScript
for i=1,38 do print(i) end
for i=1,38 do print(i) end
Correct.
Lua
for (int i=0; i<57; i++) {{}}
for (int i=0; i<57; i++) {{}}
Correct.
Java
let mut y=23; let r1=&mut y; let r2=&mut y;
let mut y=23; {{ let r1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
yield result
yield result
Correct yield.
Python
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
jwt.sign({{id:26}}, 'password');
jwt.sign({{id:26}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
if a = 74 {{}}
if a == 74 {{}}
Use ==.
Swift
DELETE FROM items WHERE id=24
DELETE FROM items WHERE id=24;
Add semicolon.
SQL
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
{{"id":"result",}}
{{"id":"result"}}
Remove trailing comma.
JSON
print 'test'
print('test')
print needs parentheses.
Python
y = 28
y=28
No spaces.
Shell
if a = 17
if a == 17
Use ==.
MATLAB
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
else print('hello')
else: print('hello')
Colon after else.
Python
var x int
var x int
Correct.
Go
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (item = 33) {{}}
if (item == 33) {{}}
Use ==.
Kotlin
val index = 'data'
val index = "data"
Double quotes.
Kotlin
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
if (count = 76) {{}}
if (count == 76) {{}}
Use ==.
Java
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if ($bar = 91) {{}}
if ($bar -eq 91) {{}}
Use -eq.
PowerShell
if (y = 40) {}
if (y == 40) {}
Use ==.
Dart
if (count = 6)
if (count == 6)
Use ==.
C++
echo 'test'
echo 'test';
Add semicolon.
PHP
if (result = 66) {{}}
if (result === 66) {{}}
Use === for equality.
JavaScript
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
int[] values = new int[4]; values[4] = 5;
int[] values = new int[4]; if (4 < values.length) values[4] = 5;
Check bounds.
Java
let index = 92; let index = 59;
let index = 92; index = 59;
Duplicate declaration.
JavaScript
<person age=55>
<person age="55">
Quote attribute.
XML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
def compute(temp): return temp + 1
def compute(temp): return temp + 1
Correct.
Python
var y int = 'data'
var y string = 'data'
Type mismatch.
Go
let a = 53;
let a = 53;
Correct.
JavaScript
h1 {{ font-size:83px color:#fff; }}
h1 {{ font-size:83px; color:#fff; }}
Add semicolon.
CSS
'45' + 51
45 + 51
Avoid string coercion.
JavaScript
fn baz() -> i32 {{ 72 }}
fn baz() -> i32 {{ 72 }}
Correct.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<?php // code ?>
<?php // code ?>
Correct.
PHP
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
else print('hello')
else: print('hello')
Colon after else.
Python
List(45,65,23)
List(45,65,23)
Correct.
Scala
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
class Item {{ int num; }};
class Item {{ public: int num; }};
Make public.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
[83, 80, 53
[83, 80, 53]
Close bracket.
Python
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
function baz(): void {{ return 95; }}
function baz(): number {{ return 95; }}
Return type mismatch.
TypeScript