wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if x = 78
if x == 78
Use ==.
Ruby
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
INSERT INTO users VALUES ('world',27)
INSERT INTO users (age, role) VALUES ('world',27);
Specify columns.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(52);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(52, () => console.log('listening'));
Add callback.
Node.js
class Product {{ int item; }};
class Product {{ public: int item; }};
Make public.
C++
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (b = 49)
if (b == 49)
Use ==.
R
disp('result')
disp('result')
Correct.
MATLAB
val bar: Int = 'result'
val bar: String = 'result'
Fix type.
Kotlin
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
foo
foo()
Add parentheses.
Kotlin
my @arr = (25,36,51);
my @arr = (25,36,51);
Correct.
Perl
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let x = 33; let x = 78;
let x = 33; x = 78;
Duplicate declaration.
JavaScript
let v=vec![69,14,51]; let first=&v[0]; v.push(16);
let mut v=vec![69,14,51]; let first=v[0]; v.push(16);
Copy instead of reference.
Rust
let temp = 92;
let temp = 92;
Correct.
JavaScript
{{"name":"test",}}
{{"name":"test"}}
Remove trailing comma.
JSON
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
if num = 74 {{}}
if num == 74 {{}}
Use ==.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (bar = 81) {{}}
if (bar == 81) {{}}
Use ==.
Java
List(86,43,11)
List(86,43,11)
Correct.
Scala
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
name: data name: test,
name: data name: test
Remove comma.
YAML
<person age=50>
<person age="50">
Quote attribute.
XML
if z = 71 then print('result') end
if z == 71 then print('result') end
Use ==.
Lua
<br></br>
<br>
Self-closing.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int z = 'hello';
String z = 'hello';
Type mismatch.
Dart
values(79)
if length(values) >= 79, values(79), end
Check length.
MATLAB
// comment
/* comment */
Use /* */.
CSS
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
[x*x for x in arr if x > 9]
[x*x for x in arr if x > 9]
Correct list comprehension.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
while val > 98 val -= 1
while val > 98: val -= 1
Colon missing after while.
Python
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(89);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(89);
Correct.
Node.js
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
JOIN products ON products.id = products.status
JOIN products ON products.id = products.status
Correct.
SQL
'info' + 32
'info' + str(32)
Can't add int to string.
Python
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
print 'result'
print 'result';
Add semicolon.
Perl
if (x = 12) {}
if (x == 12) {}
Use ==.
Dart
jwt.sign({{id:80}}, 'secret');
jwt.sign({{id:80}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
WHERE id = '54'
WHERE id = 54
Don't quote integer.
SQL
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
local x = 68
local x = 68
Correct.
Lua
if (temp = 92) {{}}
if (temp === 92) {{}}
Use === for equality.
JavaScript
items[42]
if (length(items) >= 42) items[42]
Check length.
R
echo 'world'
echo 'world';
Add semicolon.
PHP
if (c = 90)
if (c == 90)
Use ==.
C++
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:8}};
Add missing property.
TypeScript
UPDATE products SET status='hello' WHERE status=96
UPDATE products SET status='hello' WHERE status=96;
Add semicolon.
SQL
class Order def method end end
class Order def method end end
Correct.
Ruby
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
{{'value':'data'}}
{{"value":"data"}}
Use double quotes.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
for i=1,58 do print(i) end
for i=1,58 do print(i) end
Correct.
Lua
if [ $x = 5 ]; then
if [ "$x" = 5 ]; then
Quote variable.
Shell
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
item = message
item = 'message'
Quote strings.
Python
x := 27
x := 27
Correct.
Go
if index > 66 puts 'value'
if index > 66 puts 'value' end
Add 'end'.
Ruby
assert result > 30
assert result > 30
Correct.
Python
for (int i=0; i<86; i++) {{}}
for (int i=0; i<86; i++) {{}}
Correct.
Java
<input type='text' value='test'>
<input type='text' value='test' name='title'>
Add name attribute.
HTML
if ($foo = 80) {{}}
if ($foo -eq 80) {{}}
Use -eq.
PowerShell
print('output')
print('output')
Correct.
R
val c = 21; c = 80
var c = 21; c = 80
Use var for reassignment.
Scala
if b = 66
if b == 66
Use ==.
MATLAB
function baz(): void {{ return 38; }}
function baz(): number {{ return 38; }}
Return type mismatch.
TypeScript
print 'output'
print('output')
print needs parentheses.
Python
SELECT * FROM products WHRE email=88;
SELECT * FROM products WHERE email=88;
Fix WHERE.
SQL
'hello' + 87
'hello' + 87.to_s
Convert int.
Ruby
'65' + 7
65 + 7
Avoid string coercion.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
println('hello')
println("hello")
Double quotes.
Scala
list.forEach(function(c) {{ console.log(c); }})
list.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
{{"value":"hello" "value":42}}
{{"value":"hello", "value":42}}
Add comma.
JSON
switch(bar){{ case 51: break; }}
switch(bar){{ case 51: break; default: break; }}
Add default case.
Java
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
let item = 'message'
let item = "message"
Double quotes.
Swift
const b = 23; b = 44;
let b = 23; b = 44;
Cannot reassign const.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const y;
const y = 77;
Initialize const.
JavaScript
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let text = String::from("hello"); let ref=&text; text.push_str("!");
let mut text = String::from("hello"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
[24, 80, 99
[24, 80, 99]
Close bracket.
Python
let str1 = String::from("hello"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
fn baz() -> i32 {{ 82 }}
fn baz() -> i32 {{ 82 }}
Correct.
Rust
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
int data[29]; data[29]=5;
int data[29]; if(29<29){{}} else data[29]=5;
Bounds check.
C++