|
|
|
|
|
by agentwiggles
1413 days ago
|
|
> writing functions that solve the easiest or special cases, and then layering those into general functions This is something I've been getting the hang of in my recent playing around with Elixir. In Elixir, you can eliminate a lot of conditional logic by utilizing pattern matching in function signatures. Often, though not always, it's possible to write each of your edge cases with a single function head. In practice this usually looks like a few 1 or 2 line functions for simple cases, and then one gnarly one that does whatever checking you need to assure the right result. It's also a great way to write recursive functions. You can pattern match on the base case - say, an empty list - and then put the recursive case or cases under separate function head. It's a wonderfully fun and expressive language, although I have been missing static types here and there, which counterintuitively seem like they might eliminate a lot of boilerplate from my code. Highly recommended playground for the language geek. |
|