3 ms·
That's what option and result types are for, so you don't need to mess with in-band signalling.
by frou_dh 3y ago
That's what option and result types are for, so you don't need to mess with in-band signalling.
- skrebbel 3y agoThat doesn’t solve this problem at all. Nothing about the article is about the downsides of in-band error reporting. It shows JavaScript’s (terrible) -1 indexOf response in a matter-of-fact way and only talks about the meaning of it, which is “not found”. The question is whether or not to return “not found” for certain inputs, not how to return that value.
- flqn 3y agoNot so much "error reporting" as "there is no meaningful return value" for a position in a string -- if it wasn't found, it doesn't have a position. If you use either Optional or Result you don't need to choose a special value like -1 to be your "invalid string position" case which could be used incorrectly. I'd argue it's largely stylistic for this example, especially so outside of functional programming niches.
- skrebbel 3y agoIt nevertheless in no way solves the problem that the article is about.
- deleted 3y ago[deleted]