💾 Archived View for erock.io › 2022 › 05 › 28 › reply-error-handling captured on 2023-01-29 at 02:36:33. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-07-16)
-=-=-=-=-=-=-
Stardate 2022-05-28
That is, the function is able to return either the intended return value or the error. Zig also has tagged unions, which in code look like an enum wrapping a union. This is what is really meant by the term Algabraic Data Types.
gemini://gemini.hitchhiker-linux.org/gemlog/re_error_handling.gmi
After reading this post I felt the urge to mention that Typescript also has the same concept, although it's called a discriminated union.
https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html#discriminating-unions
Recently I've been doing a lot of software development in golang and this is something that was missed. It looks like there's an outstanding github issue[1] discussing the addition of discriminated unions to golang.
I love discriminated unions in Typescript. Sometimes I wish there was a more standard way to utilize them in the js ecosystem. At least in typescript, there's nothing enforcing error handling via a disciminated union for return types.
I always liked the idea of a maybe type[2] but never end up using it in my code.
Wikipedia article on algebraic data types for those interested in learning more:
gemini://gemi.dev/cgi-bin/wp.cgi/view?Algebraic%20data%20type
Overall I often find myself learning new concepts from the JS ecosystem than any other language. There are some really bright minds working in that ecosystem, producing fantatic ideas. All of this is to say that js gets a lot of hate but there are some good parts to it as well.
--
Want to chat? email me at gemlog@erock.io