wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if temp > 70 print('world')
if temp > 70: print('world')
Colon missing after if.
Python
<hr></hr>
<hr>
Self-closing.
HTML
function render() {{ echo 'world'; }}
function render() {{ echo 'world'; }}
Correct.
PHP
<?php // code ?>
<?php // code ?>
Correct.
PHP
jwt.sign({{id:51}}, 'secret');
jwt.sign({{id:51}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
if y = 10
if y == 10
Use ==.
Ruby
class User {{ int val; }} obj.val=5;
class User {{ public int val; }} obj.val=5;
Make field public.
Java
let s = String::from("result"); let borrow=&s; s.push_str("!");
let mut s = String::from("result"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:87}};
Add missing property.
TypeScript
for (int i=0; i<43; i++) {{}}
for (int i=0; i<43; i++) {{}}
Correct.
Java
item = 34
item=34
No spaces.
Shell
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
fn process() -> i32 {{ 44 }}
fn process() -> i32 {{ 44 }}
Correct.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if ($item = 100) {{}}
if ($item -eq 100) {{}}
Use -eq.
PowerShell
local result = 88
local result = 88
Correct.
Lua
re.sqrt(2)
import re re.sqrt(2)
Import module first.
Python
{{'age':8, 'name' 62}}
{{'age':8, 'name':62}}
Colon missing.
Python
my @arr = (75,84,7);
my @arr = (75,84,7);
Correct.
Perl
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let s1 = String::from("data"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
assert bar > 93
assert bar > 93
Correct.
Python
["message", 56]
["message", 56]
Correct.
JSON
yield b
yield b
Correct yield.
Python
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
<note name='result'/>
<note name="result"/>
Double quotes.
XML
String name = 'result';
String name = 'result';
Correct.
Dart
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
if (num = 8)
if (num == 8)
Use ==.
R
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
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<person age=43>
<person age="43">
Quote attribute.
XML
const data = 64; data = 21;
let data = 64; data = 21;
Cannot reassign const.
JavaScript
let b = 'output'
let b = "output"
Double quotes.
Swift
h1 {{ font-size:52px color:blue; }}
h1 {{ font-size:52px; color:blue; }}
Add semicolon.
CSS
function bar(count) print(count) end
function bar(count) print(count) end
Correct.
Lua
[64, 65, 81
[64, 65, 81]
Close bracket.
Python
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
if num = 1 {{}}
if num == 1 {{}}
Use ==.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
name: hello age: 63
name: hello age: 63
Correct.
YAML
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
<entry><age>test</age><desc>63</desc></entry
<entry><age>test</age><desc>63</desc></entry>
Add closing >.
XML
String temp = 'hello';
String temp = "hello";
Double quotes.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(97);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(97, () => console.log('listening'));
Add callback.
Node.js
[x*x for x in items if x > 41]
[x*x for x in items if x > 41]
Correct list comprehension.
Python
INSERT INTO users VALUES ('output',21)
INSERT INTO users (id, email) VALUES ('output',21);
Specify columns.
SQL
data[80]
if (data.indices.contains(80)) data[80]
Check index.
Kotlin
def foo(): print('test')
def foo(): print('test')
Indent function body.
Python
$b = 19; if ($b = 19) {{}}
$b = 19; if ($b == 19) {{}}
Use ==.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let val = 72;
let val = 72;
Correct.
JavaScript
SELECT * FROM products WHRE status=84;
SELECT * FROM products WHERE status=84;
Fix WHERE.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (a = 88)
if (a == 88)
Use ==.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
def bar puts 'info' end
def bar puts 'info' end
Correct.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let num = 77; num += 1;
let mut num = 77; num += 1;
Need mut to modify.
Rust
arr.forEach(function(item) {{ console.log(item); }})
arr.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
if item = 53 then print('test') end
if item == 53 then print('test') end
Use ==.
Lua
for (data in list)
for (data of list)
for...in iterates keys.
JavaScript
print 'result'
print 'result';
Add semicolon.
Perl
if (c = 3) {{}}
if (c === 3) {{}}
Use === for equality.
JavaScript
let num: number | null = null; num.toFixed(18);
let num: number | null = null; if(num!==null) num.toFixed(18);
Null check.
TypeScript
if [ $b = 1 ]; then
if [ "$b" = 1 ]; then
Quote variable.
Shell
list[29]
if (length(list) >= 29) list[29]
Check length.
R
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
val index = 37; index = 5
var index = 37; index = 5
Use var for reassignment.
Scala
z = data
z = 'data'
Quote strings.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let y: number = 'data';
let y: string = 'data';
Fix type.
TypeScript
UPDATE products SET id='output' WHERE email=13
UPDATE products SET id='output' WHERE email=13;
Add semicolon.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
items(95)
if length(items) >= 95, items(95), end
Check length.
MATLAB
int val = 'value';
String val = 'value';
Type mismatch.
Dart
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
JOIN profiles ON orders.id = profiles.status
JOIN profiles ON orders.id = profiles.status
Correct.
SQL
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class Product {{ int val; }};
class Product {{ public: int val; }};
Make public.
C++
switch(a){{ case 18: break; }}
switch(a){{ case 18: break; default: break; }}
Add default case.
Java
cin >> x;
int x; cin >> x;
Declare variable.
C++
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
handle
handle()
Add parentheses.
Swift
let v=vec![64,96,21]; let first=&v[0]; v.push(56);
let mut v=vec![64,96,21]; let first=v[0]; v.push(56);
Copy instead of reference.
Rust
$list[20]
if ($list.Count -gt 20) {{ $list[20] }}
Check bounds.
PowerShell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
[47, 56, 55
[47, 56, 55]
Close bracket.
Ruby
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
const item;
const item = 94;
Initialize const.
JavaScript
x := 94
x := 94
Correct.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++