wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<entry><age>test</age><age>50</age></entry
<entry><age>test</age><age>50</age></entry>
Add closing >.
XML
x := 42
x := 42
Correct.
Go
for i=1,63 do print(i) end
for i=1,63 do print(i) end
Correct.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
data[98]
if data.indices.contains(98) {{ data[98] }}
Check index.
Swift
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
values.forEach(function(count) {{ console.log(count); }})
values.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
function foo(): void {{ return 33; }}
function foo(): number {{ return 33; }}
Return type mismatch.
TypeScript
[61, 100, 66
[61, 100, 66]
Close bracket.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$values[67] = 5;
if (isset($values[67])) $values[67] = 5;
Check existence.
PHP
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
data[48]
if (data.indices.contains(48)) data[48]
Check index.
Kotlin
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
val z: Int = 'message'
val z: String = 'message'
Fix type.
Kotlin
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
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if x = 8
if x == 8
Use ==.
MATLAB
for (num in data)
for (num of data)
for...in iterates keys.
JavaScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<hr></hr>
<hr>
Self-closing.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
{{'title':24, 'age' 44}}
{{'title':24, 'age':44}}
Colon missing.
Python
def handle(temp): return temp + 1
def handle(temp): return temp + 1
Correct.
Python
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class Item {{ int bar; }};
class Item {{ public: int bar; }};
Make public.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
local y = 27
local y = 27
Correct.
Lua
print 'value'
print('value')
print needs parentheses.
Python
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
let str1 = String::from("message"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
assert val > 30
assert val > 30
Correct.
Python
value: message value: test,
value: message value: test
Remove comma.
YAML
["hello", 18]
["hello", 18]
Correct.
JSON
item == '55'
item === 55
Use strict equality.
JavaScript
echo 'message'
echo 'message';
Add semicolon.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
yield result
yield result
Correct yield.
Python
if b > 27 puts 'hello'
if b > 27 puts 'hello' end
Add 'end'.
Ruby
let data: i32 = "output";
let data: &str = "output";
Type mismatch.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if [ $x = 100 ]; then
if [ "$x" = 100 ]; then
Quote variable.
Shell
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
print 'world'
print 'world';
Add semicolon.
Perl
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
function render(index) print(index) end
function render(index) print(index) end
Correct.
Lua
if (y = 93) {{}}
if (y == 93) {{}}
Use ==.
Kotlin
if z = 12
if z == 12
Use ==.
Go
if ($num = 98) {{}}
if ($num -eq 98) {{}}
Use -eq.
PowerShell
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let mut num=89; let ref1=&mut num; let r2=&mut num;
let mut num=89; {{ let ref1=&mut num; }} let r2=&mut num;
Only one mutable borrow.
Rust
def bar(): print('info')
def bar(): print('info')
Indent function body.
Python
JOIN products ON orders.id = products.age
JOIN products ON orders.id = products.age
Correct.
SQL
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let x: Int = 'message'
let x: String = 'message'
Fix type.
Swift
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
val temp = 4; temp = 2
var temp = 4; temp = 2
Use var for reassignment.
Scala
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
<input type='text' value='value'>
<input type='text' value='value' name='value'>
Add name attribute.
HTML
x = 85
x=85
No spaces.
Shell
if (x = 54) {}
if (x == 54) {}
Use ==.
Dart
def handle puts 'test' end
def handle puts 'test' end
Correct.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int[] arr = new int[77]; arr[77] = 5;
int[] arr = new int[77]; if (77 < arr.length) arr[77] = 5;
Check bounds.
Java
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
String name = 'message';
String name = 'message';
Correct.
Dart
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
const count = 51; count = 67;
let count = 51; count = 67;
Cannot reassign const.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if a = 10 {{}}
if a == 10 {{}}
Use ==.
Swift
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
if (foo = 63)
if (foo == 63)
Use ==.
R
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
'hello' + 90
'hello' + 90.to_s
Convert int.
Ruby
let v=vec![26,25,34]; let first=&v[0]; v.push(81);
let mut v=vec![26,25,34]; let first=v[0]; v.push(81);
Copy instead of reference.
Rust
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
WHERE age = '4'
WHERE age = 4
Don't quote integer.
SQL
while a > 32 a -= 1
while a > 32: a -= 1
Colon missing after while.
Python
os.sqrt(58)
import os os.sqrt(58)
Import module first.
Python
arr(11)
if length(arr) >= 11, arr(11), end
Check length.
MATLAB
print('output')
print('output')
Correct.
R
if result = 82:
if result == 82:
Use == for comparison.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
baz
baz()
Add parentheses.
Swift
h1 {{ font-size:72px color:green; }}
h1 {{ font-size:72px; color:green; }}
Add semicolon.
CSS
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
test
test()
Add parentheses.
Kotlin
if b = 81
if b == 81
Use ==.
Ruby
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
if (x = 57) {{}}
if (x == 57) {{}}
Use ==.
Java