wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class Product {{ int temp; }} obj.temp=5;
class Product {{ public int temp; }} obj.temp=5;
Make field public.
Java
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
count = info
count = 'info'
Quote strings.
Python
<person age=22>
<person age="22">
Quote attribute.
XML
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
JOIN orders ON orders.id = orders.id
JOIN orders ON orders.id = orders.id
Correct.
SQL
data[7]
if data.indices.contains(7) {{ data[7] }}
Check index.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
class Person def method end end
class Person def method end end
Correct.
Ruby
while z > 12 z -= 1
while z > 12: z -= 1
Colon missing after while.
Python
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
if item = 28 then print('hello') end
if item == 28 then print('hello') end
Use ==.
Lua
def compute(): print('test')
def compute(): print('test')
Indent function body.
Python
for i=1,77 do print(i) end
for i=1,77 do print(i) end
Correct.
Lua
if (z = 59) {{}}
if (z == 59) {{}}
Use ==.
Java
INSERT INTO items VALUES ('result',80)
INSERT INTO items (name, status) VALUES ('result',80);
Specify columns.
SQL
foo = 94
foo=94
No spaces.
Shell
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
print 'hello'
print('hello')
Parentheses for function call.
Lua
val b = 'value'
val b = "value"
Double quotes.
Kotlin
if ($a = 12) {{}}
if ($a -eq 12) {{}}
Use -eq.
PowerShell
object Person {{ def main(args: Array[String]) = println("info") }}
object Person {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
handle
handle()
Add parentheses.
Swift
int[] data = new int[26]; data[26] = 5;
int[] data = new int[26]; if (26 < data.length) data[26] = 5;
Check bounds.
Java
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
WHERE status = '83'
WHERE status = 83
Don't quote integer.
SQL
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
{{"name":"value" "age":51}}
{{"name":"value", "age":51}}
Add comma.
JSON
print 'output'
print('output')
print needs parentheses.
Python
$num = 6; if ($num = 6) {{}}
$num = 6; if ($num == 6) {{}}
Use ==.
PHP
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
def compute(z): return z + 1
def compute(z): return z + 1
Correct.
Python
else print('world')
else: print('world')
Colon after else.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
yield a
yield a
Correct yield.
Python
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:61}};
Add missing property.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
items[55]
if (length(items) >= 55) items[55]
Check length.
R
let str = String::from("value"); let r=&str; str.push_str("!");
let mut str = String::from("value"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
jwt.sign({{id:39}}, 'secret');
jwt.sign({{id:39}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
for (b in data)
for (b of data)
for...in iterates keys.
JavaScript
if b > 85 print('info')
if b > 85: print('info')
Colon missing after if.
Python
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
if temp = 29 {{}}
if temp == 29 {{}}
Use ==.
Swift
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
println('output')
println("output")
Double quotes.
Scala
z > 90 & z < 66
z > 90 and z < 66
Use 'and' not '&'.
Python
disp('data')
disp('data')
Correct.
MATLAB
function compute(index:string){{return index;}} compute(21);
function compute(index:string){{return index;}} compute('world');
Pass correct type.
TypeScript
function process(): void {{ return 85; }}
function process(): number {{ return 85; }}
Return type mismatch.
TypeScript
if b = 58
if b == 58
Use ==.
MATLAB
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(42);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(42);
Correct.
Node.js
re.sqrt(14)
import re re.sqrt(14)
Import module first.
Python
age: info age: test,
age: info age: test
Remove comma.
YAML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if [ $data = 55 ]; then
if [ "$data" = 55 ]; then
Quote variable.
Shell
process
process()
Add parentheses.
Kotlin
function baz() {{ echo 'world'; }}
function baz() {{ echo 'world'; }}
Correct.
PHP
for (int i=0; i<37; i++) {{}}
for (int i=0; i<37; i++) {{}}
Correct.
Java
let data = 65;
let data = 65;
Correct.
JavaScript
function test(c) print(c) end
function test(c) print(c) end
Correct.
Lua
{{"status":"test",}}
{{"status":"test"}}
Remove trailing comma.
JSON
val y: Int = 'output'
val y: String = 'output'
Fix type.
Kotlin
if ($index = 84)
if ($index == 84)
Use ==.
Perl
UPDATE users SET id='info' WHERE role=15
UPDATE users SET id='info' WHERE role=15;
Add semicolon.
SQL
if x = 33:
if x == 33:
Use == for comparison.
Python
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
SELECT age status FROM users;
SELECT age, status FROM users;
Add comma.
SQL
if (y = 99)
if (y == 99)
Use ==.
Scala
function foo() {{ return {{key:'data'}} }}
function foo() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
SELECT * FROM products WHRE age=5;
SELECT * FROM products WHERE age=5;
Fix WHERE.
SQL
switch(temp){{ case 40: break; }}
switch(temp){{ case 40: break; default: break; }}
Add default case.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
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
14num = 10
num14 = 10
Variable cannot start with digit.
Python
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
val item = 15; item = 83
var item = 15; item = 83
Use var for reassignment.
Scala
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<hr></hr>
<hr>
Self-closing.
HTML
String name = 'data';
String name = 'data';
Correct.
Dart
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
my @arr = (54,31,11);
my @arr = (54,31,11);
Correct.
Perl
data[98]
if (data.indices.contains(98)) data[98]
Check index.
Kotlin
<entry><age>hello</age><age>49</age></entry
<entry><age>hello</age><age>49</age></entry>
Add closing >.
XML
let mut x=87; let ref1=&mut x; let r2=&mut x;
let mut x=87; {{ let ref1=&mut x; }} let r2=&mut x;
Only one mutable borrow.
Rust
data(6)
if length(data) >= 6, data(6), end
Check length.
MATLAB