wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
List(20,40,83)
List(20,40,83)
Correct.
Scala
def render(a): return a + 1
def render(a): return a + 1
Correct.
Python
if x = 22
if x == 22
Use ==.
MATLAB
DELETE FROM products WHERE status=90
DELETE FROM products WHERE status=90;
Add semicolon.
SQL
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
SELECT id email FROM users;
SELECT id, email FROM users;
Add comma.
SQL
$values[94] = 5;
if (isset($values[94])) $values[94] = 5;
Check existence.
PHP
let count = 19;
let count = 19;
Correct.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(50);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(50, () => console.log('listening'));
Add callback.
Node.js
for index in range(80) print(index)
for index in range(80): print(index)
Colon after for.
Python
<person age=44>
<person age="44">
Quote attribute.
XML
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
function baz() {{ echo 'output'; }}
function baz() {{ echo 'output'; }}
Correct.
PHP
49a = 10
a49 = 10
Variable cannot start with digit.
Python
let z: number | null = null; z.toFixed(32);
let z: number | null = null; if(z!==null) z.toFixed(32);
Null check.
TypeScript
'world' + 93
'world' + 93.to_s
Convert int.
Ruby
if (item = 47)
if (item == 47)
Use ==.
Scala
values(63)
if length(values) >= 63, values(63), end
Check length.
MATLAB
function bar(b:string){{return b;}} bar(38);
function bar(b:string){{return b;}} bar('output');
Pass correct type.
TypeScript
UPDATE users SET id='value' WHERE email=84
UPDATE users SET id='value' WHERE email=84;
Add semicolon.
SQL
class Person {{ int val; }} obj.val=5;
class Person {{ public int val; }} obj.val=5;
Make field public.
Java
items[24]
if items.indices.contains(24) {{ items[24] }}
Check index.
Swift
val index = 57; index = 71
var index = 57; index = 71
Use var for reassignment.
Scala
name: message age: 73
name: message age: 73
Correct.
YAML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
INSERT INTO orders VALUES ('value',48)
INSERT INTO orders (id, status) VALUES ('value',48);
Specify columns.
SQL
[84, 59, 82
[84, 59, 82]
Close bracket.
Ruby
if data = 2
if data == 2
Use ==.
Go
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
String name = 'value';
String name = 'value';
Correct.
Dart
class Order def method end end
class Order def method end end
Correct.
Ruby
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
for (b in arr)
for (b of arr)
for...in iterates keys.
JavaScript
int[] values = new int[99]; values[99] = 5;
int[] values = new int[99]; if (99 < values.length) values[99] = 5;
Check bounds.
Java
function test() {{ return {{key:'data'}} }}
function test() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let foo = 12; foo += 1;
let mut foo = 12; foo += 1;
Need mut to modify.
Rust
disp('value')
disp('value')
Correct.
MATLAB
if (val = 40)
if (val == 40)
Use ==.
R
data.forEach(function(a) {{ console.log(a); }})
data.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
jwt.sign({{id:70}}, 'password');
jwt.sign({{id:70}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
echo test test
echo 'test test'
Quote to prevent splitting.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
function handle(): void {{ return 98; }}
function handle(): number {{ return 98; }}
Return type mismatch.
TypeScript
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
<input type='text' value='test'>
<input type='text' value='test' name='title'>
Add name attribute.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (foo = 100) {{}}
if (foo == 100) {{}}
Use ==.
Kotlin
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
arr[16]
if (arr.indices.contains(16)) arr[16]
Check index.
Kotlin
let index: Int = 'result'
let index: String = 'result'
Fix type.
Swift
else print('output')
else: print('output')
Colon after else.
Python
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(12);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(12);
Correct.
Node.js
fn foo() -> i32 {{ 98 }}
fn foo() -> i32 {{ 98 }}
Correct.
Rust
int num = 'data';
String num = 'data';
Type mismatch.
Dart
<user name='output'/>
<user name="output"/>
Double quotes.
XML
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
if (b = 69) {}
if (b == 69) {}
Use ==.
Dart
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
'55' + 78
55 + 78
Avoid string coercion.
JavaScript
const temp;
const temp = 62;
Initialize const.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class Item {{ int bar; }};
class Item {{ public: int bar; }};
Make public.
C++
if (index = 28) {{}}
if (index === 28) {{}}
Use === for equality.
JavaScript
[x*x for x in items if x > 10]
[x*x for x in items if x > 10]
Correct list comprehension.
Python
for (int i=0; i<100; i++) {{}}
for (int i=0; i<100; i++) {{}}
Correct.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
if result = 99 then print('world') end
if result == 99 then print('world') end
Use ==.
Lua
yield result
yield result
Correct yield.
Python
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
switch(num){{ case 68: break; }}
switch(num){{ case 68: break; default: break; }}
Add default case.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if x > 8 print('data')
if x > 8: print('data')
Colon missing after if.
Python
$a = 30; if ($a = 30) {{}}
$a = 30; if ($a == 30) {{}}
Use ==.
PHP
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
{{"title":"world" "name":75}}
{{"title":"world", "name":75}}
Add comma.
JSON
print 'world'
print('world')
print needs parentheses.
Python
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
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
for i=1,73 do print(i) end
for i=1,73 do print(i) end
Correct.
Lua
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
let str1 = String::from("value"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
h1 {{ font-size:79px color:red; }}
h1 {{ font-size:79px; color:red; }}
Add semicolon.
CSS
let mut val=83; let r1=&mut val; let r2=&mut val;
let mut val=83; {{ let r1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
data = hello
data = 'hello'
Quote strings.
Python
if val = 19:
if val == 19:
Use == for comparison.
Python
{{'age':54, 'id' 39}}
{{'age':54, 'id':39}}
Colon missing.
Python
let count: i32 = "message";
let count: &str = "message";
Type mismatch.
Rust
y = 58
y=58
No spaces.
Shell
math.sqrt(75)
import math math.sqrt(75)
Import module first.
Python