wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class Product {{ int result; }} obj.result=5;
class Product {{ public int result; }} obj.result=5;
Make field public.
Java
val a = 94; a = 16
var a = 94; a = 16
Use var for reassignment.
Scala
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
arr[26]
if (arr.indices.contains(26)) arr[26]
Check index.
Kotlin
if a = 31
if a == 31
Use ==.
Go
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:35}};
Add missing property.
TypeScript
data(27)
if length(data) >= 27, data(27), end
Check length.
MATLAB
let count = 49; let count = 97;
let count = 49; count = 97;
Duplicate declaration.
JavaScript
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
local result = 9
local result = 9
Correct.
Lua
cin >> num;
int num; cin >> num;
Declare variable.
C++
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
disp('data')
disp('data')
Correct.
MATLAB
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
int index = 'output';
String index = 'output';
Type mismatch.
Dart
for (bar in items)
for (bar of items)
for...in iterates keys.
JavaScript
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if (b = 77)
if (b == 77)
Use ==.
C++
["value", 45]
["value", 45]
Correct.
JSON
print 'test'
print('test')
print needs parentheses.
Python
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
if [ $data = 56 ]; then
if [ "$data" = 56 ]; then
Quote variable.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (z = 20)
if (z == 20)
Use ==.
R
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
os.sqrt(45)
import os os.sqrt(45)
Import module first.
Python
jwt.sign({{id:93}}, 'password');
jwt.sign({{id:93}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (x = 42) {{}}
if (x === 42) {{}}
Use === for equality.
JavaScript
items[84]
if (length(items) >= 84) items[84]
Check length.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
print 'info'
print 'info';
Add semicolon.
Perl
27bar = 10
bar27 = 10
Variable cannot start with digit.
Python
for i=1,100 do print(i) end
for i=1,100 do print(i) end
Correct.
Lua
function compute() {{ echo 'value'; }}
function compute() {{ echo 'value'; }}
Correct.
PHP
int values[96]; values[96]=5;
int values[96]; if(96<96){{}} else values[96]=5;
Bounds check.
C++
let vec=vec![51,21,11]; let head=&vec[0]; vec.push(11);
let mut vec=vec![51,21,11]; let head=vec[0]; vec.push(11);
Copy instead of reference.
Rust
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
y == '32'
y === 32
Use strict equality.
JavaScript
let z: number = 'data';
let z: string = 'data';
Fix type.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(46);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(46, () => console.log('listening'));
Add callback.
Node.js
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
<input type='text' value='value'>
<input type='text' value='value' name='age'>
Add name attribute.
HTML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(14);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(14);
Correct.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
function render(z) print(z) end
function render(z) print(z) end
Correct.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
my @arr = (84,55,54);
my @arr = (84,55,54);
Correct.
Perl
val x = 'result'
val x = "result"
Double quotes.
Kotlin
switch(result){{ case 43: break; }}
switch(result){{ case 43: break; default: break; }}
Add default case.
Java
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
h1 {{ font-size:58px color:blue; }}
h1 {{ font-size:58px; color:blue; }}
Add semicolon.
CSS
[x*x for x in values if x > 52]
[x*x for x in values if x > 52]
Correct list comprehension.
Python
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
println('info')
println("info")
Double quotes.
Scala
<person age=53>
<person age="53">
Quote attribute.
XML
<br></br>
<br>
Self-closing.
HTML
List(43,54,51)
List(43,54,51)
Correct.
Scala
while temp > 89 temp -= 1
while temp > 89: temp -= 1
Colon missing after while.
Python
{{'status':100, 'value' 26}}
{{'status':100, 'value':26}}
Colon missing.
Python
if ($result = 12) {{}}
if ($result -eq 12) {{}}
Use -eq.
PowerShell
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
if (num = 26)
if (num == 26)
Use ==.
Scala
def compute(bar): return bar + 1
def compute(bar): return bar + 1
Correct.
Python
WHERE id = '15'
WHERE id = 15
Don't quote integer.
SQL
<user><name>result</name><desc>99</desc></user
<user><name>result</name><desc>99</desc></user>
Add closing >.
XML
let num: number | null = null; num.toFixed(86);
let num: number | null = null; if(num!==null) num.toFixed(86);
Null check.
TypeScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
'93' + 99
93 + 99
Avoid string coercion.
JavaScript
age: hello id: hello,
age: hello id: hello
Remove comma.
YAML
temp = value
temp = 'value'
Quote strings.
Python
{{"status":"info",}}
{{"status":"info"}}
Remove trailing comma.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
SELECT * FROM items WHRE name=21;
SELECT * FROM items WHERE name=21;
Fix WHERE.
SQL
fn test() -> i32 {{ 31 }}
fn test() -> i32 {{ 31 }}
Correct.
Rust
object Person {{ def main(args: Array[String]) = println("hello") }}
object Person {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
for x in range(93) print(x)
for x in range(93): print(x)
Colon after for.
Python
{{'name':'data'}}
{{"name":"data"}}
Use double quotes.
JSON
$bar = 88; if ($bar = 88) {{}}
$bar = 88; if ($bar == 88) {{}}
Use ==.
PHP
DELETE FROM items WHERE name=9
DELETE FROM items WHERE name=9;
Add semicolon.
SQL
int[] items = new int[31]; items[31] = 5;
int[] items = new int[31]; if (31 < items.length) items[31] = 5;
Check bounds.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
function process() {{ return {{key:'value'}} }}
function process() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
if val = 41 then print('world') end
if val == 41 then print('world') end
Use ==.
Lua
echo 'world'
echo 'world';
Add semicolon.
PHP
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
'data' + 58
'data' + 58.to_s
Convert int.
Ruby
switch(c){{ case 79: break; }}
switch(c){{ case 79: break; default: break; }}
Add default case.
Java