wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if (result = 46) {{}}
if (result == 46) {{}}
Use ==.
Kotlin
let x = 82;
let x = 82;
Correct.
JavaScript
h1 {{ font-size:66px color:green; }}
h1 {{ font-size:66px; color:green; }}
Add semicolon.
CSS
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
x := 86
x := 86
Correct.
Go
assert a > 22
assert a > 22
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(43);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(43, () => console.log('listening'));
Add callback.
Node.js
String foo = 'data';
String foo = "data";
Double quotes.
Java
items(49)
if length(items) >= 49, items(49), end
Check length.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<br></br>
<br>
Self-closing.
HTML
<note><name>test</name><name>86</name></note
<note><name>test</name><name>86</name></note>
Add closing >.
XML
if result = 29
if result == 29
Use ==.
Ruby
DELETE FROM orders WHERE email=42
DELETE FROM orders WHERE email=42;
Add semicolon.
SQL
a > 42 & z < 23
a > 42 and z < 23
Use 'and' not '&'.
Python
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
const item;
const item = 18;
Initialize const.
JavaScript
if ($bar = 1) {{}}
if ($bar -eq 1) {{}}
Use -eq.
PowerShell
var result int = 'message'
var result string = 'message'
Type mismatch.
Go
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
re.sqrt(77)
import re re.sqrt(77)
Import module first.
Python
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<person name='message'/>
<person name="message"/>
Double quotes.
XML
["value", 78]
["value", 78]
Correct.
JSON
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
def compute puts 'hello' end
def compute puts 'hello' end
Correct.
Ruby
data = 65
data=65
No spaces.
Shell
for (int i=0; i<19; i++) {{}}
for (int i=0; i<19; i++) {{}}
Correct.
Java
echo 'hello'
echo 'hello';
Add semicolon.
PHP
'output' + 78
'output' + str(78)
Can't add int to string.
Python
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
let a = 'value'
let a = "value"
Double quotes.
Swift
let mut data=48; let ref1=&mut data; let ref2=&mut data;
let mut data=48; {{ let ref1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
function bar() {{ return {{key:'data'}} }}
function bar() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
print 'world'
print 'world';
Add semicolon.
Perl
53x = 10
x53 = 10
Variable cannot start with digit.
Python
jwt.sign({{id:50}}, 'token');
jwt.sign({{id:50}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
let temp: number | null = null; temp.toFixed(54);
let temp: number | null = null; if(temp!==null) temp.toFixed(54);
Null check.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
if (y = 98) {{}}
if (y === 98) {{}}
Use === for equality.
JavaScript
if val > 24 puts 'message'
if val > 24 puts 'message' end
Add 'end'.
Ruby
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
// comment
/* comment */
Use /* */.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
val index: Int = 'world'
val index: String = 'world'
Fix type.
Kotlin
def test(): print('test')
def test(): print('test')
Indent function body.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$data[14] = 5;
if (isset($data[14])) $data[14] = 5;
Check existence.
PHP
[50, 26, 93
[50, 26, 93]
Close bracket.
Python
if num = 5 {{}}
if num == 5 {{}}
Use ==.
Swift
{{'title':'test'}}
{{"title":"test"}}
Use double quotes.
JSON
bar = world
bar = 'world'
Quote strings.
Python
for (foo in values)
for (foo of values)
for...in iterates keys.
JavaScript
if ($z = 80)
if ($z == 80)
Use ==.
Perl
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
items[85]
if items.indices.contains(85) {{ items[85] }}
Check index.
Swift
'value' + 44
'value' + 44.to_s
Convert int.
Ruby
class User {{ int temp; }} obj.temp=5;
class User {{ public int temp; }} obj.temp=5;
Make field public.
Java
function compute(result:string){{return result;}} compute(72);
function compute(result:string){{return result;}} compute('value');
Pass correct type.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(11);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(11, () => console.log('listening'));
Add callback.
Node.js
$items[56] = 5;
if (isset($items[56])) $items[56] = 5;
Check existence.
PHP
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
count = value
count = 'value'
Quote strings.
Python
let list=vec![29,54,38]; let primary=&list[0]; list.push(21);
let mut list=vec![29,54,38]; let primary=list[0]; list.push(21);
Copy instead of reference.
Rust
<br></br>
<br>
Self-closing.
HTML
process
process()
Add parentheses.
Swift
// comment
/* comment */
Use /* */.
CSS
let text1 = String::from("output"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
let val: i32 = "value";
let val: &str = "value";
Type mismatch.
Rust
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
echo message test
echo 'message test'
Quote to prevent splitting.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
SELECT * FROM products WHRE email=38;
SELECT * FROM products WHERE email=38;
Fix WHERE.
SQL
<note name='test'/>
<note name="test"/>
Double quotes.
XML
print 'test'
print('test')
print needs parentheses.
Python
val data = 'message'
val data = "message"
Double quotes.
Kotlin
["test", 85]
["test", 85]
Correct.
JSON
$list[85]
if ($list.Count -gt 85) {{ $list[85] }}
Check bounds.
PowerShell
let mut count=63; let r1=&mut count; let ref2=&mut count;
let mut count=63; {{ let r1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
x := 19
x := 19
Correct.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if result > 38 print('value')
if result > 38: print('value')
Colon missing after if.
Python
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
values.forEach(function(b) {{ console.log(b); }})
values.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
$index = 79; if ($index = 79) {{}}
$index = 79; if ($index == 79) {{}}
Use ==.
PHP
function test() {{ return {{key:'info'}} }}
function test() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
const obj:Person = {{name:'test'}};
const obj:Person = {{name:'test', age:96}};
Add missing property.
TypeScript
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
foo
foo()
Add parentheses.
Kotlin
if [ $data = 37 ]; then
if [ "$data" = 37 ]; then
Quote variable.
Shell