Did you know you can use arbitrary arithmetic for datapoint values? (Not in advanced entry though, ironically – that’s a can of worms. Same with the email/sms bot.). Oh, and also for setting the rate in the road dial. Relevant UVIs:
And did you know that in many programming languages, a number with a leading 0 is parsed as base 8 (aka octal)? So if you have the number 0123 in your code, that’s actually 83, not 123.
Ok, but the part that wasn’t fine was that no one typing “0123” ever means the number 83. That’s ridiculous. So last night we finally fixed that, so we thought, with an elaborate regular expression. But you know how that goes. It goes like this:
Our regular expression accidentally was turning things like “700” into “7”. Forehead smack.
Bee and I spent an hour or so throwing duct tape on our regex (swinging back and forth on the regex vine – https://xkcd.com/208/ ) and it kept falling over, ie, breaking in new ways. Then I had this mini flash of genius:
I mean clearly the problem has been solved already. So why make the mistakes yourself again? Code you don’t write is code that can’t have bugs.
Besides the other already asked question: Why have this in the first place?
Ha! Thanks everyone! In retrospect we clearly should’ve used a math expression evaluator. But I will accept a wager at @byorgey’s odds that there aren’t further bugs in this thing. I mean, how many more ridiculous things like “leading zero = octal” can there be, right?
Btw, this is client-side in the browser, which makes it less scary (wholly non-scary?) to eval strings from a user. Though I’d actually be fine trusting the sanitizing we’re doing (only digits, dots, the four arithmetic operators, and parens allowed) and be fine eval’ing them server-side too, hypothetically.
Anyway, as for the regex to strip the leading zeros, @insti, see my StackOverflow answer I linked to.
Oh yeah, and for the use cases, @apolyton, see the changelog (UVI) links above.
I shall, as @mary says, go sit in the box and feel shame now for using eval() in production code even though I still secretly kinda love it.
Another potential argument against doing it like we’re doing it today is Android and iOS support.
Folks get irritated when things don’t work the same between Android and the website (rightfully so!) for things like five minutes being able to be entered like 0:5.
I may or may not have put a pomodoro or two into making a PEG parser for parts of your grammar in Scala (which compiles to js). But since @dreev really likes his evil eval hack and there is already libraries for evaluating math expressions I stopped working on it. Anyways here is what the prototype can do:
(And no I was not THAT upset by eval that I immediately jumped up and started working on a math parser out of the blue. I was in fact already working on a different one to parse IMAP envelopes so this was more of a little exercise than anything. Turns out it is even simpler as expected to compile a Scala Parser to JS. And I think the code is rather pretty. Also statically type checked of course.)