From 27f7b46c2a74a3ff8d89364d343e9c5e0f64446b Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 29 Apr 2022 10:36:20 +0200 Subject: Added note about windows and reworded monads stuff --- different_ways_of_making_errors.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/different_ways_of_making_errors.html b/different_ways_of_making_errors.html index c4b9d3f..05227c8 100644 --- a/different_ways_of_making_errors.html +++ b/different_ways_of_making_errors.html @@ -66,6 +66,8 @@ $ if ls real_file; then real_file True branch with 0 +

Extreme example of throwing raw error codes at end-users is Windows and its API. I'd encourage you to avoid going to +such lengths.

Returning Error Objects

But you don't need to use numbers necessarily. The only requirement is that you remember about the ability to @@ -144,10 +146,10 @@ pointer constants forcing compiler and platform implementations into guaranteein real object and hopefully cause some segmentation faults here and there.

Returning Wrapped Values

-

Instead of bundling error with the value like Go did, you can wrap the value with an object that will optionally -indicate an error. This method is a simplified approach taken from functional programming languages that make heavy use -of monads. They are quite similar with main difference being flow of the error handling. The wrapper can be tailored for -errors or things like Either from Haskell or std::variant from C++ can be used. +

Instead of bundling error with the value in tuple or some other container like Go did, you can wrap the value with an +object that will optionally indicate the error. This method may vary from simplified wrapper to a full-pledged monad. +Depending on where you end up on this spectrum the main difference will be the flow of error handling. You can use +tailored wrappers or something more generic like Either from Haskell or std::variant from C++.

A naive interface of tailored wrapper could look like this:

 template<typename T, typename E=const char*>
-- 
cgit v1.1