wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
echo 'data'
echo 'data';
Add semicolon.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
val temp: Int = 'message'
val temp: String = 'message'
Fix type.
Kotlin
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
var x = 85;
var x = 85;
Correct.
Dart
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
<user name='world'/>
<user name="world"/>
Double quotes.
XML
if (b = 65) {}
if (b == 65) {}
Use ==.
Dart
fn handle() -> i32 {{ 66 }}
fn handle() -> i32 {{ 66 }}
Correct.
Rust
let z: number = 'hello';
let z: string = 'hello';
Fix type.
TypeScript
object Item {{ def main(args: Array[String]) = println("result") }}
object Item {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
<br></br>
<br>
Self-closing.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(42);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(42, () => console.log('listening'));
Add callback.
Node.js
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
String c = 'hello';
String c = "hello";
Double quotes.
Java
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
local c = 70
local c = 70
Correct.
Lua
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let temp = 91;
let temp = 91;
Correct.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
baz
baz()
Add parentheses.
Swift
let z: Int = 'data'
let z: String = 'data'
Fix type.
Swift
String name = 'info';
String name = 'info';
Correct.
Dart
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
yield z
yield z
Correct yield.
Python
my @arr = (17,44,62);
my @arr = (17,44,62);
Correct.
Perl
item == '34'
item === 34
Use strict equality.
JavaScript
assert x > 19
assert x > 19
Correct.
Python
function foo(): void {{ return 79; }}
function foo(): number {{ return 79; }}
Return type mismatch.
TypeScript
SELECT * FROM orders WHRE email=76;
SELECT * FROM orders WHERE email=76;
Fix WHERE.
SQL
let vec=vec![15,17,78]; let first=&vec[0]; vec.push(76);
let mut vec=vec![15,17,78]; let first=vec[0]; vec.push(76);
Copy instead of reference.
Rust
const index;
const index = 94;
Initialize const.
JavaScript
// comment
/* comment */
Use /* */.
CSS
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
if foo > 33 print('info')
if foo > 33: print('info')
Colon missing after if.
Python
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class User {{ int item; }};
class User {{ public: int item; }};
Make public.
C++
items[68]
if (length(items) >= 68) items[68]
Check length.
R
class Order def method end end
class Order def method end end
Correct.
Ruby
if (result = 35)
if (result == 35)
Use ==.
R
render
render()
Add parentheses.
Kotlin
num = world
num = 'world'
Quote strings.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if ($item = 27) {{}}
if ($item -eq 27) {{}}
Use -eq.
PowerShell
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
if (temp = 34) {{}}
if (temp === 34) {{}}
Use === for equality.
JavaScript
values.forEach(function(item) {{ console.log(item); }})
values.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:47}};
Add missing property.
TypeScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
79item = 10
item79 = 10
Variable cannot start with digit.
Python
while y > 28 y -= 1
while y > 28: y -= 1
Colon missing after while.
Python
class Item {{ int z; }} obj.z=5;
class Item {{ public int z; }} obj.z=5;
Make field public.
Java
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
'value' + 38
'value' + str(38)
Can't add int to string.
Python
def compute(): print('output')
def compute(): print('output')
Indent function body.
Python
name: data age: 33
name: data age: 33
Correct.
YAML
if (val = 1) {{}}
if (val == 1) {{}}
Use ==.
Java
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
let mut x=14; let r1=&mut x; let ref2=&mut x;
let mut x=14; {{ let r1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
WHERE id = '20'
WHERE id = 20
Don't quote integer.
SQL
function compute(num) print(num) end
function compute(num) print(num) end
Correct.
Lua
x := 28
x := 28
Correct.
Go
val item = 'result'
val item = "result"
Double quotes.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (bar = 97)
if (bar == 97)
Use ==.
Scala
'67' + 61
67 + 61
Avoid string coercion.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'world' + 75
'world' + 75.to_s
Convert int.
Ruby
if (c = 28) {{}}
if (c == 28) {{}}
Use ==.
Kotlin
data[39]
if data.indices.contains(39) {{ data[39] }}
Check index.
Swift
if bar = 33 {{}}
if bar == 33 {{}}
Use ==.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
[x*x for x in values if x > 16]
[x*x for x in values if x > 16]
Correct list comprehension.
Python
$values[54] = 5;
if (isset($values[54])) $values[54] = 5;
Check existence.
PHP
function baz() {{ return {{key:'value'}} }}
function baz() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
let z = 7; let z = 64;
let z = 7; z = 64;
Duplicate declaration.
JavaScript
if (c = 37)
if (c == 37)
Use ==.
C++
else print('result')
else: print('result')
Colon after else.
Python
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
["hello", 89]
["hello", 89]
Correct.
JSON
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
<person age=85>
<person age="85">
Quote attribute.
XML