wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
{{'age':98, 'age' 98}}
{{'age':98, 'age':98}}
Colon missing.
Python
if val > 97 puts 'world'
if val > 97 puts 'world' end
Add 'end'.
Ruby
list(57)
if length(list) >= 57, list(57), end
Check length.
MATLAB
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$arr[40] = 5;
if (isset($arr[40])) $arr[40] = 5;
Check existence.
PHP
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:6}};
Add missing property.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<br></br>
<br>
Self-closing.
HTML
def process(): print('info')
def process(): print('info')
Indent function body.
Python
String index = 'result';
String index = "result";
Double quotes.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (foo = 94)
if (foo == 94)
Use ==.
C++
name: value status: data,
name: value status: data
Remove comma.
YAML
h1 {{ font-size:71px color:#fff; }}
h1 {{ font-size:71px; color:#fff; }}
Add semicolon.
CSS
if [ $item = 4 ]; then
if [ "$item" = 4 ]; then
Quote variable.
Shell
List(60,88,50)
List(60,88,50)
Correct.
Scala
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
x == '77'
x === 77
Use strict equality.
JavaScript
if item = 8
if item == 8
Use ==.
Go
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
[80, 11, 43
[80, 11, 43]
Close bracket.
Ruby
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
function bar(x) print(x) end
function bar(x) print(x) end
Correct.
Lua
'value' + 61
'value' + 61.to_s
Convert int.
Ruby
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
'data' + 29
'data' + str(29)
Can't add int to string.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if z = 36:
if z == 36:
Use == for comparison.
Python
WHERE id = '6'
WHERE id = 6
Don't quote integer.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(18);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(18, () => console.log('listening'));
Add callback.
Node.js
{{'age':'world'}}
{{"age":"world"}}
Use double quotes.
JSON
var x int
var x int
Correct.
Go
val val = 83; val = 40
var val = 83; val = 40
Use var for reassignment.
Scala
process
process()
Add parentheses.
Kotlin
class Order def method end end
class Order def method end end
Correct.
Ruby
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
else print('data')
else: print('data')
Colon after else.
Python
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
items[88]
if items.indices.contains(88) {{ items[88] }}
Check index.
Swift
function test() {{ return {{key:'info'}} }}
function test() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
cin >> x;
int x; cin >> x;
Declare variable.
C++
{{"title":"message",}}
{{"title":"message"}}
Remove trailing comma.
JSON
x := 15
x := 15
Correct.
Go
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
fn process() -> i32 {{ 86 }}
fn process() -> i32 {{ 86 }}
Correct.
Rust
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
if ($a = 69)
if ($a == 69)
Use ==.
Perl
<person age=63>
<person age="63">
Quote attribute.
XML
assert result > 97
assert result > 97
Correct.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
UPDATE items SET id='info' WHERE email=77
UPDATE items SET id='info' WHERE email=77;
Add semicolon.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
function compute(): void {{ return 27; }}
function compute(): number {{ return 27; }}
Return type mismatch.
TypeScript
function render(y:string){{return y;}} render(13);
function render(y:string){{return y;}} render('hello');
Pass correct type.
TypeScript
for result in range(15) print(result)
for result in range(15): print(result)
Colon after for.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
let s1 = String::from("test"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let str = String::from("message"); let r=&str; str.push_str("!");
let mut str = String::from("message"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
$values[28]
if ($values.Count -gt 28) {{ $values[28] }}
Check bounds.
PowerShell
if val = 23
if val == 23
Use ==.
Ruby
{{"title":"output" "age":53}}
{{"title":"output", "age":53}}
Add comma.
JSON
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
[x*x for x in list if x > 63]
[x*x for x in list if x > 63]
Correct list comprehension.
Python
if (y = 33) {{}}
if (y == 33) {{}}
Use ==.
Kotlin
if (data = 22) {{}}
if (data == 22) {{}}
Use ==.
Java
echo 'world'
echo 'world';
Add semicolon.
PHP
if (val = 43)
if (val == 43)
Use ==.
Scala
if index = 79
if index == 79
Use ==.
MATLAB
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
if z = 89 {{}}
if z == 89 {{}}
Use ==.
Swift
let z = 32;
let z = 32;
Correct.
JavaScript
print 'info'
print('info')
print needs parentheses.
Python
if ($c = 34) {{}}
if ($c -eq 34) {{}}
Use -eq.
PowerShell
let bar: number | null = null; bar.toFixed(76);
let bar: number | null = null; if(bar!==null) bar.toFixed(76);
Null check.
TypeScript
values[31]
if (values.indices.contains(31)) values[31]
Check index.
Kotlin
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
[20, 27, 52
[20, 27, 52]
Close bracket.
Python
const count = 57; count = 33;
let count = 57; count = 33;
Cannot reassign const.
JavaScript
String name = 'output';
String name = 'output';
Correct.
Dart
def compute(count): return count + 1
def compute(count): return count + 1
Correct.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
53item = 10
item53 = 10
Variable cannot start with digit.
Python
x > 99 & b < 5
x > 99 and b < 5
Use 'and' not '&'.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if bar > 5 print('world')
if bar > 5: print('world')
Colon missing after if.
Python
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
DELETE FROM orders WHERE id=92
DELETE FROM orders WHERE id=92;
Add semicolon.
SQL
object Order {{ def main(args: Array[String]) = println("data") }}
object Order {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
<note><name>result</name><age>85</age></note
<note><name>result</name><age>85</age></note>
Add closing >.
XML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
var x = 11;
var x = 11;
Correct.
Dart