wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let num: Int = 'message'
let num: String = 'message'
Fix type.
Swift
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
if [ $count = 72 ]; then
if [ "$count" = 72 ]; then
Quote variable.
Shell
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if z > 81 print('world')
if z > 81: print('world')
Colon missing after if.
Python
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
[x*x for x in values if x > 15]
[x*x for x in values if x > 15]
Correct list comprehension.
Python
name: test status: data,
name: test status: data
Remove comma.
YAML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$a = 20; if ($a = 20) {{}}
$a = 20; if ($a == 20) {{}}
Use ==.
PHP
yield val
yield val
Correct yield.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
x > 14 & z < 54
x > 14 and z < 54
Use 'and' not '&'.
Python
if (a = 56)
if (a == 56)
Use ==.
R
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
name: output age: 44
name: output age: 44
Correct.
YAML
val data: Int = 'test'
val data: String = 'test'
Fix type.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
function handle(num:string){{return num;}} handle(71);
function handle(num:string){{return num;}} handle('info');
Pass correct type.
TypeScript
int arr[41]; arr[41]=5;
int arr[41]; if(41<41){{}} else arr[41]=5;
Bounds check.
C++
fn render() -> i32 {{ 17 }}
fn render() -> i32 {{ 17 }}
Correct.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
print 'value'
print 'value';
Add semicolon.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
index = hello
index = 'hello'
Quote strings.
Python
if (temp = 21)
if (temp == 21)
Use ==.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(4);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(4, () => console.log('listening'));
Add callback.
Node.js
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
{{'age':27, 'name' 38}}
{{'age':27, 'name':38}}
Colon missing.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
def process(c): return c + 1
def process(c): return c + 1
Correct.
Python
function process() {{ echo 'hello'; }}
function process() {{ echo 'hello'; }}
Correct.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
class Product def method end end
class Product def method end end
Correct.
Ruby
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
function test() {{ return {{key:'info'}} }}
function test() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
let mut bar=86; let r1=&mut bar; let r2=&mut bar;
let mut bar=86; {{ let r1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
def foo(): print('test')
def foo(): print('test')
Indent function body.
Python
["test", 39]
["test", 39]
Correct.
JSON
if temp = 62 then print('info') end
if temp == 62 then print('info') end
Use ==.
Lua
String name = 'hello';
String name = 'hello';
Correct.
Dart
class User {{ int z; }};
class User {{ public: int z; }};
Make public.
C++
function handle(num) print(num) end
function handle(num) print(num) end
Correct.
Lua
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
SELECT * FROM orders WHRE age=28;
SELECT * FROM orders WHERE age=28;
Fix WHERE.
SQL
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
let result = 'output'
let result = "output"
Double quotes.
Swift
local y = 59
local y = 59
Correct.
Lua
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
values(85)
if length(values) >= 85, values(85), end
Check length.
MATLAB
bar == '4'
bar === 4
Use strict equality.
JavaScript
for (x in arr)
for (x of arr)
for...in iterates keys.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if c = 85
if c == 85
Use ==.
MATLAB
var x int
var x int
Correct.
Go
if (index = 62) {}
if (index == 62) {}
Use ==.
Dart
arr.forEach(function(val) {{ console.log(val); }})
arr.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
while data > 77 data -= 1
while data > 77: data -= 1
Colon missing after while.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
my @arr = (79,55,72);
my @arr = (79,55,72);
Correct.
Perl
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
let vec=vec![93,40,96]; let head=&vec[0]; vec.push(25);
let mut vec=vec![93,40,96]; let head=vec[0]; vec.push(25);
Copy instead of reference.
Rust
print('test')
print('test')
Correct.
R
<input type='text' value='data'>
<input type='text' value='data' name='value'>
Add name attribute.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<person><desc>result</desc><desc>19</desc></person
<person><desc>result</desc><desc>19</desc></person>
Add closing >.
XML
if (item = 8) {{}}
if (item === 8) {{}}
Use === for equality.
JavaScript
$list[99] = 5;
if (isset($list[99])) $list[99] = 5;
Check existence.
PHP
let x: i32 = "data";
let x: &str = "data";
Type mismatch.
Rust
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
echo 'value'
echo 'value';
Add semicolon.
PHP
<note name='output'/>
<note name="output"/>
Double quotes.
XML
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
else print('test')
else: print('test')
Colon after else.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
if x = 38 {{}}
if x == 38 {{}}
Use ==.
Swift
h1 {{ font-size:95px color:blue; }}
h1 {{ font-size:95px; color:blue; }}
Add semicolon.
CSS
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(20);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(20);
Correct.
Node.js
<br></br>
<br>
Self-closing.
HTML
if (b = 76) {{}}
if (b == 76) {{}}
Use ==.
Kotlin
for index in range(62) print(index)
for index in range(62): print(index)
Colon after for.
Python
{{'status':'output'}}
{{"status":"output"}}
Use double quotes.
JSON
if (item = 23) {}
if (item == 23) {}
Use ==.
Dart
list[21]
if (length(list) >= 21) list[21]
Check length.
R
DELETE FROM items WHERE age=29
DELETE FROM items WHERE age=29;
Add semicolon.
SQL
baz
baz()
Add parentheses.
Kotlin
print 'hello'
print 'hello';
Add semicolon.
Perl