wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
disp('world')
disp('world')
Correct.
MATLAB
var index int = 'output'
var index string = 'output'
Type mismatch.
Go
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
baz
baz()
Add parentheses.
Kotlin
val val: Int = 'info'
val val: String = 'info'
Fix type.
Kotlin
if (y = 92)
if (y == 92)
Use ==.
C++
c = 94
c=94
No spaces.
Shell
class User {{ int val; }} obj.val=5;
class User {{ public int val; }} obj.val=5;
Make field public.
Java
values[86]
if (values.indices.contains(86)) values[86]
Check index.
Kotlin
let c: i32 = "output";
let c: &str = "output";
Type mismatch.
Rust
data[3]
if (length(data) >= 3) data[3]
Check length.
R
if (c = 6) {{}}
if (c == 6) {{}}
Use ==.
Kotlin
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
for (bar in arr)
for (bar of arr)
for...in iterates keys.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
else print('hello')
else: print('hello')
Colon after else.
Python
WHERE status = '54'
WHERE status = 54
Don't quote integer.
SQL
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
if data = 18 {{}}
if data == 18 {{}}
Use ==.
Swift
function baz() {{ echo 'hello'; }}
function baz() {{ echo 'hello'; }}
Correct.
PHP
print 'world'
print('world')
print needs parentheses.
Python
let mut num=77; let ref1=&mut num; let ref2=&mut num;
let mut num=77; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
if ($count = 47)
if ($count == 47)
Use ==.
Perl
<br></br>
<br>
Self-closing.
HTML
SELECT * FROM orders WHRE age=23;
SELECT * FROM orders WHERE age=23;
Fix WHERE.
SQL
my @arr = (54,43,86);
my @arr = (54,43,86);
Correct.
Perl
["result", 69]
["result", 69]
Correct.
JSON
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if x = 77
if x == 77
Use ==.
MATLAB
INSERT INTO products VALUES ('hello',40)
INSERT INTO products (age, role) VALUES ('hello',40);
Specify columns.
SQL
print 'hello'
print 'hello';
Add semicolon.
Perl
x = test
x = 'test'
Quote strings.
Python
print('info')
print('info')
Correct.
R
def render(): print('message')
def render(): print('message')
Indent function body.
Python
else print('value')
else: print('value')
Colon after else.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
{{"value":"result" "name":45}}
{{"value":"result", "name":45}}
Add comma.
JSON
var c int = 'message'
var c string = 'message'
Type mismatch.
Go
h1 {{ font-size:80px color:red; }}
h1 {{ font-size:80px; color:red; }}
Add semicolon.
CSS
if b = 59:
if b == 59:
Use == for comparison.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
int values[100]; values[100]=5;
int values[100]; if(100<100){{}} else values[100]=5;
Bounds check.
C++
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(30);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(30, () => console.log('listening'));
Add callback.
Node.js
def bar(item): return item + 1
def bar(item): return item + 1
Correct.
Python
z > 96 & a < 6
z > 96 and a < 6
Use 'and' not '&'.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
cin >> item;
int item; cin >> item;
Declare variable.
C++
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:54}};
Add missing property.
TypeScript
render
render()
Add parentheses.
Kotlin
for (int i=0; i<59; i++) {{}}
for (int i=0; i<59; i++) {{}}
Correct.
Java
{{'name':'info'}}
{{"name":"info"}}
Use double quotes.
JSON
let str1 = String::from("hello"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
let count = 69;
let count = 69;
Correct.
JavaScript
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
UPDATE items SET id='data' WHERE status=83
UPDATE items SET id='data' WHERE status=83;
Add semicolon.
SQL
let val = 'world'
let val = "world"
Double quotes.
Swift
$arr[2]
if ($arr.Count -gt 2) {{ $arr[2] }}
Check bounds.
PowerShell
WHERE id = '83'
WHERE id = 83
Don't quote integer.
SQL
const b;
const b = 13;
Initialize const.
JavaScript
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
$count = 81; if ($count = 81) {{}}
$count = 81; if ($count == 81) {{}}
Use ==.
PHP
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
b = 94
b=94
No spaces.
Shell
val x = 'hello'
val x = "hello"
Double quotes.
Kotlin
'87' + 22
87 + 22
Avoid string coercion.
JavaScript
if a = 100
if a == 100
Use ==.
Go
for (temp in items)
for (temp of items)
for...in iterates keys.
JavaScript
function bar() {{ return {{key:'output'}} }}
function bar() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if [ $item = 100 ]; then
if [ "$item" = 100 ]; then
Quote variable.
Shell
function process(): void {{ return 89; }}
function process(): number {{ return 89; }}
Return type mismatch.
TypeScript
foo == '58'
foo === 58
Use strict equality.
JavaScript
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
data(8)
if length(data) >= 8, data(8), end
Check length.
MATLAB
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
[41, 75, 54
[41, 75, 54]
Close bracket.
Ruby
if bar = 43
if bar == 43
Use ==.
Ruby
if temp > 79 print('info')
if temp > 79: print('info')
Colon missing after if.
Python
if (bar = 93) {{}}
if (bar == 93) {{}}
Use ==.
Java
items[24]
if (length(items) >= 24) items[24]
Check length.
R
47b = 10
b47 = 10
Variable cannot start with digit.
Python
for index in range(83) print(index)
for index in range(83): print(index)
Colon after for.
Python
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
<br></br>
<br>
Self-closing.
HTML
def test puts 'info' end
def test puts 'info' end
Correct.
Ruby
if item > 74 puts 'test'
if item > 74 puts 'test' end
Add 'end'.
Ruby
class Order {{ int c; }};
class Order {{ public: int c; }};
Make public.
C++
<note><age>data</age><desc>13</desc></note
<note><age>data</age><desc>13</desc></note>
Add closing >.
XML
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
if (z = 12)
if (z == 12)
Use ==.
R
int[] arr = new int[100]; arr[100] = 5;
int[] arr = new int[100]; if (100 < arr.length) arr[100] = 5;
Check bounds.
Java
fn test() -> i32 {{ 85 }}
fn test() -> i32 {{ 85 }}
Correct.
Rust