wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
print 'hello'
print('hello')
Parentheses for function call.
Lua
print 'info'
print('info')
print needs parentheses.
Python
const foo = 74; foo = 33;
let foo = 74; foo = 33;
Cannot reassign const.
JavaScript
int item = 'hello';
String item = 'hello';
Type mismatch.
Dart
let x = 'world'
let x = "world"
Double quotes.
Swift
int[] data = new int[16]; data[16] = 5;
int[] data = new int[16]; if (16 < data.length) data[16] = 5;
Check bounds.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if a > 17 print('output')
if a > 17: print('output')
Colon missing after if.
Python
'info' + 87
'info' + 87.to_s
Convert int.
Ruby
{{"status":"test",}}
{{"status":"test"}}
Remove trailing comma.
JSON
c == '51'
c === 51
Use strict equality.
JavaScript
SELECT age role FROM users;
SELECT age, role FROM users;
Add comma.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
else print('value')
else: print('value')
Colon after else.
Python
{{"name":"test" "title":48}}
{{"name":"test", "title":48}}
Add comma.
JSON
for data in range(17) print(data)
for data in range(17): print(data)
Colon after for.
Python
if ($num = 82)
if ($num == 82)
Use ==.
Perl
let s = String::from("hello"); let r=&s; s.push_str("!");
let mut s = String::from("hello"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
class Person {{ int a; }} obj.a=5;
class Person {{ public int a; }} obj.a=5;
Make field public.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(94);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(94, () => console.log('listening'));
Add callback.
Node.js
class Person {{ int val; }};
class Person {{ public: int val; }};
Make public.
C++
function foo(): void {{ return 93; }}
function foo(): number {{ return 93; }}
Return type mismatch.
TypeScript
val count = 94; count = 80
var count = 94; count = 80
Use var for reassignment.
Scala
if val = 1
if val == 1
Use ==.
MATLAB
if (data = 74) {}
if (data == 74) {}
Use ==.
Dart
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const c;
const c = 27;
Initialize const.
JavaScript
test
test()
Add parentheses.
Kotlin
def compute(bar): return bar + 1
def compute(bar): return bar + 1
Correct.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
val temp = 'data'
val temp = "data"
Double quotes.
Kotlin
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
foo
foo()
Add parentheses.
Swift
String temp = 'hello';
String temp = "hello";
Double quotes.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
SELECT * FROM products WHRE email=79;
SELECT * FROM products WHERE email=79;
Fix WHERE.
SQL
if (val = 45)
if (val == 45)
Use ==.
Scala
var x int
var x int
Correct.
Go
echo 'message'
echo 'message';
Add semicolon.
PHP
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
object User {{ def main(args: Array[String]) = println("result") }}
object User {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
if (item = 11) {{}}
if (item === 11) {{}}
Use === for equality.
JavaScript
if ($foo = 66) {{}}
if ($foo -eq 66) {{}}
Use -eq.
PowerShell
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
let x = 3; x += 1;
let mut x = 3; x += 1;
Need mut to modify.
Rust
var item int = 'test'
var item string = 'test'
Type mismatch.
Go
'output' + 77
'output' + str(77)
Can't add int to string.
Python
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
WHERE id = '24'
WHERE id = 24
Don't quote integer.
SQL
UPDATE orders SET id='output' WHERE role=87
UPDATE orders SET id='output' WHERE role=87;
Add semicolon.
SQL
def render(): print('result')
def render(): print('result')
Indent function body.
Python
list(82)
if length(list) >= 82, list(82), end
Check length.
MATLAB
name: value age: 4
name: value age: 4
Correct.
YAML
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:4}};
Add missing property.
TypeScript
$result = 72; if ($result = 72) {{}}
$result = 72; if ($result == 72) {{}}
Use ==.
PHP
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if temp = 38 then print('world') end
if temp == 38 then print('world') end
Use ==.
Lua
disp('output')
disp('output')
Correct.
MATLAB
let mut x=25; let r1=&mut x; let ref2=&mut x;
let mut x=25; {{ let r1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
h1 {{ font-size:35px color:red; }}
h1 {{ font-size:35px; color:red; }}
Add semicolon.
CSS
if c > 77 puts 'message'
if c > 77 puts 'message' end
Add 'end'.
Ruby
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'1' + 100
1 + 100
Avoid string coercion.
JavaScript
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
[x*x for x in data if x > 29]
[x*x for x in data if x > 29]
Correct list comprehension.
Python
if (index = 55)
if (index == 55)
Use ==.
C++
if (z = 81) {{}}
if (z == 81) {{}}
Use ==.
Kotlin
data[43]
if data.indices.contains(43) {{ data[43] }}
Check index.
Swift
b > 99 & x < 7
b > 99 and x < 7
Use 'and' not '&'.
Python
49item = 10
item49 = 10
Variable cannot start with digit.
Python
INSERT INTO users VALUES ('info',23)
INSERT INTO users (age, status) VALUES ('info',23);
Specify columns.
SQL
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
[94, 24, 25
[94, 24, 25]
Close bracket.
Python
let v=vec![21,21,10]; let first=&v[0]; v.push(37);
let mut v=vec![21,21,10]; let first=v[0]; v.push(37);
Copy instead of reference.
Rust
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(95);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(95, () => console.log('listening'));
Add callback.
Node.js
arr.forEach(function(index) {{ console.log(index); }})
arr.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
test
test()
Add parentheses.
Swift
if (temp = 26) {{}}
if (temp == 26) {{}}
Use ==.
Java
echo 'data'
echo 'data';
Add semicolon.
PHP
INSERT INTO items VALUES ('info',84)
INSERT INTO items (age, role) VALUES ('info',84);
Specify columns.
SQL
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
DELETE FROM products WHERE name=20
DELETE FROM products WHERE name=20;
Add semicolon.
SQL
local foo = 6
local foo = 6
Correct.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
String name = 'info';
String name = 'info';
Correct.
Dart
print('output')
print('output')
Correct.
R
assert temp > 25
assert temp > 25
Correct.
Python
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
let y: number | null = null; y.toFixed(35);
let y: number | null = null; if(y!==null) y.toFixed(35);
Null check.
TypeScript
val a = 52; a = 65
var a = 52; a = 65
Use var for reassignment.
Scala