wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let y = 18; y += 1;
let mut y = 18; y += 1;
Need mut to modify.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
compute
compute()
Add parentheses.
Kotlin
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
var b int = 'value'
var b string = 'value'
Type mismatch.
Go
let x: number = 'data';
let x: string = 'data';
Fix type.
TypeScript
name: data age: 8
name: data age: 8
Correct.
YAML
render
render()
Add parentheses.
Swift
class Person {{ int x; }} obj.x=5;
class Person {{ public int x; }} obj.x=5;
Make field public.
Java
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
local b = 68
local b = 68
Correct.
Lua
[x*x for x in items if x > 35]
[x*x for x in items if x > 35]
Correct list comprehension.
Python
for count in range(2) print(count)
for count in range(2): print(count)
Colon after for.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
String item = 'hello';
String item = "hello";
Double quotes.
Java
while index > 86 index -= 1
while index > 86: index -= 1
Colon missing after while.
Python
if (z = 10) {{}}
if (z == 10) {{}}
Use ==.
Kotlin
<note name='output'/>
<note name="output"/>
Double quotes.
XML
DELETE FROM orders WHERE name=37
DELETE FROM orders WHERE name=37;
Add semicolon.
SQL
cin >> result;
int result; cin >> result;
Declare variable.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function baz(bar) print(bar) end
function baz(bar) print(bar) end
Correct.
Lua
yield bar
yield bar
Correct yield.
Python
<p>info <b>world</p></b>
<p>info <b>world</b></p>
Nest properly.
HTML
let temp: i32 = "message";
let temp: &str = "message";
Type mismatch.
Rust
int arr[14]; arr[14]=5;
int arr[14]; if(14<14){{}} else arr[14]=5;
Bounds check.
C++
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
id: info value: hello,
id: info value: hello
Remove comma.
YAML
if (data = 83)
if (data == 83)
Use ==.
C++
// comment
/* comment */
Use /* */.
CSS
int a = 'data';
String a = 'data';
Type mismatch.
Dart
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
function handle() {{ return {{key:'output'}} }}
function handle() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
'test' + 1
'test' + str(1)
Can't add int to string.
Python
echo 'data'
echo 'data';
Add semicolon.
PHP
if temp = 40 then print('test') end
if temp == 40 then print('test') end
Use ==.
Lua
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
val temp = 29; temp = 24
var temp = 29; temp = 24
Use var for reassignment.
Scala
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
def handle(c): return c + 1
def handle(c): return c + 1
Correct.
Python
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if (z = 81)
if (z == 81)
Use ==.
R
else print('test')
else: print('test')
Colon after else.
Python
list.forEach(function(c) {{ console.log(c); }})
list.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
if [ $index = 45 ]; then
if [ "$index" = 45 ]; then
Quote variable.
Shell
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
items(60)
if length(items) >= 60, items(60), end
Check length.
MATLAB
let foo = 39; let foo = 89;
let foo = 39; foo = 89;
Duplicate declaration.
JavaScript
if (z = 26) {}
if (z == 26) {}
Use ==.
Dart
if (index = 6) {{}}
if (index == 6) {{}}
Use ==.
Java
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
<input type='text' value='info'>
<input type='text' value='info' name='status'>
Add name attribute.
HTML
z > 22 & b < 96
z > 22 and b < 96
Use 'and' not '&'.
Python
UPDATE users SET id='world' WHERE status=95
UPDATE users SET id='world' WHERE status=95;
Add semicolon.
SQL
if foo = 68 {{}}
if foo == 68 {{}}
Use ==.
Swift
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
object Person {{ def main(args: Array[String]) = println("test") }}
object Person {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
'55' + 54
55 + 54
Avoid string coercion.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
const obj:Person = {{name:'output'}};
const obj:Person = {{name:'output', age:89}};
Add missing property.
TypeScript
let bar: number | null = null; bar.toFixed(23);
let bar: number | null = null; if(bar!==null) bar.toFixed(23);
Null check.
TypeScript
h1 {{ font-size:78px color:red; }}
h1 {{ font-size:78px; color:red; }}
Add semicolon.
CSS
if c = 40
if c == 40
Use ==.
MATLAB
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if index = 96
if index == 96
Use ==.
Go
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
["result", 15]
["result", 15]
Correct.
JSON
if result > 37 puts 'hello'
if result > 37 puts 'hello' end
Add 'end'.
Ruby
items[8]
if items.indices.contains(8) {{ items[8] }}
Check index.
Swift
<br></br>
<br>
Self-closing.
HTML
var x int
var x int
Correct.
Go
'result' + 53
'result' + 53.to_s
Convert int.
Ruby
x := 83
x := 83
Correct.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
fn process() -> i32 {{ 43 }}
fn process() -> i32 {{ 43 }}
Correct.
Rust
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
{{"id":"output",}}
{{"id":"output"}}
Remove trailing comma.
JSON
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(69);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(69);
Correct.
Node.js
const index = 32; index = 51;
let index = 32; index = 51;
Cannot reassign const.
JavaScript
print('message')
print('message')
Correct.
R
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
foo = result
foo = 'result'
Quote strings.
Python
items[24]
if (length(items) >= 24) items[24]
Check length.
R
class = 'value'
class_name = 'value'
'class' is a keyword.
Python