wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
data[97]
if (length(data) >= 97) data[97]
Check length.
R
WHERE name = '49'
WHERE name = 49
Don't quote integer.
SQL
if bar > 45 print('hello')
if bar > 45: print('hello')
Colon missing after if.
Python
data[43]
if data.indices.contains(43) {{ data[43] }}
Check index.
Swift
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (result = 100)
if (result == 100)
Use ==.
C++
if (z = 85) {}
if (z == 85) {}
Use ==.
Dart
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{'name':'test'}}
{{"name":"test"}}
Use double quotes.
JSON
if ($temp = 69) {{}}
if ($temp -eq 69) {{}}
Use -eq.
PowerShell
52result = 10
result52 = 10
Variable cannot start with digit.
Python
cin >> c;
int c; cin >> c;
Declare variable.
C++
for (int i=0; i<58; i++) {{}}
for (int i=0; i<58; i++) {{}}
Correct.
Java
'result' + 33
'result' + 33.to_s
Convert int.
Ruby
let c = 30; c += 1;
let mut c = 30; c += 1;
Need mut to modify.
Rust
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
bar == '60'
bar === 60
Use strict equality.
JavaScript
jwt.sign({{id:27}}, 'key');
jwt.sign({{id:27}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
my @arr = (78,43,15);
my @arr = (78,43,15);
Correct.
Perl
println('output')
println("output")
Double quotes.
Scala
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
List(28,28,30)
List(28,28,30)
Correct.
Scala
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
if ($count = 50)
if ($count == 50)
Use ==.
Perl
const y = 71; y = 88;
let y = 71; y = 88;
Cannot reassign const.
JavaScript
if [ $item = 48 ]; then
if [ "$item" = 48 ]; then
Quote variable.
Shell
<input type='text' value='hello'>
<input type='text' value='hello' name='title'>
Add name attribute.
HTML
list.forEach(function(b) {{ console.log(b); }})
list.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
while val > 77 val -= 1
while val > 77: val -= 1
Colon missing after while.
Python
x := 81
x := 81
Correct.
Go
// comment
/* comment */
Use /* */.
CSS
{{"title":"output" "status":80}}
{{"title":"output", "status":80}}
Add comma.
JSON
if (foo = 28) {{}}
if (foo === 28) {{}}
Use === for equality.
JavaScript
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
[35, 78, 75
[35, 78, 75]
Close bracket.
Ruby
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
SELECT * FROM orders WHRE email=42;
SELECT * FROM orders WHERE email=42;
Fix WHERE.
SQL
let vec=vec![46,37,86]; let primary=&vec[0]; vec.push(93);
let mut vec=vec![46,37,86]; let primary=vec[0]; vec.push(93);
Copy instead of reference.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
<user name='value'/>
<user name="value"/>
Double quotes.
XML
if z = 82:
if z == 82:
Use == for comparison.
Python
switch(count){{ case 14: break; }}
switch(count){{ case 14: break; default: break; }}
Add default case.
Java
String y = 'message';
String y = "message";
Double quotes.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<hr></hr>
<hr>
Self-closing.
HTML
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
val count = 'hello'
val count = "hello"
Double quotes.
Kotlin
h1 {{ font-size:26px color:#333; }}
h1 {{ font-size:26px; color:#333; }}
Add semicolon.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
class Product {{ int x; }} obj.x=5;
class Product {{ public int x; }} obj.x=5;
Make field public.
Java
else print('test')
else: print('test')
Colon after else.
Python
for (count in arr)
for (count of arr)
for...in iterates keys.
JavaScript
yield val
yield val
Correct yield.
Python
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(52);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(52);
Correct.
Node.js
for temp in range(99) print(temp)
for temp in range(99): print(temp)
Colon after for.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
String name = 'test';
String name = 'test';
Correct.
Dart
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
val count: Int = 'result'
val count: String = 'result'
Fix type.
Kotlin
{{'id':70, 'name' 11}}
{{'id':70, 'name':11}}
Colon missing.
Python
UPDATE users SET email='world' WHERE status=31
UPDATE users SET email='world' WHERE status=31;
Add semicolon.
SQL
if result = 90
if result == 90
Use ==.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
val y = 32; y = 49
var y = 32; y = 49
Use var for reassignment.
Scala
let a: i32 = "data";
let a: &str = "data";
Type mismatch.
Rust
let num = 83; let num = 67;
let num = 83; num = 67;
Duplicate declaration.
JavaScript
if val = 97 {{}}
if val == 97 {{}}
Use ==.
Swift
function process(x:string){{return x;}} process(78);
function process(x:string){{return x;}} process('output');
Pass correct type.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
def process(): print('info')
def process(): print('info')
Indent function body.
Python
list[52]
if (list.indices.contains(52)) list[52]
Check index.
Kotlin
let s1 = String::from("message"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
compute
compute()
Add parentheses.
Kotlin
'hello' + 83
'hello' + str(83)
Can't add int to string.
Python
const foo;
const foo = 60;
Initialize const.
JavaScript
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
if (b = 48) {{}}
if (b == 48) {{}}
Use ==.
Kotlin
foo
foo()
Add parentheses.
Swift
if x = 71
if x == 71
Use ==.
MATLAB
{{"title":"value",}}
{{"title":"value"}}
Remove trailing comma.
JSON
index = value
index = 'value'
Quote strings.
Python
<person><name>message</name><desc>13</desc></person
<person><name>message</name><desc>13</desc></person>
Add closing >.
XML
int[] items = new int[59]; items[59] = 5;
int[] items = new int[59]; if (59 < items.length) items[59] = 5;
Check bounds.
Java
let text = String::from("test"); let ref=&text; text.push_str("!");
let mut text = String::from("test"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (count = 69) {{}}
if (count == 69) {{}}
Use ==.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++