4 ms·
Examples of essential complexity you have to worry about if you want your code to be correct, and even if you want to test/detect all issues that can/do come up
by epgui 4y ago
Examples of essential complexity you have to worry about if you want your code to be correct, and even if you want to test/detect all issues that can/do come up:
- https://infiniteundo.com/post/25326999628/falsehoods-programmers-believe-about-time https://infiniteundo.com/post/25326999628/falsehoods-program...
- https://infiniteundo.com/post/25509354022/more-falsehoods-programmers-believe-about-time https://infiniteundo.com/post/25509354022/more-falsehoods-pr...
In my experience engineers will often brush these sorts of things off as “edge cases”, but really all of these complexities are just how dates and time work in the real life (I’d argue that they’re just “normal cases” to test for)… So any anomaly in software will cause real problems of varying importance for users.
- extheat 4y agoI only see this being an issue storing times as strings. Why not store them as integers (like a Unix timestamp) or at least some standardized string format? The only reasonable use case I can think of where you absolutely need all this complexity is if you're rendering a calendar or something similar.
- 9wzYQbTYsAIc 4y agoThere are countless, profitable business use cases for accurate time tracking.
- ohbtvz 4y agoUser: set an alarm in eight hours. It's 10PM right now. At what time should the alarm be set? 6AM? Woops, tomorrow is the switch to DST! What now? User: remind me to brush my teeth on November 21st at 8AM. Okay, will do! Wait, you took a plane on November 2nd and are now on the other side of the world? Should I remind you at 8AM or 5PM? User: please note my doctor's appointment in two weeks at 10AM. Sure thing bub! Wait, but you live in Morocco in 2019? And the government just announced that reverse DST will be in effect for the month of Ramadan, which begins next week?! WTF do I do now? --- tl;dr It's not just an issue of storage. Managing time is hard. There are requirements that we, as humans, will intuitively find the right interpretation for, that computers will absolutely break their teeth on.
- jt2190 4y ago> What now? I mean, there is no way to write code to “handle” this that isn’t just guessing on the part of the programmer. The correct thing to do is to prompt the user for verification or further information. > There are requirements that we, as humans, will intuitively find the right interpretation for… Interpretation is subject to error. (Yes humans have immensely more context to work with than computer programs, but just because we we’re better guessers doesn’t mean we’re not still guessing.)
- TekMol 4y agoThis was the reply I was trying to prevent by saying "minimal code example". I'm not interested in long theoretical articles. But I would look at a few lines of code. Here is an example of some code I recently wrote: logEvent { 'date': new Date().toISOString(), 'event': 'image_updated', 'value': image['id'], } This logs that an image with a given id was updated. Why would I trade in my single date line for 423 files with 53004 lines of code?
- krainboltgreene 4y agoYou wouldn't. It's not a trade anyone is asking.
- 0xCAP 4y agoThis is only you having super basic date needs, not Day.js being overkill in general.
- TekMol 4y agoAny system, no matter how complex, can be composed of smaller units that only have super basic needs.
- 411111111111111 4y ago*if all complexity has been hidden from the developer which only needs to use a decent puplic API. I'd agree that it feels like that quiet often as a web developer, but that's only because most of our APIs are actually quiet easy to use. The illusion usually falls away if you look at the code of that API, however.
- 9wzYQbTYsAIc 4y ago> I'm not interested in long theoretical articles Those articles are more empirical in nature than theoretical. > This logs that an image with a given id was updated As a thought exercise, imagine that your log trail needed to be created in a distributed system, spanning multiple machine time zones, or that you needed to build a report that is read from browsers in multiple time zones that differ from multiple differing written time zones, and you need to account for human readable things like knowing what day of the week it is and what some given locale calls that day. If you are doing the equivalent of printf debugging with your times, maybe you likely don’t need a time library. If you are using time as a central part of a distributed algorithm, web content, or a business workflow, then you may likely need a time library.
- maigret 4y agoYou can still add a library once it’s really needed and an area is proved to cause bugs. Most of the times though, developers will add them upfront “just in case”, making the bundles always heavier and thus harming the user experience with a slower UI.
- epgui 4y agoI’d argue that we already know how time works, so the proof exists up front and there is no “just in case”. You could make an argument that there are more important things to fix, but then you’d be deciding consciously that it was okay to ship software known to be incorrect.
- jwalton 4y agoI posted about this elsewhere in the comments, but my experience with day.js is that if you're concerned with these kinds of corner cases, maybe day.js isn't the library for you.[1][2] [1]: https://github.com/iamkun/dayjs/issues/1816 https://github.com/iamkun/dayjs/issues/1816 [2]: https://github.com/iamkun/dayjs/issues/1817 https://github.com/iamkun/dayjs/issues/1817