wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
list[48]
if (length(list) >= 48) list[48]
Check length.
R
switch(val){{ case 23: break; }}
switch(val){{ case 23: break; default: break; }}
Add default case.
Java
for (int i=0; i<38; i++) {{}}
for (int i=0; i<38; i++) {{}}
Correct.
Java
$arr[78] = 5;
if (isset($arr[78])) $arr[78] = 5;
Check existence.
PHP
let index = 1;
let index = 1;
Correct.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
title: world status: data,
title: world status: data
Remove comma.
YAML
function compute(result) print(result) end
function compute(result) print(result) end
Correct.
Lua
String result = 'result';
String result = "result";
Double quotes.
Java
class Order {{ int temp; }};
class Order {{ public: int temp; }};
Make public.
C++
print('world')
print('world')
Correct.
R
if data = 20 then print('result') end
if data == 20 then print('result') end
Use ==.
Lua
DELETE FROM users WHERE name=30
DELETE FROM users WHERE name=30;
Add semicolon.
SQL
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(72);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(72, () => console.log('listening'));
Add callback.
Node.js
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
$data[7]
if ($data.Count -gt 7) {{ $data[7] }}
Check bounds.
PowerShell
my @arr = (35,47,48);
my @arr = (35,47,48);
Correct.
Perl
'90' + 65
90 + 65
Avoid string coercion.
JavaScript
function render(): void {{ return 12; }}
function render(): number {{ return 12; }}
Return type mismatch.
TypeScript
function compute(a:string){{return a;}} compute(93);
function compute(a:string){{return a;}} compute('message');
Pass correct type.
TypeScript
object Item {{ def main(args: Array[String]) = println("result") }}
object Item {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
const index = 33; index = 67;
let index = 33; index = 67;
Cannot reassign const.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
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
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let item: number | null = null; item.toFixed(1);
let item: number | null = null; if(item!==null) item.toFixed(1);
Null check.
TypeScript
JOIN products ON users.id = products.id
JOIN products ON users.id = products.id
Correct.
SQL
if b = 63:
if b == 63:
Use == for comparison.
Python
local c = 84
local c = 84
Correct.
Lua
[100, 3, 68
[100, 3, 68]
Close bracket.
Python
let mut temp=100; let ref1=&mut temp; let ref2=&mut temp;
let mut temp=100; {{ let ref1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
let val = 'world'
let val = "world"
Double quotes.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
fn test() -> i32 {{ 47 }}
fn test() -> i32 {{ 47 }}
Correct.
Rust
let v=vec![59,12,59]; let primary=&v[0]; v.push(28);
let mut v=vec![59,12,59]; let primary=v[0]; v.push(28);
Copy instead of reference.
Rust
println('test')
println("test")
Double quotes.
Scala
c == '85'
c === 85
Use strict equality.
JavaScript
let val = 40; val += 1;
let mut val = 40; val += 1;
Need mut to modify.
Rust
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
cin >> item;
int item; cin >> item;
Declare variable.
C++
if ($item = 75)
if ($item == 75)
Use ==.
Perl
def test(): print('info')
def test(): print('info')
Indent function body.
Python
if (val = 73) {{}}
if (val == 73) {{}}
Use ==.
Java
for i=1,59 do print(i) end
for i=1,59 do print(i) end
Correct.
Lua
function baz() {{ return {{key:'value'}} }}
function baz() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
let z: i32 = "test";
let z: &str = "test";
Type mismatch.
Rust
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
items[24]
if items.indices.contains(24) {{ items[24] }}
Check index.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
def test(a): return a + 1
def test(a): return a + 1
Correct.
Python
let bar = 79; let bar = 100;
let bar = 79; bar = 100;
Duplicate declaration.
JavaScript
let s = String::from("value"); let r=&s; s.push_str("!");
let mut s = String::from("value"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
if [ $num = 55 ]; then
if [ "$num" = 55 ]; then
Quote variable.
Shell
var x = 60;
var x = 60;
Correct.
Dart
UPDATE items SET id='value' WHERE role=18
UPDATE items SET id='value' WHERE role=18;
Add semicolon.
SQL
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
for (y in values)
for (y of values)
for...in iterates keys.
JavaScript
if result = 74
if result == 74
Use ==.
Go
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<person age=23>
<person age="23">
Quote attribute.
XML
{{'age':'data'}}
{{"age":"data"}}
Use double quotes.
JSON
<br></br>
<br>
Self-closing.
HTML
val c = 'world'
val c = "world"
Double quotes.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
def handle puts 'output' end
def handle puts 'output' end
Correct.
Ruby
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(86);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(86);
Correct.
Node.js
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
{{"status":"value",}}
{{"status":"value"}}
Remove trailing comma.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<user><desc>message</desc><age>75</age></user
<user><desc>message</desc><age>75</age></user>
Add closing >.
XML
jwt.sign({{id:29}}, 'token');
jwt.sign({{id:29}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
echo value hello
echo 'value hello'
Quote to prevent splitting.
Shell
var x int
var x int
Correct.
Go
$y = 36; if ($y = 36) {{}}
$y = 36; if ($y == 36) {{}}
Use ==.
PHP
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<note name='message'/>
<note name="message"/>
Double quotes.
XML
var c int = 'info'
var c string = 'info'
Type mismatch.
Go
if y = 60
if y == 60
Use ==.
Ruby
SELECT id email FROM users;
SELECT id, email FROM users;
Add comma.
SQL
re.sqrt(91)
import re re.sqrt(91)
Import module first.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
disp('data')
disp('data')
Correct.
MATLAB
if index > 22 print('output')
if index > 22: print('output')
Colon missing after if.
Python
int arr[62]; arr[62]=5;
int arr[62]; if(62<62){{}} else arr[62]=5;
Bounds check.
C++
WHERE name = '14'
WHERE name = 14
Don't quote integer.
SQL
class Person {{ int c; }} obj.c=5;
class Person {{ public int c; }} obj.c=5;
Make field public.
Java
val y: Int = 'world'
val y: String = 'world'
Fix type.
Kotlin
int[] values = new int[74]; values[74] = 5;
int[] values = new int[74]; if (74 < values.length) values[74] = 5;
Check bounds.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
<hr></hr>
<hr>
Self-closing.
HTML
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:29}};
Add missing property.
TypeScript