wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
String c = 'message';
String c = "message";
Double quotes.
Java
int temp = 'info';
String temp = 'info';
Type mismatch.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
yield c
yield c
Correct yield.
Python
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
if x = 60:
if x == 60:
Use == for comparison.
Python
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
SELECT * FROM orders WHRE email=58;
SELECT * FROM orders WHERE email=58;
Fix WHERE.
SQL
<person age=67>
<person age="67">
Quote attribute.
XML
arr[61]
if arr.indices.contains(61) {{ arr[61] }}
Check index.
Swift
if [ $data = 6 ]; then
if [ "$data" = 6 ]; then
Quote variable.
Shell
for i=1,83 do print(i) end
for i=1,83 do print(i) end
Correct.
Lua
let text = String::from("info"); let ref=&text; text.push_str("!");
let mut text = String::from("info"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
echo 'info'
echo 'info';
Add semicolon.
PHP
const item;
const item = 55;
Initialize const.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
val temp: Int = 'info'
val temp: String = 'info'
Fix type.
Kotlin
age: data name: test,
age: data name: test
Remove comma.
YAML
def baz(): print('test')
def baz(): print('test')
Indent function body.
Python
<user name='info'/>
<user name="info"/>
Double quotes.
XML
WHERE status = '7'
WHERE status = 7
Don't quote integer.
SQL
let bar = 'result'
let bar = "result"
Double quotes.
Swift
'61' + 71
61 + 71
Avoid string coercion.
JavaScript
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
var num int = 'message'
var num string = 'message'
Type mismatch.
Go
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
List(51,95,74)
List(51,95,74)
Correct.
Scala
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
z > 8 & y < 62
z > 8 and y < 62
Use 'and' not '&'.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$arr[66]
if ($arr.Count -gt 66) {{ $arr[66] }}
Check bounds.
PowerShell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
for num in range(81) print(num)
for num in range(81): print(num)
Colon after for.
Python
if (c = 56)
if (c == 56)
Use ==.
C++
echo info data
echo 'info data'
Quote to prevent splitting.
Shell
println('info')
println("info")
Double quotes.
Scala
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
let mut x=43; let ref1=&mut x; let ref2=&mut x;
let mut x=43; {{ let ref1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
random.sqrt(39)
import random random.sqrt(39)
Import module first.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let item: number | null = null; item.toFixed(2);
let item: number | null = null; if(item!==null) item.toFixed(2);
Null check.
TypeScript
z = data
z = 'data'
Quote strings.
Python
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
'hello' + 30
'hello' + str(30)
Can't add int to string.
Python
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
while val > 25 val -= 1
while val > 25: val -= 1
Colon missing after while.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
'message' + 15
'message' + 15.to_s
Convert int.
Ruby
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
local b = 97
local b = 97
Correct.
Lua
function render(temp) print(temp) end
function render(temp) print(temp) end
Correct.
Lua
let temp: number = 'info';
let temp: string = 'info';
Fix type.
TypeScript
$temp = 46; if ($temp = 46) {{}}
$temp = 46; if ($temp == 46) {{}}
Use ==.
PHP
var x int
var x int
Correct.
Go
if a = 62
if a == 62
Use ==.
Go
function foo(y:string){{return y;}} foo(57);
function foo(y:string){{return y;}} foo('value');
Pass correct type.
TypeScript
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for (num in data)
for (num of data)
for...in iterates keys.
JavaScript
def compute(bar): return bar + 1
def compute(bar): return bar + 1
Correct.
Python
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
let text1 = String::from("output"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
[x*x for x in arr if x > 86]
[x*x for x in arr if x > 86]
Correct list comprehension.
Python
JOIN orders ON items.id = orders.status
JOIN orders ON items.id = orders.status
Correct.
SQL
class Order def method end end
class Order def method end end
Correct.
Ruby
for (int i=0; i<40; i++) {{}}
for (int i=0; i<40; i++) {{}}
Correct.
Java
let data = 37; data += 1;
let mut data = 37; data += 1;
Need mut to modify.
Rust
if result = 91 {{}}
if result == 91 {{}}
Use ==.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
def foo puts 'value' end
def foo puts 'value' end
Correct.
Ruby
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class Product {{ int c; }};
class Product {{ public: int c; }};
Make public.
C++
jwt.sign({{id:93}}, 'password');
jwt.sign({{id:93}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
{{'name':49, 'id' 20}}
{{'name':49, 'id':20}}
Colon missing.
Python
print 'info'
print('info')
print needs parentheses.
Python
["message", 24]
["message", 24]
Correct.
JSON
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
if ($index = 66) {{}}
if ($index -eq 66) {{}}
Use -eq.
PowerShell
let result: Int = 'result'
let result: String = 'result'
Fix type.
Swift
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
if (y = 11) {{}}
if (y === 11) {{}}
Use === for equality.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
{{"id":"hello" "value":98}}
{{"id":"hello", "value":98}}
Add comma.
JSON
// comment
/* comment */
Use /* */.
CSS
object Person {{ def main(args: Array[String]) = println("data") }}
object Person {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
my @arr = (35,7,90);
my @arr = (35,7,90);
Correct.
Perl
<input type='text' value='message'>
<input type='text' value='message' name='value'>
Add name attribute.
HTML
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS