-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
697 lines (687 loc) · 43.1 KB
/
Copy pathindex.html
File metadata and controls
697 lines (687 loc) · 43.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
<!DOCTYPE html>
<html>
<head>
<!-- Adobe TypeKit code for fonts -->
<script src="https://use.typekit.net/hws4qsv.js"></script>
<script>try{Typekit.load({ async: true });}catch(e){}</script>
<!-- -->
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<meta name="author" content="James Geddes">
<title>Cellular:</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="reveal.js/css/reveal.css">
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>
<link rel="stylesheet" href="reveal.js/css/theme/ati.css" id="theme">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'reveal.js/css/print/pdf.css' : 'reveal.js/css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="reveal.js/lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1 class="title">Cellular:</h1>
<h1 class="subtitle">A proposal for better spreadsheets</h1>
<h2 class="author">James Geddes</h2>
<h3 class="date">May 2016</h3>
</section>
<section id="the-west-coast-mainline-débâcle" class="slide level2">
<h1>The West Coast Mainline débâcle</h1>
<figure>
<img src="images/virgin-train.jpg" alt="Photo: Aaron Roberts https://www.flickr.com/photos/aaronsrailwayphots/ (CC BY-NC 2.0)" /><figcaption>Photo: Aaron Roberts https://www.flickr.com/photos/aaronsrailwayphots/ (CC BY-NC 2.0)</figcaption>
</figure>
<aside class="notes">
<p>In 2012, the franchise to run the train service on the West Coast intercity routes, at that time run by Virgin, was sent out to tender. Bidding companies submitted details of their bid, including detailed financial projections, to the Department for Transport. A company called FirstGroup won the bid and Virgin promptly launched a legal challenge.</p>
<p>As a result of the challenge, the award was scrapped. Three civil servants were suspended. Apparently at least £40m was paid to the bidders in compensation. A review found "significant technical flaws" in the way the bidding process was run.</p>
<p>At the heart of those technical flaws appears to have been a large spreadsheet.</p>
</aside>
</section>
<section id="its-not-just-government" class="slide level2">
<h1>It's not just government</h1>
<aside class="notes">
<p>Here's another example.</p>
<p>There were several problems with Reinhart and Rogoff's paper, some of which were simply debatable assumptions, and these had a greater effect on the result than the spreadsheet error. However, it was unarguable that there was a spreadsheet error. It was an illuminating one, and we'll take a look at it later.</p>
</aside>
<hr/>
<p>Carmen M. Reinhart, Kenneth S. Rogoff (2010). "Growth in a Time of Debt". <em>American Economic Review</em> <strong>100</strong> (2): 573–78.</p>
<hr/>
<blockquote>
<p>“George Osborne’s favourite ‘godfathers of austerity’ economists admit to making error in research” — the <em>Mirror</em></p>
</blockquote>
<blockquote>
<p>“The Rogoff-Reinhart data scandal reminds us economists aren’t gods” — <em>The Guardian</em></p>
</blockquote>
<blockquote>
<p>“The Excel Depression” — Paul Krugman</p>
</blockquote>
</section>
<section id="and-some-limitations-are-fundamental" class="slide level2">
<h1>And some limitations are fundamental</h1>
<figure>
<img src="images/FIT_Evidence_Review.png" alt="Source: DECC, Performance and Impact of the Feed-In Tariff Scheme: Review of Evidence" style="width:80.0%" /><figcaption>Source: DECC, Performance and Impact of the Feed-In Tariff Scheme: Review of Evidence</figcaption>
</figure>
<aside class="notes">
<ol type="1">
<li><p>Where is the uncertainty?</p></li>
<li>What should we do in year 2?</li>
</ol>
</aside>
</section>
<section class="slide level2">
<figure>
<img src="images/algorithms.png" alt="Cartoon by Randall Munroe, http://xkcd.com/1667/ (cc by-nc 2.5)" /><figcaption>Cartoon by Randall Munroe, http://xkcd.com/1667/ (cc by-nc 2.5)</figcaption>
</figure>
<aside class="notes">
<p>Hello. My name is James Geddes and I have some bad news for you: the world runs on Excel.</p>
<p>From 2002 to 2009 I was a strategy consultant. I helped some of the largest companies in the world make decisions. I helped an airline open a new transatlantic route; I helped a mining company improve the performance of their mines; I even had the privilege of helping a chain of pubs set the price of beer.</p>
<p>How did I know what to advise our clients? I built models. A model is a mathematical simplification of the world. It keeps you honest. It lets you test out your ideas. If I make such-and-such a change, what will happen to my profits?</p>
<p>I worked for one of the most prestigious stategy consulting firms. We pride ourselves on our quantitative focus. We must use some pretty amazing modelling tools, right? Well, we used Excel. Excel <em>is</em> pretty amazing in some ways -- it's amazing because <em>everyone can use it</em>. It's less amazing in other ways.</p>
<p>From 2009 to 2014 I worked at the Department of Energy and Climate Change. I worked with a team attempting to answer the question, how do we reduce the UK's greenhouse gas emissions by 80% over the next 40 years? To answer this question, we built a model: I was the architect of this model although you could say that the godfather of the model was David MacKay. The model simulated the entire energy system of the UK for 40 years. We must have used some pretty complex software, right? Well, we used Excel. It <em>was</em> a pretty sophisticated Excel model in some ways. Less so in others.</p>
<p>Directly as a result of the West Coast mainline debacle, the government produced a review -- the MacPherson review -- to explain how to build and quality assure models properly. That review cited the 2050 model as one of its examples of how to do it right.</p>
<p>Government runs on Excel. That's what government analysts use. Often, of course, analysis is outsourced to a technical consulting company. <em>They</em> might use linear programming or something. But in government: Excel.</p>
<p>Later on, we helped other governments build their own versions of the model. China build one, India built one, even Wallonia built one. Each time we helped a country build their model we would reconstruct our enormous Excel spreadsheet, painfully making hundreds of manual changes, introducing errors as we did so.</p>
<p>Well, I've had enough. I never want to build another Excel model again. Cellular is my plan.</p>
<p>Visicalc (1979) was the “killer app” for the Apple II. You bought an Apple II because you wanted to run Visicalc. Lotus 1-2-3 was the killer app for PCs. Microsoft Multiplan -- 1982 Lotus 1-2-3 -- 1983 Excel Mac -- 1985 Excel Windows -- 1987 Quattro Pro -- 1988 (Intended to compete with Lotus, still available from Corel(!)) Improv -- 1991 (Innovative -- separated data, view, and formulas) Analytica -- 1996 Google -- 2006</p>
</aside>
</section>
<section class="slide level2">
<!-- ========================= TABLE OF CONTENTS ========================== -->
<h3 id="background-to-spreadsheet-modelling">Background to spreadsheet modelling</h3>
<h3 id="the-challenge-of-doing-better">The challenge of doing better</h3>
<h3 id="cellular">Cellular</h3>
<h3 id="uncertainty">Uncertainty</h3>
<!-- =================== A BRIEF HISTORY OF SPREADSHEETS ================== -->
</section>
<section id="background-to-spreadsheet-modelling-1" class="slide level2">
<h1>Background to spreadsheet modelling</h1>
</section>
<section class="slide level2">
<figure>
<img src="images/spreadsheet-history.png" />
</figure>
</section>
<section id="visicalc-the-first-killer-app" class="slide level2">
<h1>VisiCalc: the first ‘killer app’</h1>
<figure>
<img src="images/Visicalc.jpg" alt="Screenshot of VisiCalc on the Apple II. Photo: apple2history.org" /><figcaption>Screenshot of VisiCalc on the Apple II. Photo: apple2history.org</figcaption>
</figure>
<aside class="notes">
<p>A quick word here about what I'm not going to discuss. VisiCalc did not have any sort of embedded programming environment. Excel does, however: it has Visual Basic for Applications, VBA. VBA is a complete programming language. Any of the restrictions I'm going to discuss could I suppose be worked around by sufficiently clever use of VBA. Indeed, I've built models with VBA -- particularly in order to automate some part of a workflow so that end-users did not have perform a series of manual steps.</p>
<p>I'm not going to make a strong argument here. Let me just say that I have never seen a model which includes VBA which is at all comprehensible. In terms of clarity and robustness, VBA has in my experience only ever made things worse.</p>
</aside>
</section>
<section id="excel-has-been-dominant-for-20-years" class="slide level2">
<h1>Excel has been dominant for 20 years</h1>
<figure>
<img src="images/spreadsheet-ngrams.png" alt="A history of spreadsheets. Source: Google ngrams." /><figcaption>A history of spreadsheets. Source: Google ngrams.</figcaption>
</figure>
<aside class="notes">
<p>Excel has, perhaps, on the order of 750 million users.</p>
</aside>
<!-- =================== THE CHALLENGE OF DOING BETTER ================== -->
</section>
<section id="the-challenge-of-doing-better-1" class="slide level2">
<h1>The challenge of doing better</h1>
</section>
<section class="slide level2">
<figure>
<img src="images/reinhart_rogoff_ss.png" alt="Reinhart and Rogoff’s spreadsheet. Source: Thomas Herndon, Michael Ash, and Robert Pollin via Mike Konczal" style="width:60.0%" /><figcaption>Reinhart and Rogoff’s spreadsheet. Source: Thomas Herndon, Michael Ash, and Robert Pollin via Mike Konczal</figcaption>
</figure>
<aside class="notes">
<ul>
<li><p>NB: Spreadsheet error was not the only issue taken with the paper. But it's a good example of the sort of errors that occur.</p></li>
<li>First, some structures that we see often in a spreadsheet:</li>
<li><p>A set of values down the left; a set of values across the top; and in the intersections values whose meaning is codified by the product of the row and column headers.</p>
<p>There are many ways to lay out a spreadsheet; this is one of them. It has the virtue of being structured and of conforming to the two dimensions available.</p></li>
<li><p>A expression whose arguments are a set of related data.</p></li>
<li>There are also some problems common to spreadsheets:</li>
<li><p>Metadata (formatting) used to convey meaning -- where is the key? Is it important?</p></li>
<li><p>Inputs, intermediate values, and outputs mixed up. A well-designed spreadsheet has a linear ordering of data flow: eg, top to bottom. Here is not clear what the "maximum" etc fields at the top are.</p></li>
<li><p>Hidden columns. What's going on in there?</p></li>
<li><p>And of course the major problem with this spreadsheet, which is a simple formula error.</p></li>
<li><p>How can we fix this kind of error?</p></li>
</ul>
</aside>
</section>
<section id="how-do-we-make-good-software-anyway" class="slide level2">
<h1>How do we make good software anyway?</h1>
<blockquote>
<p>The art of programming is the art of organising complexity [...] — <em>Edsger W. Dijkstra</em> (1930–2002)</p>
</blockquote>
<blockquote>
<p>Controlling complexity is the essence of computer programming. — <em>Brian Kernighan</em> (1942–)</p>
</blockquote>
<blockquote>
<p>There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. — <em>C. A. R. Hoare</em> (1934–)</p>
</blockquote>
<aside class="notes">
<p>Okay, so how do we control complexity?</p>
</aside>
</section>
<section id="modularity-and-abstraction" class="slide level2">
<h1>Modularity and abstraction</h1>
<table>
<thead>
<tr>
<th width="20%" style="text-align: center;">
Complex
</th>
<th width="40%" style="text-align: center;">
Modular
</th>
<th width="40%" style="text-align: center;">
Abstract
</th>
</tr>
</thead>
<tr>
<td style="text-align: center; vertical-align: top;">
<img src="images/graphviz/complex-1.svg" />
</td>
<td style="text-align: center; vertical-align: top; font-size: 70%;">
<figure>
<img src="images/graphviz/complex-2.svg" />
</figure>
Decompose the system into separate, weakly-coupled parts, with well-defined interfaces between them.
</td>
<td style="text-align: center; vertical-align: top; font-size: 70%;">
<figure>
<img src="images/graphviz/complex-3.svg" />
</figure>
<p>“Abstraction principle: Each significant piece of functionality in a program should be implemented in just one place in the source code. Where similar functions are carried out by distinct pieces of code, it is generally beneficial to combine them into one by <em>abstracting out</em> the varying parts.”</p>
— Benjamin C. Pierce, <em>Types and Programming Languages</em>
</td>
</tr>
</table>
<aside class="notes">
<p>Let me outline for you some of the challenges faced by spreadsheet modellers. I'm going to spend some time on this slide and the next one.</p>
<p>Consider in particular three good practices in software development. There are many practices, of course, such as: unit testing, requirements specification, coding conventions, and what have you; but these two seem to ne to get to the essence of <em>programming</em> as opposed to an arbitrary technical design activity.</p>
<p>First of all, if you have a complicated problem, you should break it down into subproblems, each of which is simpler. Ideally, each subpart would do one, conceptually coherent, thing. Also, the connections between the subparts should be as simple as possible -- they should be "weakly coupled." All this means that one can worry about one subpart at a time.</p>
<p>Second, there's a principle that's often expressed as "Don't repeat yourself." Any time you find yourself doing thing same thing over and over: don't. Write it once, in one place, and re-use the code you've written where you need it. Again, this means fewer places to look and therefore fewer things to worry about at once.</p>
<p>This second step often requires some kind of abstraction or generalisation. It's not always obvious that one is doing the same thing. Often, in fact, one is doing "the same thing, <em>mutatis mutandis</em>, and then the goal is to write a more general model that can be reused in specific circumstances.</p>
</aside>
</section>
<section id="spreadsheets-kind-of-support-modularity" class="slide level2">
<h1>Spreadsheets <em>kind of</em> support modularity</h1>
<ul>
<li><p>Worksheets are often used to separate concerns <img src="images/ss-tabs.png" style="width:65.0%" /></p></li>
<li><p>Columns are often used to group elements of a repeated calculation <img src="images/ss-grouping.png" style="width:65.0%" /></p></li>
<li><p><strong>But</strong>: it's hard to define the "interfaces"</p>
<pre><code>=IFERROR(INDEX(INDIRECT($C10 & ".Outputs[" & this.Year & "]"),
MATCH(G$5, INDIRECT($C10 & ".Outputs[Vector]"), 0)), 0)</code></pre></li>
</ul>
<aside class="notes">
<p>In some sense, Excel does quite well here. Of course, it's up to the modeller to correctly choose the subproblems, but once she does so, Excel provides some presentational techniques to help manage the separation. One can place different tasks on different worksheets, for example, or, for simple submodels, in different rows or columns.</p>
<p>Most good modellers will do precisely this. Indeed, organisations typically set up standards for the use of each worksheet: here's an example of one such.</p>
<p>Still, it's not great. It's not enough simply to separate different parts of the model: one must define the ways in which the parts interact. Most programming languages have some facility for constructing the interface between components. That facility will typically ensure that the components cannot be used except through the interface, a constraint known as "information hiding" -- not keeping secrets, but making sure that it's clear how and when one part of the model interacts with another. In Excel one must enforce such separation through convention and practice. For example, in the 2050 Calculator, we made a rule that inputs to a worksheet must exist only in a defined block at the top of the worksheet; when those values were needed somewhere in the worksheet, they were taken from that block at the top, not directly from source.</p>
<p>And perhaps this principle finds its most useful expression in the design of "libraries": pre-built software components that perform some task commonly used in other programs. Almost every Excel model is built <em>de novo</em>. There's no "import workbook". (Well, you can copy and paste but that never leads anywhere good.) Real models of the real world involve physical units and every spreadsheet that uses units has an <em>ad hoc</em> solution to the problem. It would be nice to solve this problem once and allow modellers to re-use that solution. It would be even nicer if, when we discovered bugs in or made improvements to our common solution, those changes could painlessly be incorporated in users' models.</p>
<p>You know -- just to say -- looking at the third example, isn't it absolutely clear that if you can do <em>that</em> -- surely, <em>surely</em> you could write some code!</p>
</aside>
</section>
<section id="spreadsheets-do-not-support-abstraction" class="slide level2">
<h1>Spreadsheets <em>do not</em> support abstraction</h1>
<ul>
<li><p>Operations are repeated</p>
<figure>
<img src="images/ss-dry-fail.png" style="width:65.0%" />
</figure></li>
<li><p>Large formulae are repeated</p>
<pre><code>=IFERROR(INDEX(INDIRECT($C10 & ".Outputs[" & this.Year & "]"),
MATCH(G$5, INDIRECT($C10 & ".Outputs[Vector]"), 0)), 0)</code></pre></li>
<li><p>No structured data, higher-order functions, ...</p></li>
</ul>
<aside class="notes">
<p>One often wishes to abstract some calculation and the re-use it. It is very hard to do this in Excel. About the best we can do is copy the calculation from one cell to another and make sure that references to other cells are made relative to the copied cell. We can assume that this is what was done, for example, in the Reinhart and Rogoff model.</p>
<p>Why is this a problem? It's a problem because we are repeating ourselves. Once we repeat ourselves, inevitably one of those repetitions will be wrong. There's no way to tell Excel, "look, this is the same calculation, so make sure you really are computing the same calculation."</p>
<p>(Note to experienced modellers: array formulae are a thing that exists, of course. In some sense, array formulae are one of the most "Excel-like" things in Excel. But as you know, they have their own problems. And VBA also exists but -- at least in my view -- there is a huge impedance mismatch between the "Excel" way of doing things and the "VBA" way of doing things.)</p>
<p>Repeating larger blocks is much harder. Typically the problem is that you want to repeat something <em>mutatis mutandis</em> and so the question is, how do you explain which mutandis must be mutatis? Here's an example from the 2050 Calculator.</p>
<p>Why did I write this monstrosity? So that an entire worksheet could be reproduced from a copy of another one, whilst making sure that the copy "knew" it was a copy.</p>
<p>Look aActually, this example is a good illustration of the challenges of the third principle. What does all this palavar <em>mean</em>? In a spreadsheet, every expression is written at the lowest level -- the only level. To work out what something is trying to do it's necessary to, well, work it out. We get around this with conventions -- naming conventions, formatting conventions, structure conventions -- but it's a very weak solution.</p>
<p>This formula looks up a particular energy flow from a particular sector for a particular year, making sure the result is zero if that kind of energy isn't produced or consumed by that sector. But you wouldn't know it to look at this.</p>
<p>It's worse than you think. Because of a flaw in the way certain references are implemented in Excel, one has to encode them in character strings! That, right there, will be -- and was -- an enormous source of bugs when you want to create a similar model.</p>
<p>So our task is clear: figure out how to introduce these development practices into a spreadsheet paradigm. But we must be careful.</p>
</aside>
</section>
<section id="so-why-do-people-use-spreadsheets" class="slide level2">
<h1>So why do people use spreadsheets?</h1>
<ol type="1">
<li><p>Spreadsheets are incremental</p>
<ul>
<li>Start small, gradually get better</li>
<li>Even the basic stuff is useful (eg, making tables)</li>
<li>No big jumps in learning</li>
</ul></li>
<li><p>Spreadsheets are immediate</p>
<ul>
<li>Changes are immediately reflected in the output</li>
<li>Faster learning, quicker debugging</li>
</ul></li>
<li><p>... and, perhaps, because abstraction is not easy</p></li>
</ol>
<aside class="notes">
<p>Here's our main problem. There's a <em>reason</em> that we can't apply those three software development practices in Excel, which is that spreadsheets don't support them. And the reason for that is that spreadsheets do support something else: they support people.</p>
<p>Spreadsheets are incremental. You can start small and build up in easy steps. And even the small stuff is useful.</p>
<p>They are immediate. If you like, the edit-compile-test loop is very, very fast. That makes learning easier and it makes debugging quicker.</p>
<p>And of course, they are not abstract, and perhaps abstraction is hard. Certainly, since there are no abstractions there are, <em>a fortiori</em>, no leaky abstractions.</p>
<p>So if we are going to make something that people will use, we had better keep those features of spreadsheets that made them usable in the first place.</p>
<p>You know, there are two kinds of complexity in the world.</p>
<p>FIXME: Story of Ptolemaic epicycles (AD 100 ish) vs. Newton's laws (late 1600s) resulting in Keplerian motion (early 1610-1620s)</p>
</aside>
</section>
<section id="the-plan" class="slide level2">
<h1>The plan</h1>
<ol type="1">
<li><p>Observe that spreadsheets are already a lot like a simplistic programming language</p></li>
<li><p>Write this language explicitly, so that spreadsheets are written as programs</p>
<ul>
<li>whilst keeping the benefit/cost tradeoff positive!</li>
</ul></li>
<li><p>Generalise the language to include more powerful features</p>
<ul>
<li>without losing the ease of use!</li>
</ul></li>
</ol>
<!-- ===================== THE PLAN ==================== -->
</section>
<section id="cellular-1" class="slide level2">
<h1>Cellular</h1>
</section>
<section id="every-spreadsheet-is-a-term-graph" class="slide level2">
<h1>Every spreadsheet is a term graph</h1>
<table>
<tr>
<td style="width: 55%; vertical-align: middle;">
<pre><code> | A | B |
===+=================+============+
1 | Salary | 21000 |
2 | Allowance | 11000 |
3 | Taxable income | = B1 - B2 |
4 | Basic rate | 0.2 |
5 | Tax payable | = B3 * B4 |</code></pre>
</td>
<td style="vertical-align: middle;">
<img src="images/graphviz/eg-tax-calc-expression-tree.svg" />
</td>
</tr>
</table>
<p>Very simple term graph: only values and built-in functions. No user-defined types, no lambda abstractions, no first-class functions, no iteration or recursion.</p>
<aside class="notes">
<p>Here is a simple model written as a spreadsheet. It's a typical spreadsheet model. Computation proceeds from inputs to outputs; in this case from top-to-bottom. It's considered good design practice to lay out a spreadsheet in this way to aid in comprehension. In some sense, it's a primitive form of information hiding: if you want to find the values that enter into a particular computation you know that must look above the cell containing the computation.</p>
<p>The cells of any spreadsheet can be arranged as the nodes in a directed graph. A node in this graph is either a value or an expression of the values in other nodes and the arrows of the graph show which cells depend on which others. I am going to leave out the comments for these examples but clearly part of the challenge will be to figure out how to incorporate them since they play a key role in real spreadsheets.</p>
<p>The graph is acyclic: Excel will complain if the spreadsheet contains what it calls "circular references". It is possible to force Excel to allow cycles, but models incorporating such features are thought of as something of a hack.</p>
<p>Some cells in this example have no dependencies nor are dependent on other cells: these are the labels, which I think are akin to comments in a program.</p>
<p>Well, now we have an expression graph. In fact, we have what looks very like an abstract symantic graph, such as built by a compiler. In which case, we ought to be able to write down one or more languages which "compile to" precisely this expression graph.</p>
<p>This language is extremely simple: it is a purely functional language with neither iteration nor recursion; nor are functions first-class values.</p>
</aside>
</section>
<section id="term-graphs-are-programs" class="slide level2">
<h1>Term graphs are programs</h1>
<table>
<tbody>
<tr>
<td style="vertical-align: middle;">
Topological sort:
</td>
<td style="vertical-align: middle;">
<img src="images/graphviz/eg-tax-calc-expression-tree-linear.svg" />
</td>
</tr>
<td style="vertical-align: middle;">
Then write out each step:
</td>
<td>
<div class="sourceCode"><pre class="sourceCode pascal"><code class="sourceCode pascal">B1 := <span class="dv">21000</span>
B2 := <span class="dv">11000</span>
B3 := B1 - B2
B4 := <span class="dv">0.20</span>
B5 := B3 * B4</code></pre></div>
</td>
</tr>
<tr/>
</tbody>
</table>
<p>Poor choice of surface syntax for users: too many definitions. But perhaps useful as a target language which can then be used to generate any particular spreadsheet (Excel, Numbers, ...)</p>
<aside class="notes">
<p>Here's one approach, which is almost a direct translation of the spreadsheet. We take the expression graph of the spreadsheet and linearise it. Note that</p>
<p>Then we simply bind the value of each node to a different symbol. Here I've chosen the symbols to be precisely the names of the cells that gave rise to this graph.</p>
<p>Execution proceeds in a single path: there are no branches or loops. (Conditionals are expressions.)</p>
<p>In this view, a program consists of a series of assignments, the left-hand side of which is a previously unused symbol and the right-hand side is an expression involving primitive operators and functions and previously-named symbols.</p>
<p>Any directed acyclic graph can be written in this way -- it doesn't have to be a tree as in this example.</p>
<p>So this could be our programming language. It has the nice feature that, as a "step by step" recipe, it appears to follow the spreadsheet modeller's thought process.</p>
<p>Of course, we'd still need some sensible way of assigning these variables to cells: a single column spreadsheet is not particularly user friendly.</p>
<p>A larger problem, in my view, is that this style imposes a cognitive burden on the modeller in that it requires the modeller to worry about things they don't want to worry about: specifically, naming things. Choosing names is hard, and the beauty of spreadsheets is that you don't have to choose names: you just use an empty cell. You don't even have to remember the name later, you can just point at the cell.</p>
<p>That barrier seems to me to be too high. My intuition is that spreadsheet modellers will find it too hard to create names. And why should they? This language is too low-level.</p>
<p>However, I think it is a good <em>final</em> target. It's like "machine code for spreadsheets", in that, with the exception of layout, we could convert this into any particular spreadsheet: Excel, LibreOffice, Numbers, Google docs, and so on.</p>
<p>I propose the name "grid" for this language (which is still somewhat undefined).</p>
</aside>
</section>
<section id="a-possible-language-hierarchy" class="slide level2">
<h1>A possible language hierarchy</h1>
<figure>
<img src="images/graphviz/languages.svg" />
</figure>
<table>
<tbody>
<tr class="odd">
<td style="text-align: left;"><strong>cell</strong></td>
<td>Full language, supporting abstraction and modularity. Ideally, a superset of nocell.</td>
</tr>
<tr class="even">
<td style="text-align: left;"><strong>nocell</strong></td>
<td>A language with the same expressive power as a spreadsheet (and no more) but a more convenient surface syntax.</td>
</tr>
<tr class="odd">
<td style="text-align: left;"><strong>grid</strong></td>
<td>An intermediate representation of a spreadsheet, from which a number of backends could produce specific formats.</td>
</tr>
</tbody>
</table>
<p>(No probabilistic elements yet.)</p>
</section>
<section id="whats-the-surface-syntax-of-cellnocell" class="slide level2">
<h1>What's the surface syntax of cell/nocell?</h1>
<ul>
<li><p>Perhaps a conventional function syntax?</p>
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c">times(<span class="fl">0.20</span>, minus(<span class="dv">21000</span>, <span class="dv">11000</span>))</code></pre></div></li>
<li><p><strong>But</strong> spreadsheet modellers tend to think in terms of a "data-flow" model: Here's some data; here's the operation; here's the result; here's an operation on that ...</p></li>
<li><p>cf. the R package ‘magrittr’, which allows one to write, eg,</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">data %>%<span class="st"> </span><span class="kw">filter</span>() %>%<span class="st"> </span><span class="kw">summarise</span>()</code></pre></div></li>
<li><p>=> Can we retain this style of interactive / incremental programming?</p></li>
</ul>
<aside class="notes">
<p>What about conventional syntax?</p>
<p>Well, it has the benefit over the previous attempt that we don't have to make up names for things. And it looks like a conventional (functional) programming language.</p>
<p>But in fact I think this is a problem. Whatever cellular is, it probably had better <em>not</em> look like a conventional programming language. Spreadsheet programmers don't get programming languages, otherwise they'd be programmers.</p>
<p>My hypothesis here is that -- if we go back to the original tax calculation -- spreadsheet programmers think in a dataflow model. They start with the data (because it's concrete!) then that data is transformed in some way, then it's transformed in some other way, until we get to the answer.</p>
<p>In contrast, the standard nested functional application is precisely the other way round: it says do X to the result of doing Y to the result of doing Z to A. Of course, we could unwrap the functions by naming the arguments -- but then we're back to the naming problem.</p>
</aside>
</section>
<section id="alternative-forms-of-surface-syntax" class="slide level2">
<h1>Alternative forms of surface syntax</h1>
<p>Why not just write the spreadsheet as if you were writing a spreadsheet?</p>
<table>
<tr>
<th width="50%">
Postfix
</th>
<th>
Spreadsheet-y
</th>
</tr>
<tr>
<td width="50%" style="font-size: 90%;">
<div class="sourceCode"><pre class="sourceCode scheme"><code class="sourceCode scheme"><span class="dv">21000</span> <span class="co">; Salary</span>
<span class="dv">11000</span> <span class="co">; Personal allowance</span>
<span class="kw">-</span> <span class="co">; = Taxable income</span>
<span class="fl">0.20</span> <span class="co">; Basic rate</span>
* <span class="co">; = Tax payable </span></code></pre></div>
</td>
<td style="font-size: 90%;">
<div class="sourceCode"><pre class="sourceCode scheme"><code class="sourceCode scheme"><span class="dv">21000</span> <span class="co">; Salary</span>
<span class="dv">11000</span> <span class="kw">-</span> <span class="co">; less, Personal allowance</span>
<span class="kw">=</span> <span class="co">; Taxable income</span>
<span class="fl">0.20</span> * <span class="co">; Basic rate</span>
<span class="kw">=</span> <span class="co">; Tax payable</span></code></pre></div>
</td>
</tr>
<tr>
<td style="font-size: 70%; vertical-align: top;">
<ul>
<li><p>No names (‘;’ means ‘comment’)</p></li>
<li><p>Order parallels order of construction of spreadsheet</p></li>
<li><p>Lends itself to building “collections of data” in an interactive manner (see later)</p></li>
<li>But postfix languages haven't caught on. (Why not?)</li>
</ul>
</td>
<td style="font-size: 70%; vertical-align: top;">
<ul>
<li><p>Reminiscent of a printing calculator</p></li>
<li><p>‘=’ here means “don’t do anything, but let me label this cell in the comments”</p></li>
<li>Other ideas for usable syntax:
<ul>
<li>‘=’ means “function application” (like Excel?!)</li>
<li>‘(...)’ means “... is in infix notation”</li>
</ul></li>
</ul>
</td>
</tr>
</table>
<aside class="notes">
<p>The thing I have to say here is, I think we just need to get something working and then iterate,</p>
</aside>
</section>
<section id="open-questions" class="slide level2">
<h1>Open questions</h1>
<ol type="1">
<li><p>Does cell “compile” to nocell?</p>
<ul>
<li>Unwrap loops, expand functions, ...</li>
</ul></li>
<li><p>Or is it a “nocell-constructing” language?</p>
<ul>
<li><p>“Spreadsheets as values”</p></li>
<li><p>It would be ideal if, every time the user hits ‘return’, the spreadsheet-so-far is generated, and that spreadsheet is the same as the one obtained by compiling/running the program so far.</p></li>
</ul></li>
</ol>
</section>
<section id="layout-the-other-half-of-the-challenge" class="slide level2">
<h1>Layout: the other half of the challenge</h1>
<figure>
<img src="images/ucl-finances.png" style="width:80.0%" />
</figure>
<aside class="notes">
<p>It's clear that we could translate the operational part of programs written in a simple language like nocell into a spreadsheet simply by converting each node in the tree to a cell. It's reasonably plausible that we could make a more expressive language which is then evaluated to produce a nocell program by instantiating function bodies explicitly, unravelling loops, and so on.</p>
<p>But the resulting spreadsheet is likely to be unreadable and that would defeat the whole purpose of cellular.</p>
<p>So a huge challenge is as follows: how do we translate the semantic information inherent in the language cell to a well-structured spreadsheet?</p>
<p>Some things are clear from traditional principles of good spreadsheet design: the values of function application should be in cells below or to the right of their arguments, for example. The equivalent of vector datatypes should be in contiguous blocks of cells if possible.</p>
<p>Plausibly, most high-level operations that are used by spreadsheet models are map/reduce type operations. Those should be laid out in contiguous cells as well.</p>
<p>Some things are easy: we know what counts as sub-calculations, so we can provide appropriate formatting to each cell.</p>
<p>This is a challenge -- but I also think it's an enormous opportunity.</p>
<p>Making nice-looking, well-structured tables out of data is notoriously hard. A recent article in Significance called in "making sunbeams from cucumbers". If we could provide a mechanism that made it <em>easier</em> for people to make tables, that would be a reason to use the software, and could overcome analyst's natural reluctance to move beyond Excel.</p>
<p>I don't have an answer, but it feels like an answerable task. I think perhaps we should be thinking in terms of types, as in data types. It feels to me that tables are a visual representation of algebraic data types. To be explored.</p>
</aside>
</section>
<section id="summary" class="slide level2">
<h1>Summary</h1>
<table>
<tr>
<th width="10%">
</th>
<th width="30%">
cell
</th>
<th width="30%">
nocell
</th>
<th width="30%">
grid
</th>
</tr>
<tr>
<th style="font-size: 70%;">
Semantics
</th>
<td style="font-size: 70%;">
Functional, first-class functions, rich set of data types, user-defined data types,
</td>
<td style="font-size: 70%;">
Purely functional, primitive types only (numeric, string, boolean, perhaps vector), built-in functions only, names.
</td>
<td style="font-size: 70%;">
Like nocell, but every expression assigned to a cell. Names changed to named ranges.
</td>
</tr>
<tr>
<th style="font-size: 70%;">
Surface syntax
</th>
<td style="font-size: 70%;">
?
</td>
<td style="font-size: 70%;">
<div class="sourceCode"><pre class="sourceCode scheme"><code class="sourceCode scheme"><span class="dv">100</span>
<span class="dv">200</span>
<span class="dv">300</span>
sum</code></pre></div>
</td>
<td style="font-size: 70%;">
<div class="sourceCode"><pre class="sourceCode pascal"><code class="sourceCode pascal">A1 := <span class="dv">100</span>
A2 := <span class="dv">200</span>
A3 := <span class="dv">300</span>
A4 := SUM(A1, A2, A3)</code></pre></div>
</td>
</tr>
<tr>
<th style="font-size: 70%;">
Other
</th>
<td style="font-size: 70%;">
</td>
<td style="font-size: 70%;">
Structures annotated with information to inform <strong>layout</strong>.
</td>
<td style="font-size: 70%;">
Cells annotated with information to determine <strong>cell style</strong>.
</td>
</tr>
</table>
</section>
<section id="adding-uncertainty-to-models" class="slide level2">
<h1>Adding uncertainty to models</h1>
<figure>
<img src="images/graphviz/languages-with-p.svg" alt="PPL = Probabilistic Programming Language" /><figcaption>PPL = Probabilistic Programming Language</figcaption>
</figure>
<ul>
<li><p>Use an existing language for stochastic simulation and inference, restricting class of models to those expressible in nocell</p></li>
<li><p>Add stochastic data with a few new VBA functions (eg, <span style="font-size:
83%;"><code>=NORMAL(0,1)</code></span>)</p></li>
<li><p>Output of PPL modelled as Monte Carlo runs on separate worksheet, with named ranges, eg, <span style="font-size: 83%;"><code>=MEDIAN(param1)</code></span></p></li>
</ul>
<!-- ==================== THE CHALLENGES OF CELLULAR ====================== -->
</section>
<section id="challenges" class="slide level2">
<h1>Challenges</h1>
<ul>
<li><p>Must make at least some tasks <strong>easier</strong>, eg,</p>
<ul>
<li><p>Formatting tables (always a pain), "LaTeX for spreadsheets";</p></li>
<li><p>Make probabilistic calculations possible.</p></li>
</ul></li>
<li><p>Must extend the "natural" language of spreadsheets</p></li>
<li><p>Must allow incremental transition from concrete to abstract</p></li>
<li><p>Must be interactive</p>
<ul>
<li>eg, a "REPL" that generates a spreadsheet each time</li>
</ul></li>
</ul>
</section>
<section id="other-proposals" class="slide level2">
<h1>Other proposals</h1>
<ul>
<li><p>User-centred functions (SPJ)</p></li>
<li><p>Gencel (templates for Excel)</p></li>
<li><p>ModelSheet Authoring (specific kinds of models)</p></li>
<li><p>Tabular</p></li>
<li><p>Improv</p></li>
<li><p>Scenarios (FW)</p></li>
</ul>
<h3 id="all-of-these-use-the-spreadsheet-as-the-gui">All of these use the spreadsheet as the GUI</h3>
<aside class="notes">
<p>One good question to ask is: what haven't these succeeded?</p>
<ul>
<li><p>Maybe they will, just not yet?</p></li>
<li><p>They involve changing the spreadsheet model</p></li>
<li>They involve extensions to Excel (breaks collaboration)</li>
</ul>
</aside>
<!-- ============================= CHALLENGES ============================= -->
</section>
<section id="unused-slides" class="slide level2">
<h1>UNUSED SLIDES</h1>
</section>
<section id="other-kinds-of-models" class="slide level2">
<h1>Other kinds of models</h1>
<ul>
<li><p>Maximisation</p></li>
<li><p>Dynamic simulation</p></li>
<li><p>Agent-based simulation</p></li>
<li><p>Equilibrium-finding</p></li>
<li><p>“Full” Bayesian inference</p></li>
</ul>
</section>
</div>
</div>
<script src="reveal.js/lib/js/head.min.js"></script>
<script src="reveal.js/js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
// Display controls in the bottom right corner
controls: false,
// Display the page number of the current slide
slideNumber: true,
// Vertical centering of slides
center: true,
// Transition style
transition: 'fade', // none/fade/slide/convex/concave/zoom
// Transition speed
transitionSpeed: 'fast', // default/fast/slow
// Optional reveal.js plugins
dependencies: [
{ src: 'reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'reveal.js/plugin/zoom-js/zoom.js', async: true },
{ src: 'reveal.js/plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>