6 ms·
UI is hell: four-function calculators
- andrewfromx 2y ago"those cheap plastic rectangles hide decades of edge cases, quirks, and questionable design choices. Want to change a number's sign? That's a special case. Chain operations? Special case. Divide by pressing equals repeatedly? That's a feature called K-constant, except multiplication plays by different rules because... reasons. By the time you've handled every possible button combination, you'll wish you'd stuck to programming smart fridges"
- labster 2y agoBut the calculators last much longer than smart fridges because they don’t rely on central server existing to continue operating.
- bathtub365 2y agoThey fixed that by making solar calculators that rely on the continued existence of our temporary sun.
- TeMPOraL 2y agoI thought those solar panels are fake decorative elements only; the calculator still needs a battery to work and stops working when it runs out?
- 01HNNWZ0MV43FF 2y agoThere's counterfeit ones yes, but somewhere I have a real solar calculator. I even had a duplicate of it where I unplugged the broken solar panel and put 2x AA batteries on the back to power it. So the solar panel definitely worked
- persnickety 2y agoThere were calculators in the '90s where the display would go faint when you covered the tiny solar panel. Perhaps the battery was already drained. Quite common I would say.
- Ekaros 2y agoSome didn't. In today's world it is actually amazing how little power those things used. Both for that type of LCD screen and doing some calculations. Just compare it to almost anything else we use daily.
- bawolff 2y agoI always found percent key behaviour to be such a bizarre choice.
- theamk 2y agoWhen I was a student, I thought the same. Later when I designed some expression evaluators I've started to appreciate the language design (and hacks) required to make "100 - 5%" work "as expected" (that is, return 95). It's a pretty unusual grammar, and it is neat that it was implemented on something with only few dozens bytes of RAM.
- quesomaster9000 2y agoTL;DR PEDMAS is bullshit If you look at the internal state of the typical physical calculate it's a beautifully simple machine that tries to catch the balance between RPN and logic... except it has stupid nonsensical human rules interjected. So, every time this article where points out "actually it's more complicated than it seems" is where historically somebody has made deliberate design decisions to do it 'the dumb way' even though it adds complexity, to force something unnaturally. And what you end up with is something that's half intuitive, it's in between the two systems, but it's more complicated than it needs to be. Please, I would much prefer device for RPN calculation, that follows consistent logic, rather than silly imposed rules. 4+7*3 etc. or 4 7 + 3 * = Where the latter is much closer to what we do in our heads and conceptually think about it.
- ziml77 2y agoI don't see how PEMDAS is relevant for a 4 function calculator. The implicit equals when you press an operator means that they always work sequentially rather than jumping around.
- airstrike 2y agoI think they're saying it's bullshit because if we used (the superior) RPN across the board, we wouldn't need PEMDAS at all
- Jaxan 2y agoYou also don’t need pedmas if you just use parentheses to disambiguate your expressions. That’s what mathematicians would do.
- ziddoap 2y ago>RPN "Reverse Polish notation", I think, for people like me who aren't familiar with the acronym.
- nejsjsjsbsb 2y agoYou thank!
- gnatolf 2y agoThis article makes it sound more complicated than it is, collecting all those edge cases. Many of them can be simply ignored, as in being no-op. Which is also what most cheap calculators do...
- mazambazz 2y agoI, too, have been caught in the trap of trying to accommodate all possible user flows. Sometimes you just have to put your foot down and just say "No, that is not how you use this tool".
- jansan 2y agoTraditionally this would be solved by inserting a comment into the code that insults the user (for example the classic "The user is a wanker" comment [1]). [1] https://www.theregister.com/2006/10/13/code_outrage/ https://www.theregister.com/2006/10/13/code_outrage/
- BlueTemplar 2y agoThe site linked in comments is gold. > Shit. I was just about to launch into an explanation of our code review procedures. Every week we sit around a table and carefully and dispassionately analyse and constructively criticise each others code. And it works. We sit there and listen and take it all in. It works really well and team morale is excellent. One day we're even planning to do one when we're sober.
- mrbombastic 2y agoI think there is a lesson here. Don’t let edge cases define your complexity whenever possible. Check if it is in fits your valid expressions and if it doesn’t do nothing, otherwise you get a mess of if x then y
- userbinator 2y agoThose "edge cases" actually aren't; they're simply "emergent behaviour" of how the state machine in the ASIC works.
- userbinator 2y agoReading this article and the thought process behind it reminds me of this almost-10-year-old comment I made about how they actually work: https://news.ycombinator.com/item?id=9456444 https://news.ycombinator.com/item?id=9456444 Selecting an operator loads this value into the accumulator and makes room for the second operand to be typed in. Here is where I think the first mistake was made; if you observe the effect of repeatedly pressing '=', that obviously does not clear any registers, but merely repeats the last operation. But there’s more to the story: it’s actually a side effect of a little-known “K-constant” feature that retains one of the previously-entered operands and the operator, and lets you vary the other operand. I haven't used any 4-function calculator that behaves like this; instead, I get (without clearing): 2 + 1 0 = 12 5 = 22 0 = 32
- saurik 2y agoApple's recent iOS Calculator update broke this entirely and now = multiple times does nothing :/.
- oogetyboogety 2y agothose fuckers. If windows wants to add this as a success where Mac has failed, it still works in their calculator app.
- actionfromafar 2y agoWindows also innovated from TTC to TTCC! (Time to Candy Crush, instead of Time to Crate.)
- saagarjha 2y agoThis is fixed in the latest beta, which is probably going to ship next week or thereabouts.
- wruza 2y agoiOS calc sometimes registers a press but not a release(?) and a key gets stuck in "pressed" state and doesn't count as an input. Many years issue which renders it completely unusable, unless you're careful with your tapping. A new level of skeuomorphism, I guess, non-physical buttons that get stuck.
- openrisk 2y ago> Let’s start with the basics: the simplest calculator has ten digit keys, a decimal dot, four arithmetic operators (+, -, ×, ÷), a result button (“=”), and a “C” key to reset state. Mathematically there is already quite a lot happening here and in addition (pun) we use base-10 representation of numbers, which is not the simplest. Might be interesting to explore if decomposing the problem into even simpler "sub-calculators" (e.g., starting with binary addition) and then putting everything back together as a sort of progressive enhancement would reveal the most logical or economical UI.
- contravariant 2y agoI still wish to find the idiot who thought the reasonable thing to do when someone types 2 followed by SQRT is to return 2sqrt(
- kqr 2y agoI realised reading this that, even though I used to be quite adept with these common four-function calculators, I have since forgotten most of their operation. The past ten years or so I have exclusively been using RPN calculators – I find them so much easier to work with, and going by this article, possibly even easier to implement sensibly? (My main drivers are Emacs Calc on the computer and RealCalc on Android devices. For kitchen work I use a slide rule, which is something I think more people should do! There is nothing better for translating proportions.)
- persnickety 2y agoRPN is definitely easier to implement. I helped someone do that as a student project and while it was minimally complex, there were no edge cases with the operators. You pay for that by having a stack rather than a small fixed number of variables.
- tgv 2y agoClassical 4-func calcs are easier, I think. They don't even need a stack, just a place to store the previous value and the current input.
- _moof 2y agoMy HP RPN calculator only has four positions available in its stack, which I imagine makes the implementation a bit simpler than a stack of arbitrary size.
- persnickety 2y agoThe typical 4-function calculator doesn't even allow multiple subtrees of computation, so I think it works out to having something like 2 entries on the stack.
- enriquto 2y ago> You pay for that by having a stack rather than a small fixed number of variables. you can easily add variables to your rpn calculator. For example ">x" pops the top of the stack into the variable x, and "<x" pushes the value of x to the stack. You can also interpret parentheses as whitespace to enable users to group parts of the computation (but this may become confusing when they write nonsensical parentheses).
- troupo 2y agoOh, it doesn't even get to the juicy bit of percentages. Can't remember how physical calculators deal with them, but software calculators deal with them differently. To the point that iOS calc and MacOS calc are different. And variations of Windows calc (regular/scientific/engineering) are different
- kazinator 2y agoGoogle's calculator on Android is an absolute shitshow. Sorry for omitting details, but this issue is easy for anyone to repro without any specific steps.
- kccqzy 2y agoDoesn't the Android calculator use constructive reals? https://cacm.acm.org/practice/small-data-computing/ https://cacm.acm.org/practice/small-data-computing/
- jamesfisher 2y agoAs usual, this is completely unreadable on mobile due to Substack's hatred for zoom
- gushogg-blake 2y agoI think calculators should have "into" and "from" so you can do division and subtraction on the previous result without retyping it. I made a demo: https://fluent-calc.vercel.app/ https://fluent-calc.vercel.app/ Also supports saving a result into a variable for later reference, and x "as proportion of" y, which is just an alias for division.
- beeflet 2y agoMaybe you could do the same thing by having a negation and reciprocal button?
- gushogg-blake 2y agoYeah, having dedicated operators for going the other way just fit my mental model better for the types of tasks I had in mind for it.
- layer8 2y agoYes, I use those all the time for exactly that purpose. In many cases you don't even need to worry in which order to enter the operands when calculating a difference or ratio, just press negate or reciprocal if the result doesn't look right.
- bowsamic 2y agoI'm not joking when I say I'm 30 and I still don't understand how to use a calculator without a proper display where you see the entire expression to be evaluated. At school in the UK we all had calculators where entire expressions could be typed in including proper fractions and parentheses. I find the more basic kind of digital calculators, including built-in calculator apps, to have totally impenetrable user interfaces
- rbanffy 2y agoI remember fondly having figured out how to implement precedence with two stacks, one for operations and other for operands, the same way my Texas Instruments calculator did. It is possible to implement a desktop accessory calculator in a lunch break, but only because you get a whole lot of abstraction done by the GUI environment. Modelling the UI as a state machine in this case is essential so you don’t get crazy with all the corner cases.
- gf000 2y agoJust putting it out here - before the recentish redesign of ios's default calculator, it had a widely non-intuitive behavior. Due to how it looked I assumed it works as a standard four-function calculator, but it was actually storing the whole expression in memory and executing it as per the standard precedence rules. I do usually prefer the latter behavior, but without it being displayed as in more advanced calculators (it has been changed to show it) it's just not what I would expect at all, resulting in wrong calculations. But maybe it was just a "me-problem".
- the-grump 2y agoOne of first things I do when I set up a new iThing is to delete the calculator app and install a third-party calculator.
- ghaff 2y agoI've been RPN for so long that I pretty much need an RPN calculator app even for relatively simple stuff.
- kstrauser 2y agoI didn’t start using RPN until many years after graduating college, but took to it like a fish to water. I never again have to guess what the calculator might be doing behind the scenes. It’s doing exactly what I told it, no more or less, in precisely the order I told it.
- ghaff 2y agoWhen I started college, HPs were still really expensive so I got a TI which still wasn’t cheap. But calculator prices were plummeting like a stone and got a (relative) deal on a HP-55 a year or two later.
- airstrike 2y agothis is me too. I literally can't use a regular calculator anymore and I'm not even doing fancy math. my brain was just permanently rewired by the HP-12c
- tmjdev 2y agoI think this just illustrates why hidden state is so difficult for the user. It's hard to replicate old calculators because it was poor UI that was making do with what was yet available.
- khaki54 2y agoNew technical interview question just dropped
- phreack 2y agoTo this day I can not remember which is which in calcs with clearing buttons. I know probably one of them clears the operator and the other clears the whole operation, but since I'll never figure out the correct one I just start pressing everything when I want to start over and hope.
- genewitch 2y agoCE is clear entry to my brain, regardless of the actual etymology. So 7 + 1 * 5 ÷ 0 CE 4 = 10 And 7 + 1 * 5 ÷ 0 C 4 = 4
- iamnotsure 2y agoDoes your calculator use bigints for subtraction? why? why not?
- ForHackernews 2y agoI think there's something to be said for UX consistency even if it's "wrong" in some ways. To a first order, every basic calculator works exactly the same, and it's easy to use them all once you've learned how to use one. In contrast, every microwave in the world has reinvented its own new system for entering a time, and added a bunch of extra buttons for useless fake features.
- 2-3-7-43-1807 2y ago> Yes, there are buttons. No, it doesn’t support double-tap or long press. how do you diff between div/mul if not by double tap?
- billmcneale 2y agoThe keyboard on this calculator has the number of keys reduced to the minimum by the use of only three function keys, including a combined "x÷" key. Here, pressing "x÷" gives the multiplication function if "+=" is subsequently pressed to give the answer, and gives the division function if "-=" is subsequently pressed to give the answer, so: 4 x÷ 2 += gives the answer 8. 4 x÷ 2 -= gives the answer 2.
- 2-3-7-43-1807 2y agonice concept but a very bad choice to illustrate good UI. there is enough space to add a few more buttons with dedicated functions.
- billmcneale 2y agoIn 2025, sure. Back when that calculator came out, this kind of saving was probably worth it.
- 2-3-7-43-1807 2y agoeh why? believe it or not but they had even keyboards back then with many dozens of keys.
- kazinator 2y agoSimple calculators are actually a bit like functional pipes. There's no precedence. Everything is left or right. Every button is a prefix command: OP ARG or else just OP. For instance 3 + 4 x 3 - 1 x 9 - can be evaluated in a particular Lisp dialect as (lflow 3 (+ 4) (* 3) (- 1) (* 9) -) Where lflow is a left inserting pipe operator. It begins with the value 3, inserts it as the left argument into (+ 4) to actively produce (+ 3 4) and so on. In the calculator, the result of the previous operation is similarly another argument to OP, which is inserted on the left. It can be understood as being held in an accumulator register. If OP requires ARG, the evaluation doesn't occur until another OP is entered, or else the = button, which roughly means end of ARG. But OPs that take no argument other than the accumulator dispatch immediately. When OP ARG is followed by multiple =, it is repeated that many times. When an ARG is entered not preceded by an OP, it replaces the accumulator. In some calculators, when a new ARG value is entered this way, followed by =, the value is somehow substituted to the previous operation and it is reevaluated, instead of just becoming the new accumulator.
- carb 2y agoIf anyone else was curious about the final image and the `x÷` button: http://www.vintagecalculators.com/html/sharp_el-8.html http://www.vintagecalculators.com/html/sharp_el-8.html ---- > The keyboard on this calculator has the number of keys reduced to the minimum by the use of only three function keys, including a combined "x÷" key. > Here, pressing "x÷" gives the multiplication function if "+=" is subsequently pressed to give the answer, and gives the division function if "-=" is subsequently pressed to give the answer, so: > 4 x÷ 2 += gives the answer 8. > 4 x÷ 2 -= gives the answer 2.
- thih9 2y agoThank you! This looks surprisingly intuitive, perhaps even comfortable, especially when muscle memory kicks in. Then again… I guess 4 += 1 += gives the answer 5. What would be the result of 4 += 1 -= ? Edit: the answer is “3”, elaborated on the linked page: http://www.vintagecalculators.com/html/calculator_keyboard_layouts.html#AddingMachine http://www.vintagecalculators.com/html/calculator_keyboard_l...
- humptybumpty 2y agoBut what about: 4 -= 1 += 4 -= 1 -= I’m guessing 3 and 3?
- thih9 2y agoMy guess is different; these calculators did support negative numbers; I’d say: 4 –= 1 += gives: -3 4 –= 1 –= gives: -5 Manual for a similar model: https://www.oldcalculatormuseum.com/m-sharpqt8d.pdf https://www.oldcalculatormuseum.com/m-sharpqt8d.pdf
- manchmalscott 2y agoThis is why every calculator ever should have a RPN mode. Postfix notation removes all of that parsing ambiguity. I ended up making my own RPN calculator in C++/Dear ImGui because I wasn’t happy with any of the options for desktop Linux and, implementation wise, RPN is dead simple. Grab values off the stack, apply operator, push back onto stack.
- brundolf 2y agoThe intrinsic hardness of UI programming is representing state and state transitions. OP's problem would be much easier in a full language with things like structs and dynamic lists, but it still wouldn't be trivial People sometimes miss the point and think of UI dev as painting pictures with code, which is part of it, but the hard part is state
- tempodox 2y agoThe generic, basic LCD calculator is missing solar cells. Should be sine qua non these days for a simple device like this.