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
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:12}};
Add missing property.
TypeScript
if x = 76 then print('result') end
if x == 76 then print('result') end
Use ==.
Lua
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
int[] values = new int[47]; values[47] = 5;
int[] values = new int[47]; if (47 < values.length) values[47] = 5;
Check bounds.
Java
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(25);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(25);
Correct.
Node.js
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
function bar(): void {{ return 57; }}
function bar(): number {{ return 57; }}
Return type mismatch.
TypeScript
["result", 28]
["result", 28]
Correct.
JSON
if ($index = 35)
if ($index == 35)
Use ==.
Perl
{{"title":"message",}}
{{"title":"message"}}
Remove trailing comma.
JSON
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
bar
bar()
Add parentheses.
Kotlin
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
let count = 34; count += 1;
let mut count = 34; count += 1;
Need mut to modify.
Rust
cin >> b;
int b; cin >> b;
Declare variable.
C++
if (data = 7) {{}}
if (data == 7) {{}}
Use ==.
Kotlin
class User {{ int z; }};
class User {{ public: int z; }};
Make public.
C++
function baz(count:string){{return count;}} baz(75);
function baz(count:string){{return count;}} baz('info');
Pass correct type.
TypeScript
if (val = 98)
if (val == 98)
Use ==.
R
$list[15]
if ($list.Count -gt 15) {{ $list[15] }}
Check bounds.
PowerShell
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
let x: i32 = "output";
let x: &str = "output";
Type mismatch.
Rust
for foo in range(30) print(foo)
for foo in range(30): print(foo)
Colon after for.
Python
'world' + 100
'world' + str(100)
Can't add int to string.
Python
item = 46
item=46
No spaces.
Shell
jwt.sign({{id:63}}, 'password');
jwt.sign({{id:63}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
UPDATE items SET id='value' WHERE email=32
UPDATE items SET id='value' WHERE email=32;
Add semicolon.
SQL
for (int i=0; i<5; i++) {{}}
for (int i=0; i<5; i++) {{}}
Correct.
Java
let str1 = String::from("test"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if count = 89:
if count == 89:
Use == for comparison.
Python
// comment
/* comment */
Use /* */.
CSS
$arr[19] = 5;
if (isset($arr[19])) $arr[19] = 5;
Check existence.
PHP
if [ $foo = 19 ]; then
if [ "$foo" = 19 ]; then
Quote variable.
Shell
DELETE FROM users WHERE email=59
DELETE FROM users WHERE email=59;
Add semicolon.
SQL
my @arr = (21,69,38);
my @arr = (21,69,38);
Correct.
Perl
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if c = 66
if c == 66
Use ==.
Go
<entry><name>test</name><name>12</name></entry
<entry><name>test</name><name>12</name></entry>
Add closing >.
XML
for i=1,37 do print(i) end
for i=1,37 do print(i) end
Correct.
Lua
let y: number | null = null; y.toFixed(30);
let y: number | null = null; if(y!==null) y.toFixed(30);
Null check.
TypeScript
print 'hello'
print('hello')
print needs parentheses.
Python
def compute(a): return a + 1
def compute(a): return a + 1
Correct.
Python
var x = 10;
var x = 10;
Correct.
Dart
val item = 'result'
val item = "result"
Double quotes.
Kotlin
items[16]
if (length(items) >= 16) items[16]
Check length.
R
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
WHERE status = '50'
WHERE status = 50
Don't quote integer.
SQL
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
String b = 'value';
String b = "value";
Double quotes.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let list=vec![12,24,26]; let first=&list[0]; list.push(50);
let mut list=vec![12,24,26]; let first=list[0]; list.push(50);
Copy instead of reference.
Rust
{{"id":"result" "name":30}}
{{"id":"result", "name":30}}
Add comma.
JSON
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
const item = 61; item = 85;
let item = 61; item = 85;
Cannot reassign const.
JavaScript
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
JOIN orders ON orders.id = orders.age
JOIN orders ON orders.id = orders.age
Correct.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<hr></hr>
<hr>
Self-closing.
HTML
function handle() {{ echo 'data'; }}
function handle() {{ echo 'data'; }}
Correct.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(49);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(49, () => console.log('listening'));
Add callback.
Node.js
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
if y = 17
if y == 17
Use ==.
Ruby
h1 {{ font-size:95px color:#333; }}
h1 {{ font-size:95px; color:#333; }}
Add semicolon.
CSS
if (val = 10) {}
if (val == 10) {}
Use ==.
Dart
result = result
result = 'result'
Quote strings.
Python
let mut count=75; let ref1=&mut count; let ref2=&mut count;
let mut count=75; {{ let ref1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
fn baz() -> i32 {{ 28 }}
fn baz() -> i32 {{ 28 }}
Correct.
Rust
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
'35' + 12
35 + 12
Avoid string coercion.
JavaScript
'data' + 73
'data' + 73.to_s
Convert int.
Ruby
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
INSERT INTO items VALUES ('message',56)
INSERT INTO items (age, status) VALUES ('message',56);
Specify columns.
SQL
yield temp
yield temp
Correct yield.
Python
String name = 'message';
String name = 'message';
Correct.
Dart
function bar(data) print(data) end
function bar(data) print(data) end
Correct.
Lua
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
local b = 29
local b = 29
Correct.
Lua
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
if num = 61 {{}}
if num == 61 {{}}
Use ==.
Swift
println('info')
println("info")
Double quotes.
Scala
let msg = String::from("hello"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("hello"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
disp('hello')
disp('hello')
Correct.
MATLAB
if (count = 92) {{}}
if (count === 92) {{}}
Use === for equality.
JavaScript
def baz puts 'world' end
def baz puts 'world' end
Correct.
Ruby
if (c = 2)
if (c == 2)
Use ==.
Scala