On Wed, Dec 13, 2017 at 07:36:19AM +0000, Imobach González Sosa wrote:
> On Wed, 2017-12-13 at 00:18 +0100, Ancor Gonzalez Sosa wrote:
> > This is probably the less useful mail ever, since it just goes over a
> > topic that has been explained over and over and still pops us in
> > almost
> > every single meeting.
> 
> Discussing is (usually) fun :)
> 
> [..]
> 
> > Let's do the same in an hypothetical typed Ruby in which there is
> > nothing like nil. Now your find_device_by_name method will raise a
> > NotFound exception instead of returning nil if the device is not
> > there
> > (the approach we use in statically typed languages).
> 
> Instead of throwing (and rescuing exceptions) all over the place (an
> approach I dislike), some typed languages offer a better way to deal
> with these situations: option types[1].
> 
> In a nutshell, an option type represents a value that could (or not) be
> nil. Lately I've been playing around with Elm and Rust and, in both
> cases, the compiler will complain if you do not write code to handle
> the "None" case. You can check some Rust[2] example if you are
> interested.
> 
> And it looks like C++17 already support such a feature (although we are
> not using it IIRC).

I have that idea in mind
(https://trello.com/c/Kjq05SDY/119-use-stdoptional-c17) but C++17
in SLE 15 is experimental.

> As a side note (about throwing exceptions), I prefer having
> "find_by_device_name" and "find_by_device_name!" methods. The former
> would return 'nil' if a device is not found and the latter would raise
> an exception.

I always though the function with ! modifies the argument while
the one without returns a modified object.

> On the other hand, I've been taking care of YaST incoming bugs these
> days and I can hardly remember an "internal error" caused by some out-
> of-control nil value.

I can remember bugs of the kind "undefined method xxx for
nilClass".

And I can also remember bugs where a function name was simply
mistyped.

ciao Arvin

-- 
Arvin Schnell, <[email protected]>
Senior Software Engineer, Research & Development
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 
(AG Nürnberg)
Maxfeldstraße 5
90409 Nürnberg
Germany
-- 
To unsubscribe, e-mail: [email protected]
To contact the owner, e-mail: [email protected]

Reply via email to