3 ms·
You must have a real panic when you see a sign saying “No parking except weekends.” Weekends happen all the time!
by ajanuary 3y ago
You must have a real panic when you see a sign saying “No parking except weekends.” Weekends happen all the time!
- theshrike79 3y agoSo if you write code that handles dates you'd throw NotWeekendException to notify the caller that it's not weekend? Exceptions should be for exceptions, not control flow.
- kelseyfrog 3y agoI'm curious how this is possible? Exception throwing and handling is fundamentally a flow control construct. ie: throwing an exception must control flow. A counter-example snippet where throwing an exception does not control flow would be appreciated.
- naasking 3y agoHe means exceptions are not for common control flow that shows up everywhere, like a return value. You want an exceptional control flow change when your hard drive runs out of storage, but you don't want exceptional control flow change when your hashtable doesn't have the key you're looking for. The categories and frequency of these conditions are very different.
- kelseyfrog 3y agoHmmm, sounds like it just transforms into a Sorites paradox, no?
- naasking 3y agoI don't think cases encountered in real work are really that unclear. It can sometimes seem unclear if you're used to language semantics that are inherently riddled with possible error states (like languages that allow null).
- theshrike79 3y agoAn exception would be if someone tried to get the parking status for "Blarghsday" from the function or some other impossible state (We all know time is weird[0]) If the expected operation is to return parking allowed status for a specified date or a weekday, I'd expect the function to return true or false unless the input is malformed (Actually I'd prefer it to return some kind of object that can give more context to the true/false, but I digress). During normal operation it should never throw an exception. Because if I get an exception, I'll most likely either throw it up the stack or log an error, which will ping someone in PagerDuty if it happens too often. [0] https://gist.github.com/timvisee/fcda9bbdff88d45cc9061606b4b923ca https://gist.github.com/timvisee/fcda9bbdff88d45cc9061606b4b...
- kelseyfrog 3y agoI'm afraid that this has left me more confused. What's normal operation? It sounds rather subjective. It sounds like there are those who "expect the unexpected" and those who don't, and this plays out in weird programming language usage discussions. Among all the expectations that one could have about a program, people have the impossible choice of being either complete and inconsistent or incomplete and consistent in their operational definition of "normal". Is it not?
- ajanuary 3y agoIt says the word exception right there on the sign. People keep parroting “exceptions should be for exceptions” like it means anything. Just because when it was first used it was given a particular name doesn’t really tell you anything about how it should be used.
- naasking 3y agoYou're right, weekends happen all the time, which means they're not exceptional, so you shouldn't throw an exception if you encounter a weekend.