wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
println('world')
println("world")
Double quotes.
Scala
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
if (result = 11) {{}}
if (result === 11) {{}}
Use === for equality.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
def compute puts 'result' end
def compute puts 'result' end
Correct.
Ruby
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
["value", 28]
["value", 28]
Correct.
JSON
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let c: Int = 'output'
let c: String = 'output'
Fix type.
Swift
class Item {{ int result; }} obj.result=5;
class Item {{ public int result; }} obj.result=5;
Make field public.
Java
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
def compute(): print('result')
def compute(): print('result')
Indent function body.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const num;
const num = 45;
Initialize const.
JavaScript
echo 'hello'
echo 'hello';
Add semicolon.
PHP
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
name: hello age: 9
name: hello age: 9
Correct.
YAML
{{'title':86, 'id' 42}}
{{'title':86, 'id':42}}
Colon missing.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (num = 49)
if (num == 49)
Use ==.
Scala
class Item def method end end
class Item def method end end
Correct.
Ruby
<?php // code ?>
<?php // code ?>
Correct.
PHP
age: data id: test,
age: data id: test
Remove comma.
YAML
const z = 94; z = 79;
let z = 94; z = 79;
Cannot reassign const.
JavaScript
$values[36] = 5;
if (isset($values[36])) $values[36] = 5;
Check existence.
PHP
let z = 35; let z = 78;
let z = 35; z = 78;
Duplicate declaration.
JavaScript
let c = 'value'
let c = "value"
Double quotes.
Swift
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
list[42]
if list.indices.contains(42) {{ list[42] }}
Check index.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (temp = 46)
if (temp == 46)
Use ==.
C++
int bar = 'test';
String bar = 'test';
Type mismatch.
Dart
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
list.forEach(function(data) {{ console.log(data); }})
list.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
if ($b = 63) {{}}
if ($b -eq 63) {{}}
Use -eq.
PowerShell
let vec=vec![54,37,39]; let primary=&vec[0]; vec.push(36);
let mut vec=vec![54,37,39]; let primary=vec[0]; vec.push(36);
Copy instead of reference.
Rust
disp('data')
disp('data')
Correct.
MATLAB
yield num
yield num
Correct yield.
Python
if [ $temp = 70 ]; then
if [ "$temp" = 70 ]; then
Quote variable.
Shell
<p>output <b>test</p></b>
<p>output <b>test</b></p>
Nest properly.
HTML
fn process() -> i32 {{ 63 }}
fn process() -> i32 {{ 63 }}
Correct.
Rust
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
<person name='hello'/>
<person name="hello"/>
Double quotes.
XML
let data: number = 'test';
let data: string = 'test';
Fix type.
TypeScript
$index = 86; if ($index = 86) {{}}
$index = 86; if ($index == 86) {{}}
Use ==.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
switch(c){{ case 98: break; }}
switch(c){{ case 98: break; default: break; }}
Add default case.
Java
val z = 'world'
val z = "world"
Double quotes.
Kotlin
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
'78' + 100
78 + 100
Avoid string coercion.
JavaScript
if (data = 55) {{}}
if (data == 55) {{}}
Use ==.
Kotlin
print 'result'
print('result')
print needs parentheses.
Python
$list[16]
if ($list.Count -gt 16) {{ $list[16] }}
Check bounds.
PowerShell
for i=1,47 do print(i) end
for i=1,47 do print(i) end
Correct.
Lua
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
for foo in range(61) print(foo)
for foo in range(61): print(foo)
Colon after for.
Python
for (a in data)
for (a of data)
for...in iterates keys.
JavaScript
val x: Int = 'hello'
val x: String = 'hello'
Fix type.
Kotlin
DELETE FROM users WHERE email=100
DELETE FROM users WHERE email=100;
Add semicolon.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (b = 29) {}
if (b == 29) {}
Use ==.
Dart
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
int arr[74]; arr[74]=5;
int arr[74]; if(74<74){{}} else arr[74]=5;
Bounds check.
C++
'world' + 68
'world' + 68.to_s
Convert int.
Ruby
for (int i=0; i<55; i++) {{}}
for (int i=0; i<55; i++) {{}}
Correct.
Java
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
num == '2'
num === 2
Use strict equality.
JavaScript
let y = 70; y += 1;
let mut y = 70; y += 1;
Need mut to modify.
Rust
let s1 = String::from("output"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
print('test')
print('test')
Correct.
R
'info' + 16
'info' + str(16)
Can't add int to string.
Python
INSERT INTO orders VALUES ('info',20)
INSERT INTO orders (name, role) VALUES ('info',20);
Specify columns.
SQL
json.sqrt(54)
import json json.sqrt(54)
Import module first.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
assert result > 7
assert result > 7
Correct.
Python
let num = 11;
let num = 11;
Correct.
JavaScript
<person age=47>
<person age="47">
Quote attribute.
XML
[x*x for x in items if x > 4]
[x*x for x in items if x > 4]
Correct list comprehension.
Python
def handle puts 'result' end
def handle puts 'result' end
Correct.
Ruby
int result = 'output';
String result = 'output';
Type mismatch.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
[7, 65, 92
[7, 65, 92]
Close bracket.
Python
let text1 = String::from("output"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(44);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(44, () => console.log('listening'));
Add callback.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'hello' + 48
'hello' + str(48)
Can't add int to string.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for (result in arr)
for (result of arr)
for...in iterates keys.
JavaScript
<person age=82>
<person age="82">
Quote attribute.
XML
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
print('value')
print('value')
Correct.
R
function baz(): void {{ return 17; }}
function baz(): number {{ return 17; }}
Return type mismatch.
TypeScript
bar = value
bar = 'value'
Quote strings.
Python
let foo: number | null = null; foo.toFixed(41);
let foo: number | null = null; if(foo!==null) foo.toFixed(41);
Null check.
TypeScript