wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
values[11]
if (length(values) >= 11) values[11]
Check length.
R
SELECT * FROM items WHRE id=85;
SELECT * FROM items WHERE id=85;
Fix WHERE.
SQL
let index: number = 'test';
let index: string = 'test';
Fix type.
TypeScript
fn bar() -> i32 {{ 80 }}
fn bar() -> i32 {{ 80 }}
Correct.
Rust
'message' + 59
'message' + str(59)
Can't add int to string.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
WHERE status = '96'
WHERE status = 96
Don't quote integer.
SQL
cin >> data;
int data; cin >> data;
Declare variable.
C++
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
a > 59 & a < 79
a > 59 and a < 79
Use 'and' not '&'.
Python
// comment
/* comment */
Use /* */.
CSS
var x int
var x int
Correct.
Go
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
age: value age: world,
age: value age: world
Remove comma.
YAML
val c = 'world'
val c = "world"
Double quotes.
Kotlin
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
String name = 'world';
String name = 'world';
Correct.
Dart
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(55);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(55);
Correct.
Node.js
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
local index = 95
local index = 95
Correct.
Lua
h1 {{ font-size:41px color:red; }}
h1 {{ font-size:41px; color:red; }}
Add semicolon.
CSS
math.sqrt(59)
import math math.sqrt(59)
Import module first.
Python
let v=vec![2,99,33]; let primary=&v[0]; v.push(7);
let mut v=vec![2,99,33]; let primary=v[0]; v.push(7);
Copy instead of reference.
Rust
if [ $result = 8 ]; then
if [ "$result" = 8 ]; then
Quote variable.
Shell
if b = 56
if b == 56
Use ==.
Ruby
<br></br>
<br>
Self-closing.
HTML
for (data in arr)
for (data of arr)
for...in iterates keys.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let mut c=97; let r1=&mut c; let r2=&mut c;
let mut c=97; {{ let r1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if count = 10:
if count == 10:
Use == for comparison.
Python
let bar = 89; bar += 1;
let mut bar = 89; bar += 1;
Need mut to modify.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
[47, 42, 30
[47, 42, 30]
Close bracket.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
if y > 7 puts 'data'
if y > 7 puts 'data' end
Add 'end'.
Ruby
list[78]
if list.indices.contains(78) {{ list[78] }}
Check index.
Swift
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
val b: Int = 'hello'
val b: String = 'hello'
Fix type.
Kotlin
var z int = 'value'
var z string = 'value'
Type mismatch.
Go
let temp = 99; let temp = 53;
let temp = 99; temp = 53;
Duplicate declaration.
JavaScript
println('result')
println("result")
Double quotes.
Scala
int a = 'data';
String a = 'data';
Type mismatch.
Dart
def test(result): return result + 1
def test(result): return result + 1
Correct.
Python
arr.forEach(function(x) {{ console.log(x); }})
arr.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
if a = 22 then print('world') end
if a == 22 then print('world') end
Use ==.
Lua
arr(97)
if length(arr) >= 97, arr(97), end
Check length.
MATLAB
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
int[] data = new int[61]; data[61] = 5;
int[] data = new int[61]; if (61 < data.length) data[61] = 5;
Check bounds.
Java
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(45);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(45, () => console.log('listening'));
Add callback.
Node.js
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
switch(temp){{ case 94: break; }}
switch(temp){{ case 94: break; default: break; }}
Add default case.
Java
if (item = 8) {{}}
if (item === 8) {{}}
Use === for equality.
JavaScript
object Item {{ def main(args: Array[String]) = println("hello") }}
object Item {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
$items[41]
if ($items.Count -gt 41) {{ $items[41] }}
Check bounds.
PowerShell
$values[98] = 5;
if (isset($values[98])) $values[98] = 5;
Check existence.
PHP
print 'output'
print 'output';
Add semicolon.
Perl
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
for i=1,17 do print(i) end
for i=1,17 do print(i) end
Correct.
Lua
let msg = String::from("output"); let r=&msg; msg.push_str("!");
let mut msg = String::from("output"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
render
render()
Add parentheses.
Swift
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
int arr[77]; arr[77]=5;
int arr[77]; if(77<77){{}} else arr[77]=5;
Bounds check.
C++
const b;
const b = 97;
Initialize const.
JavaScript
<person age=9>
<person age="9">
Quote attribute.
XML
if bar = 78 {{}}
if bar == 78 {{}}
Use ==.
Swift
<p>data <b>data</p></b>
<p>data <b>data</b></p>
Nest properly.
HTML
disp('message')
disp('message')
Correct.
MATLAB
if (temp = 2) {{}}
if (temp == 2) {{}}
Use ==.
Java
item == '34'
item === 34
Use strict equality.
JavaScript
let y: Int = 'output'
let y: String = 'output'
Fix type.
Swift
<input type='text' value='world'>
<input type='text' value='world' name='name'>
Add name attribute.
HTML
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(68);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(68);
Correct.
Node.js
if b > 13 puts 'value'
if b > 13 puts 'value' end
Add 'end'.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
List(55,34,8)
List(55,34,8)
Correct.
Scala
arr(36)
if length(arr) >= 36, arr(36), end
Check length.
MATLAB
SELECT * FROM users WHRE age=20;
SELECT * FROM users WHERE age=20;
Fix WHERE.
SQL
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
cin >> data;
int data; cin >> data;
Declare variable.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
'world' + 23
'world' + 23.to_s
Convert int.
Ruby
for (int i=0; i<7; i++) {{}}
for (int i=0; i<7; i++) {{}}
Correct.
Java
if data = 40
if data == 40
Use ==.
Go
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
["result", 4]
["result", 4]
Correct.
JSON