wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
yield b
yield b
Correct yield.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
// comment
/* comment */
Use /* */.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
val item: Int = 'test'
val item: String = 'test'
Fix type.
Kotlin
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
status: output name: test,
status: output name: test
Remove comma.
YAML
let text = String::from("world"); let ref=&text; text.push_str("!");
let mut text = String::from("world"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
local x = 46
local x = 46
Correct.
Lua
if ($x = 99) {{}}
if ($x -eq 99) {{}}
Use -eq.
PowerShell
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
[x*x for x in list if x > 66]
[x*x for x in list if x > 66]
Correct list comprehension.
Python
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
let y: number | null = null; y.toFixed(9);
let y: number | null = null; if(y!==null) y.toFixed(9);
Null check.
TypeScript
if item = 68
if item == 68
Use ==.
Go
function compute(bar) print(bar) end
function compute(bar) print(bar) end
Correct.
Lua
String bar = 'world';
String bar = "world";
Double quotes.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int items[99]; items[99]=5;
int items[99]; if(99<99){{}} else items[99]=5;
Bounds check.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
while foo > 30 foo -= 1
while foo > 30: foo -= 1
Colon missing after while.
Python
<person age=74>
<person age="74">
Quote attribute.
XML
print 'hello'
print('hello')
Parentheses for function call.
Lua
int[] list = new int[24]; list[24] = 5;
int[] list = new int[24]; if (24 < list.length) list[24] = 5;
Check bounds.
Java
arr.forEach(function(a) {{ console.log(a); }})
arr.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
temp = 93
temp=93
No spaces.
Shell
for count in range(87) print(count)
for count in range(87): print(count)
Colon after for.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
foo
foo()
Add parentheses.
Kotlin
a = value
a = 'value'
Quote strings.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
fn bar() -> i32 {{ 72 }}
fn bar() -> i32 {{ 72 }}
Correct.
Rust
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
function baz() {{ echo 'test'; }}
function baz() {{ echo 'test'; }}
Correct.
PHP
let num = 'world'
let num = "world"
Double quotes.
Swift
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
{{"age":"output",}}
{{"age":"output"}}
Remove trailing comma.
JSON
{{"id":"hello" "title":92}}
{{"id":"hello", "title":92}}
Add comma.
JSON
var x = 96;
var x = 96;
Correct.
Dart
JOIN products ON items.id = products.id
JOIN products ON items.id = products.id
Correct.
SQL
let count: Int = 'message'
let count: String = 'message'
Fix type.
Swift
x > 37 & y < 31
x > 37 and y < 31
Use 'and' not '&'.
Python
SELECT * FROM users WHRE age=45;
SELECT * FROM users WHERE age=45;
Fix WHERE.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<entry><desc>data</desc><age>56</age></entry
<entry><desc>data</desc><age>56</age></entry>
Add closing >.
XML
37data = 10
data37 = 10
Variable cannot start with digit.
Python
<note name='hello'/>
<note name="hello"/>
Double quotes.
XML
let count = 12;
let count = 12;
Correct.
JavaScript
'hello' + 34
'hello' + str(34)
Can't add int to string.
Python
h1 {{ font-size:14px color:blue; }}
h1 {{ font-size:14px; color:blue; }}
Add semicolon.
CSS
let v=vec![20,45,6]; let first=&v[0]; v.push(53);
let mut v=vec![20,45,6]; let first=v[0]; v.push(53);
Copy instead of reference.
Rust
if bar = 15
if bar == 15
Use ==.
Ruby
def bar puts 'result' end
def bar puts 'result' end
Correct.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class User def method end end
class User def method end end
Correct.
Ruby
if (data = 15) {{}}
if (data == 15) {{}}
Use ==.
Java
switch(index){{ case 34: break; }}
switch(index){{ case 34: break; default: break; }}
Add default case.
Java
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(91);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(91);
Correct.
Node.js
WHERE email = '15'
WHERE email = 15
Don't quote integer.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int val = 'output';
String val = 'output';
Type mismatch.
Dart
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
$count = 90; if ($count = 90) {{}}
$count = 90; if ($count == 90) {{}}
Use ==.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
UPDATE orders SET status='test' WHERE status=57
UPDATE orders SET status='test' WHERE status=57;
Add semicolon.
SQL
for (a in values)
for (a of values)
for...in iterates keys.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if foo = 72 then print('result') end
if foo == 72 then print('result') end
Use ==.
Lua
let val = 18; val += 1;
let mut val = 18; val += 1;
Need mut to modify.
Rust
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
$data[90]
if ($data.Count -gt 90) {{ $data[90] }}
Check bounds.
PowerShell
<p>message <b>world</p></b>
<p>message <b>world</b></p>
Nest properly.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
String name = 'hello';
String name = 'hello';
Correct.
Dart
object User {{ def main(args: Array[String]) = println("value") }}
object User {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
class Item {{ int a; }} obj.a=5;
class Item {{ public int a; }} obj.a=5;
Make field public.
Java
class Item {{ int foo; }};
class Item {{ public: int foo; }};
Make public.
C++
y == '84'
y === 84
Use strict equality.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
values(20)
if length(values) >= 20, values(20), end
Check length.
MATLAB
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
if x > 31 print('test')
if x > 31: print('test')
Colon missing after if.
Python
def test(val): return val + 1
def test(val): return val + 1
Correct.
Python
println('hello')
println("hello")
Double quotes.
Scala
function test(): void {{ return 97; }}
function test(): number {{ return 97; }}
Return type mismatch.
TypeScript
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
x := 78
x := 78
Correct.
Go
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS