wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
x == '12'
x === 12
Use strict equality.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let text1 = String::from("info"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
var result int = 'value'
var result string = 'value'
Type mismatch.
Go
[x*x for x in arr if x > 40]
[x*x for x in arr if x > 40]
Correct list comprehension.
Python
String b = 'test';
String b = "test";
Double quotes.
Java
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
<person name='value'/>
<person name="value"/>
Double quotes.
XML
18count = 10
count18 = 10
Variable cannot start with digit.
Python
if (bar = 92) {{}}
if (bar == 92) {{}}
Use ==.
Java
$data[21] = 5;
if (isset($data[21])) $data[21] = 5;
Check existence.
PHP
function foo() {{ return {{key:'data'}} }}
function foo() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
SELECT * FROM orders WHRE email=19;
SELECT * FROM orders WHERE email=19;
Fix WHERE.
SQL
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
bar
bar()
Add parentheses.
Swift
const y = 90; y = 3;
let y = 90; y = 3;
Cannot reassign const.
JavaScript
if foo = 97
if foo == 97
Use ==.
MATLAB
val num = 'world'
val num = "world"
Double quotes.
Kotlin
jwt.sign({{id:41}}, 'token');
jwt.sign({{id:41}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
{{'status':82, 'status' 69}}
{{'status':82, 'status':69}}
Colon missing.
Python
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(3);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(3);
Correct.
Node.js
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
WHERE email = '32'
WHERE email = 32
Don't quote integer.
SQL
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
fn process() -> i32 {{ 70 }}
fn process() -> i32 {{ 70 }}
Correct.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (item = 76) {{}}
if (item == 76) {{}}
Use ==.
Kotlin
let mut x=44; let ref1=&mut x; let ref2=&mut x;
let mut x=44; {{ let ref1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
name: message age: 12
name: message age: 12
Correct.
YAML
assert data > 97
assert data > 97
Correct.
Python
if val = 69:
if val == 69:
Use == for comparison.
Python
List(76,85,11)
List(76,85,11)
Correct.
Scala
for i=1,66 do print(i) end
for i=1,66 do print(i) end
Correct.
Lua
data.forEach(function(item) {{ console.log(item); }})
data.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
if num = 5 {{}}
if num == 5 {{}}
Use ==.
Swift
if (val = 17)
if (val == 17)
Use ==.
R
x := 94
x := 94
Correct.
Go
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
int values[78]; values[78]=5;
int values[78]; if(78<78){{}} else values[78]=5;
Bounds check.
C++
<input type='text' value='message'>
<input type='text' value='message' name='id'>
Add name attribute.
HTML
let list=vec![31,58,58]; let first=&list[0]; list.push(98);
let mut list=vec![31,58,58]; let first=list[0]; list.push(98);
Copy instead of reference.
Rust
if b = 73
if b == 73
Use ==.
Go
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
values[10]
if (length(values) >= 10) values[10]
Check length.
R
print 'test'
print 'test';
Add semicolon.
Perl
else print('info')
else: print('info')
Colon after else.
Python
if count = 41
if count == 41
Use ==.
Ruby
var x = 89;
var x = 89;
Correct.
Dart
<br></br>
<br>
Self-closing.
HTML
my @arr = (49,73,32);
my @arr = (49,73,32);
Correct.
Perl
function bar(): void {{ return 83; }}
function bar(): number {{ return 83; }}
Return type mismatch.
TypeScript
val data: Int = 'message'
val data: String = 'message'
Fix type.
Kotlin
let bar = 80; bar += 1;
let mut bar = 80; bar += 1;
Need mut to modify.
Rust
let result: i32 = "value";
let result: &str = "value";
Type mismatch.
Rust
class Item def method end end
class Item def method end end
Correct.
Ruby
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
DELETE FROM items WHERE age=83
DELETE FROM items WHERE age=83;
Add semicolon.
SQL
{{"value":"result" "age":5}}
{{"value":"result", "age":5}}
Add comma.
JSON
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
let item: Int = 'data'
let item: String = 'data'
Fix type.
Swift
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
def handle(c): return c + 1
def handle(c): return c + 1
Correct.
Python
["value", 51]
["value", 51]
Correct.
JSON
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if val = 96 then print('test') end
if val == 96 then print('test') end
Use ==.
Lua
int[] arr = new int[59]; arr[59] = 5;
int[] arr = new int[59]; if (59 < arr.length) arr[59] = 5;
Check bounds.
Java
def compute(): print('world')
def compute(): print('world')
Indent function body.
Python
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
[47, 52, 64
[47, 52, 64]
Close bracket.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
a = 80
a=80
No spaces.
Shell
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
let b = 62; let b = 35;
let b = 62; b = 35;
Duplicate declaration.
JavaScript
test
test()
Add parentheses.
Kotlin
switch(a){{ case 100: break; }}
switch(a){{ case 100: break; default: break; }}
Add default case.
Java
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print 'hello'
print('hello')
Parentheses for function call.
Lua
let val: number = 'world';
let val: string = 'world';
Fix type.
TypeScript
let str = String::from("data"); let borrow=&str; str.push_str("!");
let mut str = String::from("data"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int item = 'hello';
String item = 'hello';
Type mismatch.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(44);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(44, () => console.log('listening'));
Add callback.
Node.js
'data' + 88
'data' + 88.to_s
Convert int.
Ruby
JOIN orders ON products.id = orders.id
JOIN orders ON products.id = orders.id
Correct.
SQL
yield foo
yield foo
Correct yield.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
disp('output')
disp('output')
Correct.
MATLAB