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.

Reply via email to