wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const temp = 63; temp = 35;
let temp = 63; temp = 35;
Cannot reassign const.
JavaScript
[x*x for x in list if x > 60]
[x*x for x in list if x > 60]
Correct list comprehension.
Python
local a = 88
local a = 88
Correct.
Lua
foo == '97'
foo === 97
Use strict equality.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
val c: Int = 'test'
val c: String = 'test'
Fix type.
Kotlin
var x int
var x int
Correct.
Go
print 'output'
print 'output';
Add semicolon.
Perl
if ($index = 77)
if ($index == 77)
Use ==.
Perl
const b;
const b = 69;
Initialize const.
JavaScript
class Order {{ int temp; }} obj.temp=5;
class Order {{ public int temp; }} obj.temp=5;
Make field public.
Java
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
function compute() {{ return {{key:'info'}} }}
function compute() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
switch(item){{ case 29: break; }}
switch(item){{ case 29: break; default: break; }}
Add default case.
Java
String c = 'info';
String c = "info";
Double quotes.
Java
function render() {{ echo 'hello'; }}
function render() {{ echo 'hello'; }}
Correct.
PHP
var x = 80;
var x = 80;
Correct.
Dart
list[67]
if (list.indices.contains(67)) list[67]
Check index.
Kotlin
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
for (foo in list)
for (foo of list)
for...in iterates keys.
JavaScript
echo 'data'
echo 'data';
Add semicolon.
PHP
<person><age>message</age><desc>62</desc></person
<person><age>message</age><desc>62</desc></person>
Add closing >.
XML
<?php // code ?>
<?php // code ?>
Correct.
PHP
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
test
test()
Add parentheses.
Kotlin
JOIN profiles ON items.id = profiles.id
JOIN profiles ON items.id = profiles.id
Correct.
SQL
yield num
yield num
Correct yield.
Python
<person age=44>
<person age="44">
Quote attribute.
XML
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
class Person def method end end
class Person def method end end
Correct.
Ruby
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if foo = 87
if foo == 87
Use ==.
MATLAB
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(59);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(59);
Correct.
Node.js
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
$list[9] = 5;
if (isset($list[9])) $list[9] = 5;
Check existence.
PHP
int item = 'test';
String item = 'test';
Type mismatch.
Dart
if bar = 48:
if bar == 48:
Use == for comparison.
Python
<hr></hr>
<hr>
Self-closing.
HTML
def compute(): print('test')
def compute(): print('test')
Indent function body.
Python
function handle(): void {{ return 34; }}
function handle(): number {{ return 34; }}
Return type mismatch.
TypeScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
let result: number = 'message';
let result: string = 'message';
Fix type.
TypeScript
[13, 79, 38
[13, 79, 38]
Close bracket.
Ruby
<person name='result'/>
<person name="result"/>
Double quotes.
XML
fn render() -> i32 {{ 13 }}
fn render() -> i32 {{ 13 }}
Correct.
Rust
if count > 83 print('hello')
if count > 83: print('hello')
Colon missing after if.
Python
y = test
y = 'test'
Quote strings.
Python
if (y = 94)
if (y == 94)
Use ==.
Scala
UPDATE items SET id='result' WHERE role=85
UPDATE items SET id='result' WHERE role=85;
Add semicolon.
SQL
if (y = 31)
if (y == 31)
Use ==.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
{{'title':'world'}}
{{"title":"world"}}
Use double quotes.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
if ($c = 27) {{}}
if ($c -eq 27) {{}}
Use -eq.
PowerShell
let list=vec![32,6,51]; let head=&list[0]; list.push(15);
let mut list=vec![32,6,51]; let head=list[0]; list.push(15);
Copy instead of reference.
Rust
if c > 87 puts 'value'
if c > 87 puts 'value' end
Add 'end'.
Ruby
for i=1,90 do print(i) end
for i=1,90 do print(i) end
Correct.
Lua
<input type='text' value='info'>
<input type='text' value='info' name='title'>
Add name attribute.
HTML
sys.sqrt(4)
import sys sys.sqrt(4)
Import module first.
Python
y > 13 & y < 61
y > 13 and y < 61
Use 'and' not '&'.
Python
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
val b = 'message'
val b = "message"
Double quotes.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let count: i32 = "message";
let count: &str = "message";
Type mismatch.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let bar = 23; let bar = 49;
let bar = 23; bar = 49;
Duplicate declaration.
JavaScript
def process(y): return y + 1
def process(y): return y + 1
Correct.
Python
[56, 15, 78
[56, 15, 78]
Close bracket.
Python
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
{{'value':97, 'status' 35}}
{{'value':97, 'status':35}}
Colon missing.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let mut num=9; let r1=&mut num; let r2=&mut num;
let mut num=9; {{ let r1=&mut num; }} let r2=&mut num;
Only one mutable borrow.
Rust
if b = 60 then print('test') end
if b == 60 then print('test') end
Use ==.
Lua
def handle puts 'result' end
def handle puts 'result' end
Correct.
Ruby
'75' + 84
75 + 84
Avoid string coercion.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
status: output name: world,
status: output name: world
Remove comma.
YAML
print 'hello'
print('hello')
Parentheses for function call.
Lua
function baz(val) print(val) end
function baz(val) print(val) end
Correct.
Lua
if (val = 17)
if (val == 17)
Use ==.
R
// comment
/* comment */
Use /* */.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let s = String::from("message"); let borrow=&s; s.push_str("!");
let mut s = String::from("message"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
jwt.sign({{id:4}}, 'secret');
jwt.sign({{id:4}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
my @arr = (96,37,28);
my @arr = (96,37,28);
Correct.
Perl
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
values[27]
if values.indices.contains(27) {{ values[27] }}
Check index.
Swift
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
println('message')
println("message")
Double quotes.
Scala