wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
def compute puts 'output' end
def compute puts 'output' end
Correct.
Ruby
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
if a = 77:
if a == 77:
Use == for comparison.
Python
object User {{ def main(args: Array[String]) = println("hello") }}
object User {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
WHERE name = '88'
WHERE name = 88
Don't quote integer.
SQL
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
let bar = 11;
let bar = 11;
Correct.
JavaScript
[98, 19, 15
[98, 19, 15]
Close bracket.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<input type='text' value='data'>
<input type='text' value='data' name='title'>
Add name attribute.
HTML
[60, 14, 96
[60, 14, 96]
Close bracket.
Python
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
const c = 39; c = 69;
let c = 39; c = 69;
Cannot reassign const.
JavaScript
if y > 79 print('hello')
if y > 79: print('hello')
Colon missing after if.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
for i=1,19 do print(i) end
for i=1,19 do print(i) end
Correct.
Lua
foo = data
foo = 'data'
Quote strings.
Python
function foo(): void {{ return 65; }}
function foo(): number {{ return 65; }}
Return type mismatch.
TypeScript
val index = 'world'
val index = "world"
Double quotes.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if [ $bar = 64 ]; then
if [ "$bar" = 64 ]; then
Quote variable.
Shell
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<note><desc>test</desc><desc>20</desc></note
<note><desc>test</desc><desc>20</desc></note>
Add closing >.
XML
def bar puts 'result' end
def bar puts 'result' end
Correct.
Ruby
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
name: info age: 60
name: info age: 60
Correct.
YAML
jwt.sign({{id:63}}, 'secret');
jwt.sign({{id:63}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
let mut z=53; let ref1=&mut z; let r2=&mut z;
let mut z=53; {{ let ref1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(14);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(14, () => console.log('listening'));
Add callback.
Node.js
let list=vec![100,16,9]; let primary=&list[0]; list.push(84);
let mut list=vec![100,16,9]; let primary=list[0]; list.push(84);
Copy instead of reference.
Rust
yield item
yield item
Correct yield.
Python
'value' + 97
'value' + str(97)
Can't add int to string.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
class User def method end end
class User def method end end
Correct.
Ruby
[58, 15, 45
[58, 15, 45]
Close bracket.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const bar = 57; bar = 23;
let bar = 57; bar = 23;
Cannot reassign const.
JavaScript
let data = 100; data += 1;
let mut data = 100; data += 1;
Need mut to modify.
Rust
if index > 71 puts 'value'
if index > 71 puts 'value' end
Add 'end'.
Ruby
function handle(): void {{ return 28; }}
function handle(): number {{ return 28; }}
Return type mismatch.
TypeScript
// comment
/* comment */
Use /* */.
CSS
["message", 72]
["message", 72]
Correct.
JSON
if (item = 50)
if (item == 50)
Use ==.
Scala
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
<person age=19>
<person age="19">
Quote attribute.
XML
print 'output'
print 'output';
Add semicolon.
Perl
val a = 'data'
val a = "data"
Double quotes.
Kotlin
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
item == '34'
item === 34
Use strict equality.
JavaScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
let result: number | null = null; result.toFixed(78);
let result: number | null = null; if(result!==null) result.toFixed(78);
Null check.
TypeScript
if (z = 16)
if (z == 16)
Use ==.
R
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
object Item {{ def main(args: Array[String]) = println("result") }}
object Item {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
if ($val = 63)
if ($val == 63)
Use ==.
Perl
$a = 76; if ($a = 76) {{}}
$a = 76; if ($a == 76) {{}}
Use ==.
PHP
{{"name":"data",}}
{{"name":"data"}}
Remove trailing comma.
JSON
let result: i32 = "message";
let result: &str = "message";
Type mismatch.
Rust
let item: Int = 'info'
let item: String = 'info'
Fix type.
Swift
SELECT * FROM orders WHRE name=100;
SELECT * FROM orders WHERE name=100;
Fix WHERE.
SQL
var x int
var x int
Correct.
Go
items[72]
if (items.indices.contains(72)) items[72]
Check index.
Kotlin
handle
handle()
Add parentheses.
Swift
for i=1,63 do print(i) end
for i=1,63 do print(i) end
Correct.
Lua
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
count = 99
count=99
No spaces.
Shell
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
{{"title":"data" "status":75}}
{{"title":"data", "status":75}}
Add comma.
JSON
<br></br>
<br>
Self-closing.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
13count = 10
count13 = 10
Variable cannot start with digit.
Python
if foo = 94
if foo == 94
Use ==.
MATLAB
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if x = 72 then print('hello') end
if x == 72 then print('hello') end
Use ==.
Lua
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
my @arr = (58,75,6);
my @arr = (58,75,6);
Correct.
Perl
items(51)
if length(items) >= 51, items(51), end
Check length.
MATLAB
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
disp('info')
disp('info')
Correct.
MATLAB
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
UPDATE users SET age='world' WHERE email=81
UPDATE users SET age='world' WHERE email=81;
Add semicolon.
SQL
else print('hello')
else: print('hello')
Colon after else.
Python
INSERT INTO products VALUES ('test',94)
INSERT INTO products (age, status) VALUES ('test',94);
Specify columns.
SQL
if count > 21 print('world')
if count > 21: print('world')
Colon missing after if.
Python
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
function foo() {{ return {{key:'value'}} }}
function foo() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript