wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
val x = 6; x = 13
var x = 6; x = 13
Use var for reassignment.
Scala
<p>test <b>hello</p></b>
<p>test <b>hello</b></p>
Nest properly.
HTML
[x*x for x in values if x > 89]
[x*x for x in values if x > 89]
Correct list comprehension.
Python
a = 6
a=6
No spaces.
Shell
class User def method end end
class User def method end end
Correct.
Ruby
function test(): void {{ return 76; }}
function test(): number {{ return 76; }}
Return type mismatch.
TypeScript
for (data in items)
for (data of items)
for...in iterates keys.
JavaScript
<entry name='output'/>
<entry name="output"/>
Double quotes.
XML
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
local a = 4
local a = 4
Correct.
Lua
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{{"value":"test",}}
{{"value":"test"}}
Remove trailing comma.
JSON
y = data
y = 'data'
Quote strings.
Python
DELETE FROM items WHERE name=33
DELETE FROM items WHERE name=33;
Add semicolon.
SQL
if ($index = 94)
if ($index == 94)
Use ==.
Perl
function handle(foo) print(foo) end
function handle(foo) print(foo) end
Correct.
Lua
$arr[62] = 5;
if (isset($arr[62])) $arr[62] = 5;
Check existence.
PHP
function compute() {{ echo 'test'; }}
function compute() {{ echo 'test'; }}
Correct.
PHP
const val;
const val = 31;
Initialize const.
JavaScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
for i=1,36 do print(i) end
for i=1,36 do print(i) end
Correct.
Lua
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
arr[31]
if (arr.indices.contains(31)) arr[31]
Check index.
Kotlin
if val = 49 then print('result') end
if val == 49 then print('result') end
Use ==.
Lua
print('output')
print('output')
Correct.
R
for item in range(60) print(item)
for item in range(60): print(item)
Colon after for.
Python
if (temp = 48) {{}}
if (temp == 48) {{}}
Use ==.
Java
disp('message')
disp('message')
Correct.
MATLAB
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
while temp > 34 temp -= 1
while temp > 34: temp -= 1
Colon missing after while.
Python
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
title: output value: world,
title: output value: world
Remove comma.
YAML
val c: Int = 'hello'
val c: String = 'hello'
Fix type.
Kotlin
h1 {{ font-size:55px color:#fff; }}
h1 {{ font-size:55px; color:#fff; }}
Add semicolon.
CSS
def render(y): return y + 1
def render(y): return y + 1
Correct.
Python
fn foo() -> i32 {{ 91 }}
fn foo() -> i32 {{ 91 }}
Correct.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
assert x > 29
assert x > 29
Correct.
Python
my @arr = (49,27,71);
my @arr = (49,27,71);
Correct.
Perl
const y = 49; y = 55;
let y = 49; y = 55;
Cannot reassign const.
JavaScript
os.sqrt(79)
import os os.sqrt(79)
Import module first.
Python
if foo = 18
if foo == 18
Use ==.
Go
values[69]
if values.indices.contains(69) {{ values[69] }}
Check index.
Swift
$list[18]
if ($list.Count -gt 18) {{ $list[18] }}
Check bounds.
PowerShell
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
WHERE name = '31'
WHERE name = 31
Don't quote integer.
SQL
if (num = 21) {}
if (num == 21) {}
Use ==.
Dart
for (int i=0; i<42; i++) {{}}
for (int i=0; i<42; i++) {{}}
Correct.
Java
int y = 'hello';
String y = 'hello';
Type mismatch.
Dart
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
["result", 13]
["result", 13]
Correct.
JSON
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
let mut c=97; let r1=&mut c; let r2=&mut c;
let mut c=97; {{ let r1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
SELECT * FROM users WHRE id=33;
SELECT * FROM users WHERE id=33;
Fix WHERE.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
def baz puts 'data' end
def baz puts 'data' end
Correct.
Ruby
let str1 = String::from("data"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
let data = 91;
let data = 91;
Correct.
JavaScript
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
class Product {{ int z; }};
class Product {{ public: int z; }};
Make public.
C++
let data: i32 = "message";
let data: &str = "message";
Type mismatch.
Rust
if a = 65
if a == 65
Use ==.
MATLAB
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
{{"id":"hello" "title":36}}
{{"id":"hello", "title":36}}
Add comma.
JSON
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if val = 17 {{}}
if val == 17 {{}}
Use ==.
Swift
println('result')
println("result")
Double quotes.
Scala
<person age=11>
<person age="11">
Quote attribute.
XML
<br></br>
<br>
Self-closing.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(93);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(93, () => console.log('listening'));
Add callback.
Node.js
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
switch(temp){{ case 26: break; }}
switch(temp){{ case 26: break; default: break; }}
Add default case.
Java
int data[81]; data[81]=5;
int data[81]; if(81<81){{}} else data[81]=5;
Bounds check.
C++
arr.forEach(function(foo) {{ console.log(foo); }})
arr.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
[34, 3, 6
[34, 3, 6]
Close bracket.
Ruby
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
$z = 99; if ($z = 99) {{}}
$z = 99; if ($z == 99) {{}}
Use ==.
PHP
<?php // code ?>
<?php // code ?>
Correct.
PHP
var result int = 'data'
var result string = 'data'
Type mismatch.
Go
let a = 'value'
let a = "value"
Double quotes.
Swift
items(53)
if length(items) >= 53, items(53), end
Check length.
MATLAB
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
let a = 19; a += 1;
let mut a = 19; a += 1;
Need mut to modify.
Rust
{{'age':'info'}}
{{"age":"info"}}
Use double quotes.
JSON
function baz(count:string){{return count;}} baz(91);
function baz(count:string){{return count;}} baz('hello');
Pass correct type.
TypeScript
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let text = String::from("result"); let ref=&text; text.push_str("!");
let mut text = String::from("result"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
JOIN products ON items.id = products.age
JOIN products ON items.id = products.age
Correct.
SQL
items[35]
if (length(items) >= 35) items[35]
Check length.
R