What on earth did I just read
Maybe an essay
Maybe Functions
21–30 of 103 posts
Re: Maybe Functions
#22* Monads naturally arise out of many problems in programming.
* But I don't want my language to support monads.
* So here's something you can do to stay in denial about how much you need monads.
At least this example only involves writing hard-to-analyse code and doesn't lead to you trying to invent green threads.
Re: Maybe Functions
#23Two remarks:
• the render function is omitted, this pattern as a huge impact on application behaviors, if not for display-as-you-load issues, on DOM hidden state (things like focus, animations, etc…) for web apps.
• App's do have a global state, with self-consistency, scattering it in a mixed match of loading cache and self contained components just make it hard to work with. I think it's better to have a centralized upper level parent component that manage the transitional initialization states and consistency, not necessarily for the whole app, but at least for the whole displayed UI content.
Re: Maybe Functions
#24(mostly waiting for this in JS and Go)
[1]: https://doc.rust-lang.org/reference/expressions/operator-exp...
Re: Maybe Functions
#25Another option is Exceptions. The function either does what it's supposed to, or freaks out. You can remove the null checks and the software will raise a null pointer exception. In the first example, could raise a NotLoggedInException. It's still a maybe function, but you have a mechanism for expressing the why-notness of the function run, as opposed to returning a generic null. As an aside, I prefer the "Unless" mod…
I am for exceptions but it should not be used for basic control flow. Many techs will treat all exceptions as errors.
Re: Maybe Functions
#26Re: Maybe Functions
#27What's the advantage of the Monad approach? Doesn't the render function still have to check whether those Maybes contain values or not?
getUser :: Maybe User
getUser = ...
getFriends :: Maybe [User]
getFriends = do
user renderBestFriends besties
Nothing -> renderNoFriends
The Maybe monad itself contains the equivalent of runSafely from the article, and the syntax propagates the failure case transparently from getUser down to the choice of render function used. All without either the hassle of handling null cases, or the danger that you might forget to handle them and the code crash. Without syntax level support, its not obviously an improvement to meRe: Maybe Functions
#28Another option is Exceptions. The function either does what it's supposed to, or freaks out. You can remove the null checks and the software will raise a null pointer exception. In the first example, could raise a NotLoggedInException. It's still a maybe function, but you have a mechanism for expressing the why-notness of the function run, as opposed to returning a generic null. As an aside, I prefer the "Unless" mod…
Re: Maybe Functions
#29I'm all for a perfy shortcut / early return but this maybe just seems like an abstraction on a non-issue.
Re: Maybe Functions
#30It is false that getUser being a “maybe function” forces the other functions like getFriends to be maybe functions. Don’t let them take null in their arguments. Force the caller to deal with the null when it is returned by getUser.