News for hackers. Stuff that matters.
Re:Anti-if: The Missing Patterns by mikkom on Friday June 10, 2016 @03:40AM (#11874816)
All these complicated examples and no mention of functional pattern matching or pattern matching at all.

IMHO These are by far the two most important ways to get rid of complex code embedded with ifs.

One very good example of this is erlangs factorial method.

   factorial(0) -> 1;
   factorial(N) -> N * factorial(N-1).
There are many other nice examples at the erlang documentation:

https://www.erlang.org/course/sequential-programming#funcsyn...

Re:Anti-if: The Missing Patterns by chriswarbo on Friday June 10, 2016 @06:10AM (#11875351)
Unfortunately, pattern matching isn't available in many languages (or at least, including a new dependency for the sake of removing `if`s may not be worth it).

On the other hand, the article recommends using sub-type polymorphism, which is also unavailable in many languages.

Re:Anti-if: The Missing Patterns by majewsky on Friday June 10, 2016 @05:02AM (#11875135)
True functional-style pattern matching is only slowly coming into imperative languages right now, most prominently in Rust.