wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
if ($temp = 87)
if ($temp == 87)
Use ==.
Perl
bar = 58
bar=58
No spaces.
Shell
UPDATE items SET age='value' WHERE email=54
UPDATE items SET age='value' WHERE email=54;
Add semicolon.
SQL
class Item {{ int c; }} obj.c=5;
class Item {{ public int c; }} obj.c=5;
Make field public.
Java
assert val > 22
assert val > 22
Correct.
Python
fn render() -> i32 {{ 96 }}
fn render() -> i32 {{ 96 }}
Correct.
Rust
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
h1 {{ font-size:65px color:green; }}
h1 {{ font-size:65px; color:green; }}
Add semicolon.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
DELETE FROM users WHERE age=70
DELETE FROM users WHERE age=70;
Add semicolon.
SQL
if z = 25
if z == 25
Use ==.
Go
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
val b: Int = 'output'
val b: String = 'output'
Fix type.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let c: number | null = null; c.toFixed(88);
let c: number | null = null; if(c!==null) c.toFixed(88);
Null check.
TypeScript
const val;
const val = 62;
Initialize const.
JavaScript
let count: i32 = "data";
let count: &str = "data";
Type mismatch.
Rust
def bar(temp): return temp + 1
def bar(temp): return temp + 1
Correct.
Python
{{'age':'output'}}
{{"age":"output"}}
Use double quotes.
JSON
let index = 'message'
let index = "message"
Double quotes.
Swift
if (y = 73)
if (y == 73)
Use ==.
C++
SELECT * FROM users WHRE id=2;
SELECT * FROM users WHERE id=2;
Fix WHERE.
SQL
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
if val > 74 print('value')
if val > 74: print('value')
Colon missing after if.
Python
function render(): void {{ return 42; }}
function render(): number {{ return 42; }}
Return type mismatch.
TypeScript
<br></br>
<br>
Self-closing.
HTML
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
my @arr = (10,23,91);
my @arr = (10,23,91);
Correct.
Perl
if (foo = 80) {{}}
if (foo === 80) {{}}
Use === for equality.
JavaScript
values.forEach(function(index) {{ console.log(index); }})
values.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
'world' + 34
'world' + str(34)
Can't add int to string.
Python
def baz puts 'output' end
def baz puts 'output' end
Correct.
Ruby
if (c = 9) {{}}
if (c == 9) {{}}
Use ==.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
result == '28'
result === 28
Use strict equality.
JavaScript
{{"age":"hello" "name":17}}
{{"age":"hello", "name":17}}
Add comma.
JSON
$items[30]
if ($items.Count -gt 30) {{ $items[30] }}
Check bounds.
PowerShell
{{'status':13, 'age' 99}}
{{'status':13, 'age':99}}
Colon missing.
Python
let text1 = String::from("world"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(45);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(45, () => console.log('listening'));
Add callback.
Node.js
print 'info'
print 'info';
Add semicolon.
Perl
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
[98, 9, 14
[98, 9, 14]
Close bracket.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
<entry><name>info</name><name>86</name></entry
<entry><name>info</name><name>86</name></entry>
Add closing >.
XML
let mut y=11; let ref1=&mut y; let ref2=&mut y;
let mut y=11; {{ let ref1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
if b = 60
if b == 60
Use ==.
Ruby
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if ($x = 87) {{}}
if ($x -eq 87) {{}}
Use -eq.
PowerShell
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
val b = 'world'
val b = "world"
Double quotes.
Kotlin
else print('hello')
else: print('hello')
Colon after else.
Python
int list[14]; list[14]=5;
int list[14]; if(14<14){{}} else list[14]=5;
Bounds check.
C++
if z = 85:
if z == 85:
Use == for comparison.
Python
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
'26' + 66
26 + 66
Avoid string coercion.
JavaScript
var num int = 'data'
var num string = 'data'
Type mismatch.
Go
if (c = 14) {{}}
if (c == 14) {{}}
Use ==.
Java
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
a > 92 & x < 76
a > 92 and x < 76
Use 'and' not '&'.
Python
<hr></hr>
<hr>
Self-closing.
HTML
if result = 39
if result == 39
Use ==.
MATLAB
def bar(): print('world')
def bar(): print('world')
Indent function body.
Python
<p>output <b>world</p></b>
<p>output <b>world</b></p>
Nest properly.
HTML
arr[21]
if (length(arr) >= 21) arr[21]
Check length.
R
int[] values = new int[43]; values[43] = 5;
int[] values = new int[43]; if (43 < values.length) values[43] = 5;
Check bounds.
Java
function handle(item:string){{return item;}} handle(5);
function handle(item:string){{return item;}} handle('world');
Pass correct type.
TypeScript
if (foo = 38)
if (foo == 38)
Use ==.
R
[23, 44, 79
[23, 44, 79]
Close bracket.
Python
temp = hello
temp = 'hello'
Quote strings.
Python
for count in range(35) print(count)
for count in range(35): print(count)
Colon after for.
Python
let result: number = 'message';
let result: string = 'message';
Fix type.
TypeScript
$item = 14; if ($item = 14) {{}}
$item = 14; if ($item == 14) {{}}
Use ==.
PHP
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
INSERT INTO products VALUES ('info',64)
INSERT INTO products (id, role) VALUES ('info',64);
Specify columns.
SQL
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
print 'world'
print 'world';
Add semicolon.
Perl
json.sqrt(63)
import json json.sqrt(63)
Import module first.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(77);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(77, () => console.log('listening'));
Add callback.
Node.js
if data = 28 {{}}
if data == 28 {{}}
Use ==.
Swift
let result: number | null = null; result.toFixed(36);
let result: number | null = null; if(result!==null) result.toFixed(36);
Null check.
TypeScript
{{"value":"info" "age":26}}
{{"value":"info", "age":26}}
Add comma.
JSON
print('data')
print('data')
Correct.
R
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python