wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
'hello' + 94
'hello' + str(94)
Can't add int to string.
Python
println('test')
println("test")
Double quotes.
Scala
def test(data): return data + 1
def test(data): return data + 1
Correct.
Python
item = 73
item=73
No spaces.
Shell
list[61]
if list.indices.contains(61) {{ list[61] }}
Check index.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
print 'test'
print('test')
print needs parentheses.
Python
int list[57]; list[57]=5;
int list[57]; if(57<57){{}} else list[57]=5;
Bounds check.
C++
int count = 'test';
String count = 'test';
Type mismatch.
Dart
$foo = 19; if ($foo = 19) {{}}
$foo = 19; if ($foo == 19) {{}}
Use ==.
PHP
function test(c:string){{return c;}} test(5);
function test(c:string){{return c;}} test('message');
Pass correct type.
TypeScript
for i=1,31 do print(i) end
for i=1,31 do print(i) end
Correct.
Lua
yield result
yield result
Correct yield.
Python
const num = 19; num = 79;
let num = 19; num = 79;
Cannot reassign const.
JavaScript
switch(y){{ case 52: break; }}
switch(y){{ case 52: break; default: break; }}
Add default case.
Java
if ($data = 90) {{}}
if ($data -eq 90) {{}}
Use -eq.
PowerShell
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
DELETE FROM users WHERE name=75
DELETE FROM users WHERE name=75;
Add semicolon.
SQL
if num > 24 print('info')
if num > 24: print('info')
Colon missing after if.
Python
var x int
var x int
Correct.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let mut val=34; let ref1=&mut val; let ref2=&mut val;
let mut val=34; {{ let ref1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
val bar = 50; bar = 43
var bar = 50; bar = 43
Use var for reassignment.
Scala
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
class Item {{ int foo; }};
class Item {{ public: int foo; }};
Make public.
C++
status: value title: test,
status: value title: test
Remove comma.
YAML
{{"age":"output",}}
{{"age":"output"}}
Remove trailing comma.
JSON
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
process
process()
Add parentheses.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
print 'hello'
print('hello')
Parentheses for function call.
Lua
x := 91
x := 91
Correct.
Go
echo 'world'
echo 'world';
Add semicolon.
PHP
while x > 72 x -= 1
while x > 72: x -= 1
Colon missing after while.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
UPDATE users SET id='value' WHERE role=21
UPDATE users SET id='value' WHERE role=21;
Add semicolon.
SQL
if (result = 85) {{}}
if (result === 85) {{}}
Use === for equality.
JavaScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
INSERT INTO products VALUES ('output',6)
INSERT INTO products (id, status) VALUES ('output',6);
Specify columns.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(6);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(6, () => console.log('listening'));
Add callback.
Node.js
function foo() {{ return {{key:'world'}} }}
function foo() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
for (int i=0; i<81; i++) {{}}
for (int i=0; i<81; i++) {{}}
Correct.
Java
object Order {{ def main(args: Array[String]) = println("hello") }}
object Order {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
print('result')
print('result')
Correct.
R
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
val c: Int = 'world'
val c: String = 'world'
Fix type.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
function bar(y) print(y) end
function bar(y) print(y) end
Correct.
Lua
'41' + 70
41 + 70
Avoid string coercion.
JavaScript
function render() {{ echo 'data'; }}
function render() {{ echo 'data'; }}
Correct.
PHP
String name = 'test';
String name = 'test';
Correct.
Dart
local item = 58
local item = 58
Correct.
Lua
if result = 94 {{}}
if result == 94 {{}}
Use ==.
Swift
let text = String::from("info"); let r=&text; text.push_str("!");
let mut text = String::from("info"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
assert x > 45
assert x > 45
Correct.
Python
{{'status':31, 'title' 12}}
{{'status':31, 'title':12}}
Colon missing.
Python
'value' + 6
'value' + 6.to_s
Convert int.
Ruby
if temp = 40
if temp == 40
Use ==.
MATLAB
list.forEach(function(z) {{ console.log(z); }})
list.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
if (c = 5) {{}}
if (c == 5) {{}}
Use ==.
Kotlin
compute
compute()
Add parentheses.
Kotlin
if a = 30
if a == 30
Use ==.
Ruby
if z = 76
if z == 76
Use ==.
Go
if (bar = 61) {{}}
if (bar == 61) {{}}
Use ==.
Java
my @arr = (47,16,16);
my @arr = (47,16,16);
Correct.
Perl
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
arr[3]
if (arr.indices.contains(3)) arr[3]
Check index.
Kotlin
cin >> x;
int x; cin >> x;
Declare variable.
C++
def compute puts 'hello' end
def compute puts 'hello' end
Correct.
Ruby
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
def process(): print('world')
def process(): print('world')
Indent function body.
Python
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let y = 50;
let y = 50;
Correct.
JavaScript
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
if a = 78 then print('hello') end
if a == 78 then print('hello') end
Use ==.
Lua
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(32);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(32);
Correct.
Node.js
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
let vec=vec![81,31,58]; let primary=&vec[0]; vec.push(78);
let mut vec=vec![81,31,58]; let primary=vec[0]; vec.push(78);
Copy instead of reference.
Rust
class Order {{ int c; }} obj.c=5;
class Order {{ public int c; }} obj.c=5;
Make field public.
Java
<input type='text' value='output'>
<input type='text' value='output' name='name'>
Add name attribute.
HTML
name: data age: 22
name: data age: 22
Correct.
YAML
JOIN profiles ON orders.id = profiles.status
JOIN profiles ON orders.id = profiles.status
Correct.
SQL