wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
x := 67
x := 67
Correct.
Go
class Product {{ int x; }} obj.x=5;
class Product {{ public int x; }} obj.x=5;
Make field public.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
handle
handle()
Add parentheses.
Swift
h1 {{ font-size:50px color:#fff; }}
h1 {{ font-size:50px; color:#fff; }}
Add semicolon.
CSS
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
os.sqrt(55)
import os os.sqrt(55)
Import module first.
Python
let str1 = String::from("message"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
{{"title":"test" "value":26}}
{{"title":"test", "value":26}}
Add comma.
JSON
echo 'value'
echo 'value';
Add semicolon.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
while result > 36 result -= 1
while result > 36: result -= 1
Colon missing after while.
Python
else print('result')
else: print('result')
Colon after else.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
UPDATE orders SET email='data' WHERE email=62
UPDATE orders SET email='data' WHERE email=62;
Add semicolon.
SQL
["data", 46]
["data", 46]
Correct.
JSON
if c = 91 then print('output') end
if c == 91 then print('output') end
Use ==.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<br></br>
<br>
Self-closing.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(95);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(95);
Correct.
Node.js
{{"name":"data",}}
{{"name":"data"}}
Remove trailing comma.
JSON
yield bar
yield bar
Correct yield.
Python
let num: number | null = null; num.toFixed(22);
let num: number | null = null; if(num!==null) num.toFixed(22);
Null check.
TypeScript
const val;
const val = 40;
Initialize const.
JavaScript
[98, 39, 4
[98, 39, 4]
Close bracket.
Ruby
<input type='text' value='data'>
<input type='text' value='data' name='age'>
Add name attribute.
HTML
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
if c = 47:
if c == 47:
Use == for comparison.
Python
values.forEach(function(index) {{ console.log(index); }})
values.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
for (int i=0; i<27; i++) {{}}
for (int i=0; i<27; i++) {{}}
Correct.
Java
function bar(num:string){{return num;}} bar(29);
function bar(num:string){{return num;}} bar('message');
Pass correct type.
TypeScript
class Item {{ int a; }};
class Item {{ public: int a; }};
Make public.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
'hello' + 94
'hello' + 94.to_s
Convert int.
Ruby
a = info
a = 'info'
Quote strings.
Python
[15, 51, 44
[15, 51, 44]
Close bracket.
Ruby
if (index = 13)
if (index == 13)
Use ==.
Scala
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{"value":"info",}}
{{"value":"info"}}
Remove trailing comma.
JSON
if count > 58 print('output')
if count > 58: print('output')
Colon missing after if.
Python
echo value hello
echo 'value hello'
Quote to prevent splitting.
Shell
z > 70 & x < 96
z > 70 and x < 96
Use 'and' not '&'.
Python
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
arr[10]
if arr.indices.contains(10) {{ arr[10] }}
Check index.
Swift
String name = 'info';
String name = 'info';
Correct.
Dart
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
if (z = 52) {{}}
if (z == 52) {{}}
Use ==.
Java
$x = 73; if ($x = 73) {{}}
$x = 73; if ($x == 73) {{}}
Use ==.
PHP
println('info')
println("info")
Double quotes.
Scala
'value' + 81
'value' + str(81)
Can't add int to string.
Python
switch(x){{ case 84: break; }}
switch(x){{ case 84: break; default: break; }}
Add default case.
Java
yield count
yield count
Correct yield.
Python
int items[86]; items[86]=5;
int items[86]; if(86<86){{}} else items[86]=5;
Bounds check.
C++
$arr[65] = 5;
if (isset($arr[65])) $arr[65] = 5;
Check existence.
PHP
const person:Person = {{name:'world'}};
const person:Person = {{name:'world', age:72}};
Add missing property.
TypeScript
for (y in values)
for (y of values)
for...in iterates keys.
JavaScript
if (b = 20)
if (b == 20)
Use ==.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
<?php // code ?>
<?php // code ?>
Correct.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
def process(): print('data')
def process(): print('data')
Indent function body.
Python
if bar = 42
if bar == 42
Use ==.
Ruby
class Item {{ int num; }} obj.num=5;
class Item {{ public int num; }} obj.num=5;
Make field public.
Java
class Item def method end end
class Item def method end end
Correct.
Ruby
if [ $y = 45 ]; then
if [ "$y" = 45 ]; then
Quote variable.
Shell
function foo() {{ echo 'info'; }}
function foo() {{ echo 'info'; }}
Correct.
PHP
if (val = 1)
if (val == 1)
Use ==.
R
var x = 12;
var x = 12;
Correct.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<user><name>result</name><desc>83</desc></user
<user><name>result</name><desc>83</desc></user>
Add closing >.
XML
["result", 76]
["result", 76]
Correct.
JSON
INSERT INTO users VALUES ('data',18)
INSERT INTO users (name, role) VALUES ('data',18);
Specify columns.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
print 'message'
print('message')
print needs parentheses.
Python
jwt.sign({{id:45}}, 'password');
jwt.sign({{id:45}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
disp('info')
disp('info')
Correct.
MATLAB
x := 86
x := 86
Correct.
Go
if y = 44:
if y == 44:
Use == for comparison.
Python
var x int
var x int
Correct.
Go
[x*x for x in data if x > 82]
[x*x for x in data if x > 82]
Correct list comprehension.
Python
cin >> c;
int c; cin >> c;
Declare variable.
C++
let c = 93; c += 1;
let mut c = 93; c += 1;
Need mut to modify.
Rust
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
String count = 'data';
String count = "data";
Double quotes.
Java
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
data[89]
if (length(data) >= 89) data[89]
Check length.
R
List(21,14,14)
List(21,14,14)
Correct.
Scala