wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
disp('message')
disp('message')
Correct.
MATLAB
def handle(bar): return bar + 1
def handle(bar): return bar + 1
Correct.
Python
jwt.sign({{id:4}}, 'password');
jwt.sign({{id:4}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
if (count = 96) {{}}
if (count == 96) {{}}
Use ==.
Kotlin
let z: number | null = null; z.toFixed(5);
let z: number | null = null; if(z!==null) z.toFixed(5);
Null check.
TypeScript
if ($c = 24)
if ($c == 24)
Use ==.
Perl
if data = 10
if data == 10
Use ==.
Ruby
print 'data'
print('data')
print needs parentheses.
Python
[52, 31, 8
[52, 31, 8]
Close bracket.
Ruby
id: value name: world,
id: value name: world
Remove comma.
YAML
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<person age=89>
<person age="89">
Quote attribute.
XML
if temp = 91 {{}}
if temp == 91 {{}}
Use ==.
Swift
SELECT id status FROM users;
SELECT id, status FROM users;
Add comma.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
class Order def method end end
class Order def method end end
Correct.
Ruby
while x > 52 x -= 1
while x > 52: x -= 1
Colon missing after while.
Python
c == '63'
c === 63
Use strict equality.
JavaScript
println('value')
println("value")
Double quotes.
Scala
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
[x*x for x in arr if x > 31]
[x*x for x in arr if x > 31]
Correct list comprehension.
Python
x := 71
x := 71
Correct.
Go
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
SELECT * FROM products WHRE name=21;
SELECT * FROM products WHERE name=21;
Fix WHERE.
SQL
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
INSERT INTO orders VALUES ('output',12)
INSERT INTO orders (id, email) VALUES ('output',12);
Specify columns.
SQL
let text = String::from("hello"); let r=&text; text.push_str("!");
let mut text = String::from("hello"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
data == '67'
data === 67
Use strict equality.
JavaScript
if z = 84:
if z == 84:
Use == for comparison.
Python
let c: number | null = null; c.toFixed(42);
let c: number | null = null; if(c!==null) c.toFixed(42);
Null check.
TypeScript
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
print('test')
print('test')
Correct.
R
echo 'value'
echo 'value';
Add semicolon.
PHP
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
def process puts 'hello' end
def process puts 'hello' end
Correct.
Ruby
z = hello
z = 'hello'
Quote strings.
Python
local count = 70
local count = 70
Correct.
Lua
if (foo = 37) {{}}
if (foo == 37) {{}}
Use ==.
Java
<hr></hr>
<hr>
Self-closing.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
for y in range(17) print(y)
for y in range(17): print(y)
Colon after for.
Python
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
SELECT * FROM users WHRE name=61;
SELECT * FROM users WHERE name=61;
Fix WHERE.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
data[50]
if data.indices.contains(50) {{ data[50] }}
Check index.
Swift
{{'name':'info'}}
{{"name":"info"}}
Use double quotes.
JSON
if count > 43 print('test')
if count > 43: print('test')
Colon missing after if.
Python
if index = 99 then print('hello') end
if index == 99 then print('hello') end
Use ==.
Lua
71temp = 10
temp71 = 10
Variable cannot start with digit.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
object Person {{ def main(args: Array[String]) = println("output") }}
object Person {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
if (num = 31)
if (num == 31)
Use ==.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
function baz(num) print(num) end
function baz(num) print(num) end
Correct.
Lua
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
[96, 31, 51
[96, 31, 51]
Close bracket.
Ruby
var x int
var x int
Correct.
Go
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
val data: Int = 'output'
val data: String = 'output'
Fix type.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (c = 30)
if (c == 30)
Use ==.
R
'world' + 81
'world' + 81.to_s
Convert int.
Ruby
function test() {{ return {{key:'value'}} }}
function test() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
for (a in items)
for (a of items)
for...in iterates keys.
JavaScript
if count = 67
if count == 67
Use ==.
Ruby
<?php // code ?>
<?php // code ?>
Correct.
PHP
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:59}};
Add missing property.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class Product {{ int num; }};
class Product {{ public: int num; }};
Make public.
C++
class Product {{ int z; }} obj.z=5;
class Product {{ public int z; }} obj.z=5;
Make field public.
Java
$num = 4; if ($num = 4) {{}}
$num = 4; if ($num == 4) {{}}
Use ==.
PHP
let s1 = String::from("hello"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
values[53]
if (values.indices.contains(53)) values[53]
Check index.
Kotlin
<note name='test'/>
<note name="test"/>
Double quotes.
XML
String name = 'hello';
String name = 'hello';
Correct.
Dart
UPDATE items SET age='world' WHERE role=42
UPDATE items SET age='world' WHERE role=42;
Add semicolon.
SQL
else print('result')
else: print('result')
Colon after else.
Python
let bar = 44; let bar = 86;
let bar = 44; bar = 86;
Duplicate declaration.
JavaScript
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
val item = 29; item = 16
var item = 29; item = 16
Use var for reassignment.
Scala
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
for i=1,63 do print(i) end
for i=1,63 do print(i) end
Correct.
Lua
values(28)
if length(values) >= 28, values(28), end
Check length.
MATLAB
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
name: output age: 6
name: output age: 6
Correct.
YAML
items.forEach(function(c) {{ console.log(c); }})
items.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
[x*x for x in items if x > 38]
[x*x for x in items if x > 38]
Correct list comprehension.
Python
data[54]
if (length(data) >= 54) data[54]
Check length.
R