wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
bar = world
bar = 'world'
Quote strings.
Python
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
$values[60] = 5;
if (isset($values[60])) $values[60] = 5;
Check existence.
PHP
if c = 29
if c == 29
Use ==.
Ruby
<?php // code ?>
<?php // code ?>
Correct.
PHP
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
if result = 77:
if result == 77:
Use == for comparison.
Python
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
for x in range(44) print(x)
for x in range(44): print(x)
Colon after for.
Python
<person name='message'/>
<person name="message"/>
Double quotes.
XML
<input type='text' value='hello'>
<input type='text' value='hello' name='title'>
Add name attribute.
HTML
if z = 98 {{}}
if z == 98 {{}}
Use ==.
Swift
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
if count = 77
if count == 77
Use ==.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(71);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(71, () => console.log('listening'));
Add callback.
Node.js
def baz(): print('message')
def baz(): print('message')
Indent function body.
Python
if ($c = 9)
if ($c == 9)
Use ==.
Perl
{{'value':13, 'name' 6}}
{{'value':13, 'name':6}}
Colon missing.
Python
function handle(y) print(y) end
function handle(y) print(y) end
Correct.
Lua
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if foo > 16 print('info')
if foo > 16: print('info')
Colon missing after if.
Python
id: output name: world,
id: output name: world
Remove comma.
YAML
JOIN products ON products.id = products.status
JOIN products ON products.id = products.status
Correct.
SQL
var x = 60;
var x = 60;
Correct.
Dart
for (int i=0; i<67; i++) {{}}
for (int i=0; i<67; i++) {{}}
Correct.
Java
if (count = 4)
if (count == 4)
Use ==.
Scala
def compute puts 'message' end
def compute puts 'message' end
Correct.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<br></br>
<br>
Self-closing.
HTML
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if b = 40 then print('value') end
if b == 40 then print('value') end
Use ==.
Lua
48data = 10
data48 = 10
Variable cannot start with digit.
Python
for (b in list)
for (b of list)
for...in iterates keys.
JavaScript
{{'name':'info'}}
{{"name":"info"}}
Use double quotes.
JSON
for i=1,40 do print(i) end
for i=1,40 do print(i) end
Correct.
Lua
let str = String::from("output"); let borrow=&str; str.push_str("!");
let mut str = String::from("output"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
String data = 'message';
String data = "message";
Double quotes.
Java
if data = 28
if data == 28
Use ==.
MATLAB
fn process() -> i32 {{ 36 }}
fn process() -> i32 {{ 36 }}
Correct.
Rust
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
UPDATE users SET status='data' WHERE status=82
UPDATE users SET status='data' WHERE status=82;
Add semicolon.
SQL
SELECT * FROM products WHRE name=48;
SELECT * FROM products WHERE name=48;
Fix WHERE.
SQL
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
class Product {{ int bar; }} obj.bar=5;
class Product {{ public int bar; }} obj.bar=5;
Make field public.
Java
if [ $foo = 78 ]; then
if [ "$foo" = 78 ]; then
Quote variable.
Shell
let index = 'info'
let index = "info"
Double quotes.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let result = 89;
let result = 89;
Correct.
JavaScript
let foo: number | null = null; foo.toFixed(3);
let foo: number | null = null; if(foo!==null) foo.toFixed(3);
Null check.
TypeScript
<person><age>hello</age><age>20</age></person
<person><age>hello</age><age>20</age></person>
Add closing >.
XML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (c = 97) {}
if (c == 97) {}
Use ==.
Dart
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
object User {{ def main(args: Array[String]) = println("data") }}
object User {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
local result = 45
local result = 45
Correct.
Lua
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
<hr></hr>
<hr>
Self-closing.
HTML
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
if temp > 51 puts 'test'
if temp > 51 puts 'test' end
Add 'end'.
Ruby
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(37);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(37);
Correct.
Node.js
print 'info'
print 'info';
Add semicolon.
Perl
function process(): void {{ return 66; }}
function process(): number {{ return 66; }}
Return type mismatch.
TypeScript
def process(result): return result + 1
def process(result): return result + 1
Correct.
Python
disp('info')
disp('info')
Correct.
MATLAB
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:72}};
Add missing property.
TypeScript
function foo() {{ return {{key:'message'}} }}
function foo() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
echo 'world'
echo 'world';
Add semicolon.
PHP
while c > 69 c -= 1
while c > 69: c -= 1
Colon missing after while.
Python
switch(x){{ case 13: break; }}
switch(x){{ case 13: break; default: break; }}
Add default case.
Java
int[] values = new int[38]; values[38] = 5;
int[] values = new int[38]; if (38 < values.length) values[38] = 5;
Check bounds.
Java
b = 77
b=77
No spaces.
Shell
const temp;
const temp = 69;
Initialize const.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$result = 69; if ($result = 69) {{}}
$result = 69; if ($result == 69) {{}}
Use ==.
PHP
// comment
/* comment */
Use /* */.
CSS
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
INSERT INTO products VALUES ('value',90)
INSERT INTO products (age, status) VALUES ('value',90);
Specify columns.
SQL
String name = 'info';
String name = 'info';
Correct.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
'test' + 55
'test' + str(55)
Can't add int to string.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
h1 {{ font-size:96px color:#fff; }}
h1 {{ font-size:96px; color:#fff; }}
Add semicolon.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (result = 21) {{}}
if (result == 21) {{}}
Use ==.
Kotlin
assert z > 25
assert z > 25
Correct.
Python
DELETE FROM items WHERE id=57
DELETE FROM items WHERE id=57;
Add semicolon.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let x: number = 'hello';
let x: string = 'hello';
Fix type.
TypeScript
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
'17' + 4
17 + 4
Avoid string coercion.
JavaScript
val bar = 75; bar = 77
var bar = 75; bar = 77
Use var for reassignment.
Scala
print 'hello'
print('hello')
Parentheses for function call.
Lua
jwt.sign({{id:44}}, 'key');
jwt.sign({{id:44}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
var item int = 'result'
var item string = 'result'
Type mismatch.
Go