The design of the hooks in std.experimental.checkedint

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 4 12:25:02 PDT 2017


On 2017-06-03 23:45, Andrei Alexandrescu wrote:

> One question - current logic decides whether to call e.g. hookOpBinary
> vs. perform the default operation followed by onOverflow. How would that
> work if both hookOpBinary and onOverflow are defined?

I'm not sure I fully understand without a code example but I would say 
that the default hook would implement hookOpBinary to perform the 
default operation and then call onOverflow.

> I'm unclear whether this is a step in the right direction. Why have user
> code work more to provide less information to the framework?

I don't see how it would provide less information to the framework.

> Let user code define what it can, and the framework takes care of the rest.

Well, the default hook is part of the framework.

> A look at how std.experimental.allocator would work if all primitives
> were required would also be useful.

Yes. I haven't looked that carefully on how DbI is used in the 
allocators yet.

> A look at an alternative design would definitely be interesting.

Note that it doesn't need to be an either or case. Some of hooks can be 
required while other are optional. This suggestion is perfect when the 
logic is: if there's a hook, call that, otherwise perform a default 
operation. It's less ideal when there are multiple conditional branches.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list