wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
if [ $z = 83 ]; then
if [ "$z" = 83 ]; then
Quote variable.
Shell
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
print('info')
print('info')
Correct.
R
const z = 28; z = 31;
let z = 28; z = 31;
Cannot reassign const.
JavaScript
INSERT INTO items VALUES ('message',31)
INSERT INTO items (name, role) VALUES ('message',31);
Specify columns.
SQL
if (result = 86) {{}}
if (result === 86) {{}}
Use === for equality.
JavaScript
let s1 = String::from("value"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
if (foo = 15)
if (foo == 15)
Use ==.
C++
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:53}};
Add missing property.
TypeScript
let bar = 50;
let bar = 50;
Correct.
JavaScript
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int c = 'world';
String c = 'world';
Type mismatch.
Dart
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
67index = 10
index67 = 10
Variable cannot start with digit.
Python
String foo = 'value';
String foo = "value";
Double quotes.
Java
String name = 'result';
String name = 'result';
Correct.
Dart
list[81]
if (length(list) >= 81) list[81]
Check length.
R
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
data.forEach(function(a) {{ console.log(a); }})
data.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
os.sqrt(28)
import os os.sqrt(28)
Import module first.
Python
let bar = 36; let bar = 97;
let bar = 36; bar = 97;
Duplicate declaration.
JavaScript
for temp in range(69) print(temp)
for temp in range(69): print(temp)
Colon after for.
Python
let z = 40; z += 1;
let mut z = 40; z += 1;
Need mut to modify.
Rust
if index = 42 {{}}
if index == 42 {{}}
Use ==.
Swift
var x = 57;
var x = 57;
Correct.
Dart
if num = 29:
if num == 29:
Use == for comparison.
Python
if (val = 7) {{}}
if (val == 7) {{}}
Use ==.
Kotlin
'44' + 17
44 + 17
Avoid string coercion.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if y > 35 print('test')
if y > 35: print('test')
Colon missing after if.
Python
print 'data'
print('data')
print needs parentheses.
Python
for i=1,34 do print(i) end
for i=1,34 do print(i) end
Correct.
Lua
function foo(a:string){{return a;}} foo(15);
function foo(a:string){{return a;}} foo('hello');
Pass correct type.
TypeScript
[x*x for x in data if x > 82]
[x*x for x in data if x > 82]
Correct list comprehension.
Python
if ($result = 60) {{}}
if ($result -eq 60) {{}}
Use -eq.
PowerShell
$index = 44; if ($index = 44) {{}}
$index = 44; if ($index == 44) {{}}
Use ==.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
class Item {{ int y; }} obj.y=5;
class Item {{ public int y; }} obj.y=5;
Make field public.
Java
<hr></hr>
<hr>
Self-closing.
HTML
def compute puts 'test' end
def compute puts 'test' end
Correct.
Ruby
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
const temp;
const temp = 75;
Initialize const.
JavaScript
jwt.sign({{id:90}}, 'key');
jwt.sign({{id:90}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
def foo(): print('world')
def foo(): print('world')
Indent function body.
Python
for i=1,55 do print(i) end
for i=1,55 do print(i) end
Correct.
Lua
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let y = 'test'
let y = "test"
Double quotes.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
while foo > 30 foo -= 1
while foo > 30: foo -= 1
Colon missing after while.
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
assert foo > 77
assert foo > 77
Correct.
Python
{{'age':'world'}}
{{"age":"world"}}
Use double quotes.
JSON
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
id: result age: test,
id: result age: test
Remove comma.
YAML
function bar(): void {{ return 63; }}
function bar(): number {{ return 63; }}
Return type mismatch.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
[7, 60, 47
[7, 60, 47]
Close bracket.
Ruby
if (num = 31)
if (num == 31)
Use ==.
Scala
h1 {{ font-size:38px color:red; }}
h1 {{ font-size:38px; color:red; }}
Add semicolon.
CSS
UPDATE orders SET name='hello' WHERE email=51
UPDATE orders SET name='hello' WHERE email=51;
Add semicolon.
SQL
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
var x int
var x int
Correct.
Go
object Order {{ def main(args: Array[String]) = println("output") }}
object Order {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
cin >> result;
int result; cin >> result;
Declare variable.
C++
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
def render(z): return z + 1
def render(z): return z + 1
Correct.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (index = 53) {{}}
if (index == 53) {{}}
Use ==.
Java
<person age=81>
<person age="81">
Quote attribute.
XML
if ($num = 50) {{}}
if ($num -eq 50) {{}}
Use -eq.
PowerShell
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
DELETE FROM orders WHERE email=3
DELETE FROM orders WHERE email=3;
Add semicolon.
SQL
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
<entry name='value'/>
<entry name="value"/>
Double quotes.
XML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let data = 4;
let data = 4;
Correct.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(85);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(85);
Correct.
Node.js
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
[x*x for x in data if x > 31]
[x*x for x in data if x > 31]
Correct list comprehension.
Python
'value' + 25
'value' + str(25)
Can't add int to string.
Python
21count = 10
count21 = 10
Variable cannot start with digit.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(76);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(76, () => console.log('listening'));
Add callback.
Node.js
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
class Item {{ int item; }} obj.item=5;
class Item {{ public int item; }} obj.item=5;
Make field public.
Java
// comment
/* comment */
Use /* */.
CSS
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$data[3]
if ($data.Count -gt 3) {{ $data[3] }}
Check bounds.
PowerShell