Since most functions in core also support nil, it isn't as big of an issue
as some make it out to be. So things like this work as expected, even if a
nil exists somewhere

(-> coll
      (map first)
      (filter even?)
      count)

Since all these functions support nil it really isn't a problem. If coll is
nil (or anything else down the chain) count will return 0.

In the end, nil is just a value just like anything else. If your functions
polymorphically dispatch on nil, it's never really a problem.

I know some people may disagree with me, but I probably loose a max of a
few minutes a week to a issue related to a nil. It's really not that big of
an issue.

Timothy

On Tue, Jan 12, 2016 at 2:06 PM, Alan Thompson <clooj...@gmail.com> wrote:

> If the assumptions of a function call aren't satisfied, I find the "silent
> failure" of returning nil to be extremely problematic.
>
> After all, you can't fix a problem if you don't know you have a problem
> (or where it is). As a result, I am definitely in the camp of the
> "fail-fast" philosophy.
>
> Liberal use of Prismatic Schema can help in this area by documenting &
> verifying the expected type of function arguments and its return value.
>
> Re the specific case of trying to lookup a non-existant key in a map, this
> is the precise reason I create the "grab" function in the Tupelo Core
> library <https://github.com/cloojure/tupelo#map-value-lookup>. This
> implements the "fail-fast" practice of notifying the caller as soon as a
> problem is detected, rather than silently ignoring the problem.
>
> Please take a look and tell me if you find it useful!
> Alan
>
>
>
> On Tue, Jan 12, 2016 at 12:25 PM, mattias w <matti...@gmail.com> wrote:
>
>> Clojure and Erlang are very similar, except for the syntax, macros and
>> that you can use Java libraries.
>>
>> There is one big difference: In Erlang, fail as early as possible is the
>> norm. In Clojure it is almost the opposite.
>>
>> Many errors in Clojure code will result in nil, and most operations
>> accept nil as a valid parameter, i.e. many fails will not even be visible
>> unless you check the result.
>>
>> The most common I stumble on is assuming that a value exists in a map,
>> but that is just the top of the iceberg
>>
>> I assume Rick H did this on purpose, and I am looking for pointers to
>> where the rationale behind is described.
>>
>> Thanks,
>>
>> Mattias
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to