# Reusability Improvements

**URL:** <https://talk.observablehq.com/t/reusability-improvements/1512>\
**Category:** Uncategorized\
**Created:** [December 17, 2018, 7:28pm UTC](https://talk.observablehq.com/t/reusability-improvements/1512 "2018-12-17T19:28:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bumbeishvili](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bumbeishvili/32/4220_2.png) [@bumbeishvili](https://talk.observablehq.com/u/bumbeishvili)\
**Post date:** [December 17, 2018, 7:28pm UTC](https://talk.observablehq.com/t/reusability-improvements/1512/1 "2018-12-17T19:28:16Z")

</div>

I have the following 2 reusability improvement ideas.

1. Automatically override cell values from query string
2. Automatically create functions from cell blocks

I know they may sound utopian, but I think they will be a good addition for the platform.

See the notebook for details:

> **[Observable reusability improvement ideas](https://beta.observablehq.com/@bumbeishvili/observable-reusability-improvement-ideas)**
>
> An Observable notebook by David Bumbeishvili.

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [December 17, 2018, 7:54pm UTC](https://talk.observablehq.com/t/reusability-improvements/1512/2 "2018-12-17T19:54:20Z")

</div>

Hi David, thanks for the feedback!

We can’t implement the first one for security reasons: it would allow someone to inject code (through the URL) that runs on your domain. For this reason we think the best approach is to make parameters explicit, as shown here:

> **[Parameterized Notebooks](https://beta.observablehq.com/@mbostock/parameterized-notebooks?foo=bar)**
>
> An Observable notebook by Mike Bostock.

As in:

```auto
params = new URLSearchParams(new URL(document.baseURI).search)

```

Your second suggestion is very interesting. We’ve considered a few approaches to parameterizing cells in the past, like import-with but within a notebook. I like the idea of cells-as-functions, though there are some details to work out so it’ll require further thought.

---

<div class="post-metadata">

**Author:** ![bumbeishvili](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bumbeishvili/32/4220_2.png) [@bumbeishvili](https://talk.observablehq.com/u/bumbeishvili)\
**Post date:** [December 17, 2018, 8:13pm UTC](https://talk.observablehq.com/t/reusability-improvements/1512/3 "2018-12-17T20:13:40Z")

</div>

For the first one , I was just thinking about simple cell values - string, boolean, number , I think it’ll be pretty easy to sanitize. I don’t know if this still will pose security issues, I haven’t thought about security regarding this matter at all.

For the second one - Yeah, agree , It’ll require more thinking , but I hope this feature(or similar, which allows parameterized cells) will end up implemented in Observable in future

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [December 17, 2018, 8:17pm UTC](https://talk.observablehq.com/t/reusability-improvements/1512/4 "2018-12-17T20:17:32Z")

</div>

> [@bumbeishvili](#):
>
> For the first one , I was just thinking about simple cell values - string, boolean, number , I think it’ll be pretty easy to sanitize. I don’t know if this still will pose security issues, I haven’t thought about security regarding this matter at all.

Personally I’d prefer an stdlib helper over something that can screw up any named cell and gives me no chance for further sanitization.

> [@mbostock](#):
>
> Your second suggestion is very interesting. We’ve considered a few approaches to parameterizing cells in the past, like import-with but within a notebook. I like the idea of cells-as-functions, though there are some details to work out so it’ll require further thought.

Since cells are already functions, perhaps a keyword similar to mutable and viewof could be introduced to get a reference to the cell’s outer function?

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [December 17, 2018, 8:28pm UTC](https://talk.observablehq.com/t/reusability-improvements/1512/5 "2018-12-17T20:28:15Z")

</div>

Unfortunately it’s not enough to just restrict the input types. Imagine you have a notebook that’s like

```auto
enforceAccess = true

```

And then someone can override that by setting ?enforceAccess=false in the URL. You would lessen the attack surface by restricting what values could be set by URL, but you could still change the behavior of a notebook in unexpected ways. (And, as Fabian points out, if this override happens at the platform layer it doesn’t give the author an opportunity to control what happens.)

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [December 17, 2018, 8:34pm UTC](https://talk.observablehq.com/t/reusability-improvements/1512/6 "2018-12-17T20:34:42Z")

</div>

Yep, exposing the cell’s definition function as `functionof foo` or something might be possible. The challenge is that you’d have to supply everything that `foo` references, which is a little brittle and perhaps non-obvious with larger cells; it’d be more robust if you could explicitly tell it which parameters you want to specify and left the others as implicit. Like:

```auto
k = 5
x = 8
y = 10 * k * x + 11

```

Then maybe:

```auto
functionof y({x: 42}) // k = 5 is implicit

```

(Just a sketch; don’t get attached to the syntax!)

---

<div class="post-metadata">

**Author:** ![bars](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bars/32/1768_2.png) [@bars](https://talk.observablehq.com/u/bars)\
**Post date:** [May 26, 2019, 7:43am UTC](https://talk.observablehq.com/t/reusability-improvements/1512/7 "2019-05-26T07:43:52Z")

</div>

This functionality is exactly what would be needed for my case: ["Recompute with...", or: a way to "climb the ladder of abstraction"](https://talk.observablehq.com/t/recompute-with-or-a-way-to-climb-the-ladder-of-abstraction/2008)

It would be amazing, specifically to map the behavior of an algorithm with a range of values. It would make Observable the best tool for running algorithm simulations!

---

<div class="post-metadata">

**Author:** ![j-f1](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/j-f1/32/368_2.png) [@j-f1](https://talk.observablehq.com/u/j-f1)\
**Post date:** [May 26, 2019, 10:56am UTC](https://talk.observablehq.com/t/reusability-improvements/1512/8 "2019-05-26T10:56:44Z")

</div>

A couple of API proposals:

```auto
y with { x: 42 }
Notebook.call('y', { x: 42 })

```

The second one would mesh nicely with [this other proposal of mine](https://talk.observablehq.com/t/access-current-cell-metadata/1873).
