TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: What would Excel's formula language look like if you invented it today?

30 pointsby r4vikover 11 years ago
If you were to invent a language to be used in spreadsheets today, what would it look like?<p>Would you just jump on the JavaScript bandwagon?<p>Google Docs clones the Excel formula language for use in cells but allows you to write extensions&#x2F;macros (where you would use VBA) in Google Apps Script but what is it really? It looks a lot like JavaScript. The documentation totally sucks, it lives in the Google Apps Script IDE, the debugging is terrible. It can&#x27;t easily be shared or put on github and it&#x27;s hard to test.<p>Why not have a single language for the cells and for extensions? I&#x27;m thinking real JavaScript would be interesting, as in is being able to import external scripts and exporting their globals into the spreadsheet&#x27;s namespace then being able to set a cell to apply the function and display the output of that function.<p>So you could set the value of a cell to `=function(i){Math.pow(i,2)}(A2)` this would apply JavaScript&#x27;s `Math.pow(_,2)` to the value of the cell `A2` or you could let imported functions work directly on the spreadsheet cells and do something like `=Math.pow(A2,2)`<p>This doesn&#x27;t solve the problem of JavaScript being a terrible programming language and after re-reading the above, is asking users to write a closure around multiple-argument functions crazy, is polluting the spreadsheet namespace with external functions too crazy? What if a third party JavaScript lib has a function called A2, or even SUM which conflicted with the builtins Perhaps a stack-based programming language would be more appropriate, especially when you start trying to do operations on ranges (lists).<p>The first thing that comes to mind is Forth but a more modern alternative that plays well with JavaScript is Daimio http:&#x2F;&#x2F;daimio.org&#x2F;.

26 comments

Pxtlover 11 years ago
Honestly, I think the bones of Excel&#x27;s language are fine. It&#x27;s very natural for anybody who knows highschool math. There are obviously a few features I&#x27;d want redesigned - like the inline-if stuff, and a good lambda syntax would be nice. Better Boolean support would be a big thing.<p>Basically I&#x27;d want something like C# or Python.<p>The big thing is that Excel is for non-coders, so you can&#x27;t use programmer-centric syntax. That means that C&#x27;s ternary operators, double-equal-signs equality test, and the ampersand&#x2F;pipe boolean logic is <i>right out</i>.<p>On the other hand, I like curly braces, and the &quot;BEGIN&quot; &quot;END&quot; keywords of wordy languages seem more confusing than simple braces. Or indent-based since the environment can be trusted to enforce them and make them neat. But curly-braces are good for one-liners, which are important to Excel.<p>.NET support would also be a huge plus.<p>Oh, I just designed Boo.<p>Yeah, Boo (or something very close to it) would be my language for Excel. Except for the silly double-equality thing, screw that, since most variable declarations will be a cell anyways so the assignment operator isn&#x27;t too useful for Excel and you can make assignment verbose with a &quot;let&quot; keyword.<p>My biggest problem with Excel isn&#x27;t the formula language but the muddy-thinking nature of spreadsheets themselves. I&#x27;d rather see a middle-ground between a database and a spreadsheet, something like Lotus Improv.<p>Make the user specifically define the names of their variables they&#x27;re using and whether they&#x27;re a scalar, an array, or a 2d array. Make the formulas <i>visible</i> above these things.
评论 #6842992 未加载
xmonkeeover 11 years ago
I think the current Excel formula language is perfect for what it does. 99.999% excel users don&#x27;t really need anything more than sum or sumif.<p>I work extensively in Excel and we have an in-house programming language that can be run with an eval() type excel function. The code is written directly in the cells and you just have to eval() it to run it. It&#x27;s brilliant, let&#x27;s you do all you want without breaking excel in any way. The syntax is a pretty standard C variant with a lot of support for matrices (finance work).
评论 #6834069 未加载
sheetjsover 11 years ago
A 2013 spreadsheet formula language would look pretty similar to what we see now. The format is simple and relatively easy for people to understand.<p>If I were able to change it, I may consider adding a left hand side to the formulas (A3=A1+A2 rather than just =A1+A2), which seems verbose but completely obviates the need for the special array formula type (e.g. `{=A1:A2 * B1:B2}`, which would be naturally expressed as C1:C2=A1:A2 * B1:B2). There are other constructions like range unions and intersections that I probably would change, but no obvious replacement comes to mind.<p>If you want to explore JS in excel formulae further, there are people trying to implement the formula space in JS: <a href="https://github.com/sutoiku/formula.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sutoiku&#x2F;formula.js</a><p>BTW: if your goal is to attack the spreadsheet space by innovating on formulas, you are probably barking up the wrong tree.
mklover 11 years ago
I would do away with the opaque, error-prone cell references altogether and work exclusively with named columns, cells, etc. Yes, named cells and ranges are supported in most spreadsheet programs, but people don&#x27;t seem to use them much since it&#x27;s easy to get started with the cell references. Operating on named column ranges seems safer than &quot;fill-down&quot; etc. which it&#x27;s easy to go wrong with.<p>I think this change would be more beneficial than changes to the formula language, though I think the one-liner style the formula languages encourage is quite problematic too.
评论 #6834944 未加载
评论 #6834536 未加载
patrickmayover 11 years ago
Scheme is easy to embed and maps well to common spreadsheet operations because it accepts lists of arguments to functions like sum and stdev. It also has a full numeric stack. Modify it to accept ranges of cells and it would be an excellent language for Excel.
评论 #6833957 未加载
noinsightover 11 years ago
Python.<p>I actually want to use Python in a spreadsheet program but it&#x27;s more difficult than it should be, DataNitro is not free and Gnumeric&#x27;s Python support is not enabled in Windows builds. Pyspread doesn&#x27;t work quite like a regular spreadsheet program.
评论 #6833958 未加载
评论 #6833974 未加载
评论 #6869262 未加载
w_t_payneover 11 years ago
Not sure the language design can really be considered (totally) independently of the UI design. Spreadsheets are not text editors, and what is good for the goose may poison the gander and render it dead.
zhte415over 11 years ago
I wouldn&#x27;t change a lot, perhaps nothing.<p>VBA is a fuzzy line; a lot of functionality is added through plugins from Bloomberg &#x2F; Datastream &#x2F; Reauters (I live in the financial world) through C++ libraries for all kinds of functions.<p>Integrity of data and calculation... Best not to use Excel for critical, non audited systems. Changing the language will not change the potential to use a dodgy clockwork clock (spreadsheet) to do the job of a digital watch.<p>I do deeply dislike the visualisation of data. Formatting a chart is simple but tedious. If venturing from bar &#x2F; line &#x2F; area &#x2F; scatter charts i.e. more than an extremely linear presentation of data, then Excel does not excel.<p>But a vlookup, or a pivot, at the stroke of a few characters, is amazing. Given the &gt;65535 line restriction of earlier versions of excel, it would be very nice these functions could function on larger data groups, the hundreds of thousands of lines Excel now represents in rows.
nailerover 11 years ago
<p><pre><code> pow(A2,2) </code></pre> seems reasonable.<p>Please:<p><pre><code> pow = Math.pow.bind(Math) </code></pre> at least, as typing Math in a spreadsheet is going to get boring.<p>Not sure if JS is the best choice for a spreadsheet, though, JS has surprising (compared to Python or Ruby) IEEE 754 arithmetic. I don&#x27;t know that much about the topic so perhaps someone else could elucidate.
arh68over 11 years ago
Most of the trouble I&#x27;ve had with spreadsheets boils down to not knowing the (albeit small) language. Writing =B3&#x2F;B$1*$A$1 is generally useful, don&#x27;t get rid of that. Emphasize the formatting as a separate concept from the data (formatting needs its own language). Add type hinting&#x2F;checking to cells &amp; functions, but don&#x27;t &#x27;enforce&#x27;. Make plots first-class, embeddable in single cells (and mergable into larger areas). Make functions first-class, so a cell can contain a formula. Allow simple access to not just other sheets&#x27; cells&#x2F;fns, but other files&#x27; cells. If you&#x27;re crazy, allow access to remote files&#x27; cells&#x2F;fn over HTTP. If you can define a sane JS FFI, you could import js libraries remotely. It blurs into web development, but what doesn&#x27;t?
telover 11 years ago
I think it&#x27;d be neat to get some flowback from the FRP&#x2F;Cells community which seems to be reinventing spreadsheet computation from first principles.
merkittover 11 years ago
<p><pre><code> $(1,1) = $(1,2) + $(1,3); &#x2F;&#x2F; cell value ref: $(row, col) $(&#x27;sheet1&#x27;).onready(function() { }); &#x2F;&#x2F; you get the picture </code></pre> the spreadsheet programming and the data grid&#x2F;presentation could be made separate.<p>replace fill handle based formula extension with parameterized formulae:<p><pre><code> for (int i = 0; i &lt; $(&#x27;name_range&#x27;).length(); i++) $(1,i) = $(2,i) + $(3,i); &#x2F;&#x2F; and so on and so forth </code></pre> write as many functions as necessary.
rchover 11 years ago
As a simple experiment or learning experience, why not start with the same languages as Light Table, then add R and Julia. (or start with Light Table and add a spreadsheet view)<p>But if you wanted to raise the bar on spreadsheets in general, you might back away from the scripting end and think about sets, series, logic, and ontologies. Look at CLIPS and Prolog, and try out Protégé.<p>Also, &quot;Populous is a generic tool for building ontologies from simple spreadsheet like templates.&quot; (<a href="http://www.e-lico.eu/populous.html" rel="nofollow">http:&#x2F;&#x2F;www.e-lico.eu&#x2F;populous.html</a>)<p>I would personally enjoy being able to define named streams with Redis-like pub&#x2F;sub semantics driven by arbitrary generators, composeable as sets (when finite, or as constrained by rules), and having a parametric type system available when it makes sense. Then scripting.
dragonwriterover 11 years ago
&gt; Google Docs clones the Excel formula language for use in cells but allows you to write extensions&#x2F;macros (where you would use VBA) in Google Apps Script but what is it really? It looks a lot like JavaScript.<p>It doesn&#x27;t just &quot;look a lot like JavaScript&quot;, it -- to quote Google -- &quot;is a JavaScript cloud scripting language that provides easy ways to automate tasks across Google products and third party services and build web applications.&quot; [1]<p>[1] <a href="https://developers.google.com/apps-script/" rel="nofollow">https:&#x2F;&#x2F;developers.google.com&#x2F;apps-script&#x2F;</a><p>&gt; Why not have a single language for the cells and for extensions?<p>Because programming in the <i>extremely</i> small is different than programming in the large.<p>With a suitable functional programming language, you could probably find something that would work tolerably well for both.
talmandover 11 years ago
I would base it on Javascript just to give certain people something else to whine about.
kamakazizuruover 11 years ago
for what excel is intended to do - the current formula language is actually perfect - I wouldnt trade it for anything else (being someone who does a lot of work in excel - but also spends plenty of time hacking python &amp; js) - if you really want to do more powerful stuff - you have macros and the like. Theres also Datanitro and other plugins you can add in. Also - if you really just care about using the data in the sheet - just read it into a simple python script and manipulate away. Dont fix something that isn&#x27;t broken, I say.
评论 #6834115 未加载
评论 #6834008 未加载
linker3000over 11 years ago
As a few others have said, the current language is suitable for the original intended purpose, although a better way of managing if..then..else situations would be appreciated.<p>If anything, I&#x27;d take away some of the non-core mathematical procedures and functions (ie: cell prettifiers) so that people stop using spreadsheets for such diverse purposes as project management (GANTT in spereadsheet columns - ugh!), tabular text reports that should be done in a word processor and anything else where another app would be more suitable.
mrtimukover 11 years ago
I think Excel language is great: It&#x27;s fantastic that so many people in the world are unwittingly gaining experience in using a pure functional language, and its conciseness really lends itself to writing in relatively small cells. There are no side effects, it&#x27;s hard to shoot yourself in the foot.<p>I do find myself writing fold-like functions by creating a column to hold the accumulator; whereas it might be nice to have that syntax built-in.<p>It&#x27;s an intuitive functional language. Well played.
vertex-fourover 11 years ago
I think that I wouldn&#x27;t build spreadsheets today. I&#x27;d build a tool which allows me to build simple forms which store, edit, and view data, and a separate tool which lets me work on and transform that dataset through a visual programming pipeline.<p>This would allow me to decouple the storage format, the views, and the transformations from each other, and make for a significantly more maintainable system for most things that spreadsheets are commonly used for.
edw519over 11 years ago
&quot;Make everything as simple as possible, but not simpler.&quot; - Albert Einstein<p><a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Reverse_Polish_notation</a><p><a href="http://old.easyco.com/easydocs/d3/pickref/page1517.htm" rel="nofollow">http:&#x2F;&#x2F;old.easyco.com&#x2F;easydocs&#x2F;d3&#x2F;pickref&#x2F;page1517.htm</a><p>(50 year old methods that worked well on the technology of the day would <i>fly</i> today.)
drzaiusapelordover 11 years ago
Today with the politics at MS? I imagine it would be similar to powershell&#x27;s syntax or just be powershell with new excel specific functions. I imagine there would be more wizards to help non-techies generate code. Maybe even natural language stuff. &quot;I want to add up everything in column B.&quot; or &quot;I want to append <a href="http://" rel="nofollow">http:&#x2F;&#x2F;</a> to everything in column C.&quot;
ben0x539over 11 years ago
Something like Haskell seems like a good fit for the brevity of working with sequences using higher order functions, but maybe the type system is too verbose... I&#x27;m sure there&#x27;s some better candidates, but it&#x27;d be a nice start and maybe an excuse to look at the work of that one person who turned a Haskell dialect that compiles to javascript into a fulltime job.
vijucatover 11 years ago
Firstly : cells + formulas are isomorphic to rule-based (expert) systems in that both are directed graphs (which may contain cycles, which is an error!).<p>Thus, just a thought experiment, it may be useful to turn the situation on it&#x27;s head and say &#x2F; ask : &quot;So, this GUI, with formulas and cell references, is actually a way to visualize a rule-based system...&quot;
eddyparkinsonover 11 years ago
Build web applications, with formulas. Formulas that build real software, the kind a programmer is able to create. This way: www.cellmaster.com.au&#x2F;Build.html?hn (2 min video)
applecoreover 11 years ago
JavaScript or a language that improves upon it like CoffeeScript, TypeScript, or Dart.
6d0debc071over 11 years ago
&gt; If you were to invent a language to be used in spreadsheets today, what would it look like?<p>Lisp. I&#x27;d have the cells contain data, and only data. You can type data into the cells like normal. However, when you want to input a formula I&#x27;d split the screen horizontally and have it start off with<p>(cell-name ( ____ ))<p>Have the user start typing in the middle of the second parenthesis where the underscore is by default - have it default selected to make it clear, slightly grey out the surrounding syntax so they don&#x27;t immediately have to worry about it but bring it back to the normal colour if they click outside of that.<p>Clicking a cell back on the cells windows would insert a reference to it.<p>(cell-name (+ a1))<p>Dragging across cells would define a group with some syntactic sugar.<p>(cell-name (+ group a1 b2))<p>Inserting a graph would show you the code of the graph right there in the code window.<p>What might I do differently to Lisp? I&#x27;d replace the + sign with &#x27;sum-of&#x27; and * with &#x27;product-of&#x27; to help people get used to the prefix style. So the above would become.<p>(cell-name (sum-of group a1 b2))<p>I&#x27;d have sum-of inserted when you clicked the + key on your keyboard to make it clearer how it worked.<p>I think this would be quite intuitive and add a lot of easily seen power. We&#x27;re used to using parenthesis to group math things, we&#x27;re used to using variables, we&#x27;re used to using functions - we just don&#x27;t tend to think of those things as such.<p>All your logic would be visible in the code window, finally escaping the horrible black-box style of clicking off the cell and everything vanishing.<p>Potential problems?<p>&#x27;Ah, but Excel&#x27;s for non-coders,&#x27; you might say. I don&#x27;t think it is, not really. If you just want to add a range together you have to learn a formula that&#x27;s quite similar to Lisp to begin with:<p>=SUM(a1:b2)<p>And in many ways it&#x27;s less intuitive than Lisp is. Why is =SUM required to be like that, why do you need to group the references after SUM like that? What is the : meant to signify? And as you go develop more complex things like SUM-IF you&#x27;re rapidly looking at something that&#x27;s just a bad programming language.<p>You can sort of muddle your way into it by messing around - but I don&#x27;t see that it&#x27;s not a thing that people have to learn or that it&#x27;s any easier than Lisp&#x27;s presentation would be. Have you tried interviewing for admin jobs lately? I have, I try interviewing for jobs I&#x27;m not interested in from time to time, and even working some of them, just to keep in contact with the state of offices. Pivot tables and &#x27;macros&#x27; are considered advanced excel knowledge - I&#x27;ve been in offices where most of the people working there don&#x27;t know how to make a drop-down list for a cell, or how to use something as simple as SUM-IF.<p>Excel&#x27;s language isn&#x27;t simple for non-coders already. Where it wins above programming languages that we all are perhaps more familiar with, IMO, is that it gives people an immediate visual hook into a data structure that they can use as a starting point.<p>Like the REPL - but with a slightly different emphasis.