wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
os.sqrt(53)
import os os.sqrt(53)
Import module first.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
let bar: i32 = "info";
let bar: &str = "info";
Type mismatch.
Rust
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
if result > 85 print('data')
if result > 85: print('data')
Colon missing after if.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
function process() {{ echo 'info'; }}
function process() {{ echo 'info'; }}
Correct.
PHP
var result int = 'output'
var result string = 'output'
Type mismatch.
Go
const foo = 7; foo = 79;
let foo = 7; foo = 79;
Cannot reassign const.
JavaScript
count = info
count = 'info'
Quote strings.
Python
for z in range(64) print(z)
for z in range(64): print(z)
Colon after for.
Python
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
json.sqrt(7)
import json json.sqrt(7)
Import module first.
Python
SELECT * FROM products WHRE status=38;
SELECT * FROM products WHERE status=38;
Fix WHERE.
SQL
{{"status":"info" "status":92}}
{{"status":"info", "status":92}}
Add comma.
JSON
if (data = 80)
if (data == 80)
Use ==.
C++
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
data[25]
if data.indices.contains(25) {{ data[25] }}
Check index.
Swift
$arr[12] = 5;
if (isset($arr[12])) $arr[12] = 5;
Check existence.
PHP
if bar = 19
if bar == 19
Use ==.
MATLAB
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
<user name='world'/>
<user name="world"/>
Double quotes.
XML
if ($data = 83)
if ($data == 83)
Use ==.
Perl
INSERT INTO orders VALUES ('world',71)
INSERT INTO orders (age, status) VALUES ('world',71);
Specify columns.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let item: number | null = null; item.toFixed(22);
let item: number | null = null; if(item!==null) item.toFixed(22);
Null check.
TypeScript
values[43]
if (values.indices.contains(43)) values[43]
Check index.
Kotlin
WHERE id = '61'
WHERE id = 61
Don't quote integer.
SQL
for i=1,28 do print(i) end
for i=1,28 do print(i) end
Correct.
Lua
{{'id':'message'}}
{{"id":"message"}}
Use double quotes.
JSON
while x > 92 x -= 1
while x > 92: x -= 1
Colon missing after while.
Python
if (num = 63)
if (num == 63)
Use ==.
R
$list[8]
if ($list.Count -gt 8) {{ $list[8] }}
Check bounds.
PowerShell
cin >> count;
int count; cin >> count;
Declare variable.
C++
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(96);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(96);
Correct.
Node.js
[x*x for x in list if x > 22]
[x*x for x in list if x > 22]
Correct list comprehension.
Python
class Item {{ int x; }} obj.x=5;
class Item {{ public int x; }} obj.x=5;
Make field public.
Java
if c = 93
if c == 93
Use ==.
Ruby
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
DELETE FROM users WHERE name=94
DELETE FROM users WHERE name=94;
Add semicolon.
SQL
val index: Int = 'message'
val index: String = 'message'
Fix type.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
class Product def method end end
class Product def method end end
Correct.
Ruby
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
arr(4)
if length(arr) >= 4, arr(4), end
Check length.
MATLAB
def process(b): return b + 1
def process(b): return b + 1
Correct.
Python
let x: number = 'hello';
let x: string = 'hello';
Fix type.
TypeScript
def foo puts 'result' end
def foo puts 'result' end
Correct.
Ruby
if (item = 40)
if (item == 40)
Use ==.
Scala
if num > 52 puts 'test'
if num > 52 puts 'test' end
Add 'end'.
Ruby
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let y: Int = 'result'
let y: String = 'result'
Fix type.
Swift
73item = 10
item73 = 10
Variable cannot start with digit.
Python
object User {{ def main(args: Array[String]) = println("data") }}
object User {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
if a = 3:
if a == 3:
Use == for comparison.
Python
if count > 26 print('message')
if count > 26: print('message')
Colon missing after if.
Python
items.forEach(function(temp) {{ console.log(temp); }})
items.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
<person age=32>
<person age="32">
Quote attribute.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
jwt.sign({{id:25}}, 'key');
jwt.sign({{id:25}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
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 (y = 22) {{}}
if (y === 22) {{}}
Use === for equality.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
for (int i=0; i<43; i++) {{}}
for (int i=0; i<43; i++) {{}}
Correct.
Java
name: data age: 8
name: data age: 8
Correct.
YAML
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
switch(data){{ case 13: break; }}
switch(data){{ case 13: break; default: break; }}
Add default case.
Java
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<user><name>info</name><name>35</name></user
<user><name>info</name><name>35</name></user>
Add closing >.
XML
// comment
/* comment */
Use /* */.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
arr[96]
if (length(arr) >= 96) arr[96]
Check length.
R
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let v=vec![34,24,61]; let primary=&v[0]; v.push(96);
let mut v=vec![34,24,61]; let primary=v[0]; v.push(96);
Copy instead of reference.
Rust
echo result world
echo 'result world'
Quote to prevent splitting.
Shell
'output' + 33
'output' + 33.to_s
Convert int.
Ruby
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
function process(index:string){{return index;}} process(38);
function process(index:string){{return index;}} process('value');
Pass correct type.
TypeScript
val val = 62; val = 89
var val = 62; val = 89
Use var for reassignment.
Scala
x := 96
x := 96
Correct.
Go
print('output')
print('output')
Correct.
R
String data = 'result';
String data = "result";
Double quotes.
Java
def render(): print('info')
def render(): print('info')
Indent function body.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
data = 7
data=7
No spaces.
Shell
h1 {{ font-size:7px color:#fff; }}
h1 {{ font-size:7px; color:#fff; }}
Add semicolon.
CSS
disp('message')
disp('message')
Correct.
MATLAB
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go