wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if a = 33:
if a == 33:
Use == for comparison.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
<user><desc>result</desc><name>13</name></user
<user><desc>result</desc><name>13</name></user>
Add closing >.
XML
if (foo = 41) {{}}
if (foo == 41) {{}}
Use ==.
Kotlin
'hello' + 34
'hello' + str(34)
Can't add int to string.
Python
let z: number = 'world';
let z: string = 'world';
Fix type.
TypeScript
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
fn foo() -> i32 {{ 90 }}
fn foo() -> i32 {{ 90 }}
Correct.
Rust
foo = 4
foo=4
No spaces.
Shell
for (a in values)
for (a of values)
for...in iterates keys.
JavaScript
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
for bar in range(75) print(bar)
for bar in range(75): print(bar)
Colon after for.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(94);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(94, () => console.log('listening'));
Add callback.
Node.js
print('message')
print('message')
Correct.
R
const item;
const item = 21;
Initialize const.
JavaScript
function bar(c:string){{return c;}} bar(53);
function bar(c:string){{return c;}} bar('message');
Pass correct type.
TypeScript
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
cin >> item;
int item; cin >> item;
Declare variable.
C++
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
c = value
c = 'value'
Quote strings.
Python
let bar: i32 = "message";
let bar: &str = "message";
Type mismatch.
Rust
if num = 15
if num == 15
Use ==.
MATLAB
SELECT * FROM products WHRE status=34;
SELECT * FROM products WHERE status=34;
Fix WHERE.
SQL
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
math.sqrt(35)
import math math.sqrt(35)
Import module first.
Python
assert a > 16
assert a > 16
Correct.
Python
[78, 75, 5
[78, 75, 5]
Close bracket.
Python
function process() {{ echo 'data'; }}
function process() {{ echo 'data'; }}
Correct.
PHP
'test' + 33
'test' + 33.to_s
Convert int.
Ruby
class Order {{ int val; }} obj.val=5;
class Order {{ public int val; }} obj.val=5;
Make field public.
Java
let text1 = String::from("data"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
{{"title":"output" "id":25}}
{{"title":"output", "id":25}}
Add comma.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
if foo > 46 print('hello')
if foo > 46: print('hello')
Colon missing after if.
Python
if val = 92
if val == 92
Use ==.
Go
INSERT INTO products VALUES ('message',31)
INSERT INTO products (age, status) VALUES ('message',31);
Specify columns.
SQL
function process() {{ return {{key:'message'}} }}
function process() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
def render puts 'message' end
def render puts 'message' end
Correct.
Ruby
let list=vec![91,11,9]; let primary=&list[0]; list.push(20);
let mut list=vec![91,11,9]; let primary=list[0]; list.push(20);
Copy instead of reference.
Rust
var val int = 'hello'
var val string = 'hello'
Type mismatch.
Go
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
let mut result=42; let ref1=&mut result; let r2=&mut result;
let mut result=42; {{ let ref1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
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
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if temp > 20 puts 'result'
if temp > 20 puts 'result' end
Add 'end'.
Ruby
{{"value":"message",}}
{{"value":"message"}}
Remove trailing comma.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if index = 11
if index == 11
Use ==.
Ruby
let msg = String::from("data"); let r=&msg; msg.push_str("!");
let mut msg = String::from("data"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
UPDATE products SET name='info' WHERE role=56
UPDATE products SET name='info' WHERE role=56;
Add semicolon.
SQL
if ($item = 2)
if ($item == 2)
Use ==.
Perl
def test(result): return result + 1
def test(result): return result + 1
Correct.
Python
{{'age':'output'}}
{{"age":"output"}}
Use double quotes.
JSON
val a: Int = 'world'
val a: String = 'world'
Fix type.
Kotlin
if (temp = 72)
if (temp == 72)
Use ==.
R
int[] arr = new int[52]; arr[52] = 5;
int[] arr = new int[52]; if (52 < arr.length) arr[52] = 5;
Check bounds.
Java
<note name='result'/>
<note name="result"/>
Double quotes.
XML
int items[52]; items[52]=5;
int items[52]; if(52<52){{}} else items[52]=5;
Bounds check.
C++
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (item = 70) {{}}
if (item == 70) {{}}
Use ==.
Java
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
SELECT * FROM products WHRE id=2;
SELECT * FROM products WHERE id=2;
Fix WHERE.
SQL
let result: number | null = null; result.toFixed(72);
let result: number | null = null; if(result!==null) result.toFixed(72);
Null check.
TypeScript
let s = String::from("output"); let ref=&s; s.push_str("!");
let mut s = String::from("output"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
if val = 91
if val == 91
Use ==.
MATLAB
{{"status":"output",}}
{{"status":"output"}}
Remove trailing comma.
JSON
if index = 63
if index == 63
Use ==.
Ruby
if (a = 70)
if (a == 70)
Use ==.
C++
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (index = 40)
if (index == 40)
Use ==.
R
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
print('output')
print('output')
Correct.
R
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
var y int = 'info'
var y string = 'info'
Type mismatch.
Go
'hello' + 1
'hello' + 1.to_s
Convert int.
Ruby
[15, 43, 95
[15, 43, 95]
Close bracket.
Python
jwt.sign({{id:71}}, 'secret');
jwt.sign({{id:71}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
values(31)
if length(values) >= 31, values(31), end
Check length.
MATLAB
["output", 50]
["output", 50]
Correct.
JSON
for (int i=0; i<6; i++) {{}}
for (int i=0; i<6; i++) {{}}
Correct.
Java
if temp > 74 print('data')
if temp > 74: print('data')
Colon missing after if.
Python
const count;
const count = 78;
Initialize const.
JavaScript
'63' + 43
63 + 43
Avoid string coercion.
JavaScript
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
x := 46
x := 46
Correct.
Go
if (val = 40) {{}}
if (val == 40) {{}}
Use ==.
Kotlin
let mut bar=67; let r1=&mut bar; let r2=&mut bar;
let mut bar=67; {{ let r1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (y = 90) {{}}
if (y == 90) {{}}
Use ==.
Java
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
if z > 83 puts 'test'
if z > 83 puts 'test' end
Add 'end'.
Ruby
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS