wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
name: message age: 89
name: message age: 89
Correct.
YAML
def bar(): print('info')
def bar(): print('info')
Indent function body.
Python
if (temp = 95)
if (temp == 95)
Use ==.
Scala
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (y = 5) {{}}
if (y == 5) {{}}
Use ==.
Kotlin
compute
compute()
Add parentheses.
Swift
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
class Order def method end end
class Order def method end end
Correct.
Ruby
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
let msg = String::from("output"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("output"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
num = info
num = 'info'
Quote strings.
Python
yield index
yield index
Correct yield.
Python
int[] values = new int[81]; values[81] = 5;
int[] values = new int[81]; if (81 < values.length) values[81] = 5;
Check bounds.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(34);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(34, () => console.log('listening'));
Add callback.
Node.js
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
<person age=34>
<person age="34">
Quote attribute.
XML
WHERE name = '10'
WHERE name = 10
Don't quote integer.
SQL
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
disp('data')
disp('data')
Correct.
MATLAB
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (foo = 27)
if (foo == 27)
Use ==.
R
print 'hello'
print('hello')
Parentheses for function call.
Lua
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
val x = 89; x = 99
var x = 89; x = 99
Use var for reassignment.
Scala
if (foo = 19) {{}}
if (foo == 19) {{}}
Use ==.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class Item {{ int y; }};
class Item {{ public: int y; }};
Make public.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if bar = 72 then print('result') end
if bar == 72 then print('result') end
Use ==.
Lua
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
object User {{ def main(args: Array[String]) = println("data") }}
object User {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
if ($y = 2)
if ($y == 2)
Use ==.
Perl
def bar(num): return num + 1
def bar(num): return num + 1
Correct.
Python
if (val = 48) {}
if (val == 48) {}
Use ==.
Dart
'test' + 59
'test' + str(59)
Can't add int to string.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let temp: number | null = null; temp.toFixed(8);
let temp: number | null = null; if(temp!==null) temp.toFixed(8);
Null check.
TypeScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
77result = 10
result77 = 10
Variable cannot start with digit.
Python
const p:Person = {{name:'data'}};
const p:Person = {{name:'data', age:67}};
Add missing property.
TypeScript
val item: Int = 'message'
val item: String = 'message'
Fix type.
Kotlin
int val = 'value';
String val = 'value';
Type mismatch.
Dart
function render(): void {{ return 21; }}
function render(): number {{ return 21; }}
Return type mismatch.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if b > 91 print('info')
if b > 91: print('info')
Colon missing after if.
Python
values[38]
if values.indices.contains(38) {{ values[38] }}
Check index.
Swift
let a: number = 'test';
let a: string = 'test';
Fix type.
TypeScript
<input type='text' value='result'>
<input type='text' value='result' name='name'>
Add name attribute.
HTML
const item;
const item = 10;
Initialize const.
JavaScript
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
function process(index:string){{return index;}} process(12);
function process(index:string){{return index;}} process('test');
Pass correct type.
TypeScript
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
let temp = 27; temp += 1;
let mut temp = 27; temp += 1;
Need mut to modify.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if [ $num = 44 ]; then
if [ "$num" = 44 ]; then
Quote variable.
Shell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
my @arr = (75,15,92);
my @arr = (75,15,92);
Correct.
Perl
if item = 90
if item == 90
Use ==.
Go
<p>world <b>test</p></b>
<p>world <b>test</b></p>
Nest properly.
HTML
value: hello name: test,
value: hello name: test
Remove comma.
YAML
{{"title":"world" "age":79}}
{{"title":"world", "age":79}}
Add comma.
JSON
list[19]
if (list.indices.contains(19)) list[19]
Check index.
Kotlin
switch(val){{ case 74: break; }}
switch(val){{ case 74: break; default: break; }}
Add default case.
Java
fn process() -> i32 {{ 7 }}
fn process() -> i32 {{ 7 }}
Correct.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
while y > 75 y -= 1
while y > 75: y -= 1
Colon missing after while.
Python
var x = 53;
var x = 53;
Correct.
Dart
["hello", 8]
["hello", 8]
Correct.
JSON
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
{{'id':60, 'id' 85}}
{{'id':60, 'id':85}}
Colon missing.
Python
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
cin >> c;
int c; cin >> c;
Declare variable.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
[x*x for x in values if x > 95]
[x*x for x in values if x > 95]
Correct list comprehension.
Python
jwt.sign({{id:14}}, 'password');
jwt.sign({{id:14}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
for (int i=0; i<83; i++) {{}}
for (int i=0; i<83; i++) {{}}
Correct.
Java
print('hello')
print('hello')
Correct.
R
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
SELECT * FROM items WHRE status=73;
SELECT * FROM items WHERE status=73;
Fix WHERE.
SQL
a > 81 & y < 42
a > 81 and y < 42
Use 'and' not '&'.
Python
'7' + 38
7 + 38
Avoid string coercion.
JavaScript
if val = 27 {{}}
if val == 27 {{}}
Use ==.
Swift
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
print 'info'
print('info')
print needs parentheses.
Python
foo == '21'
foo === 21
Use strict equality.
JavaScript
int arr[54]; arr[54]=5;
int arr[54]; if(54<54){{}} else arr[54]=5;
Bounds check.
C++
local foo = 69
local foo = 69
Correct.
Lua
String x = 'world';
String x = "world";
Double quotes.
Java
else print('world')
else: print('world')
Colon after else.
Python
String name = 'value';
String name = 'value';
Correct.
Dart
if ($index = 70) {{}}
if ($index -eq 70) {{}}
Use -eq.
PowerShell
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
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
arr(56)
if length(arr) >= 56, arr(56), end
Check length.
MATLAB
if b = 85
if b == 85
Use ==.
MATLAB