Hacker News new | ask | show | jobs
by Veen 3529 days ago
> You write your base functions, then higher-level functions which use those base functions, and so on. Functions all the way down.

I'm hoping to follow a similar trajectory to you, but with Elixir instead of closure. At the moment though, I tend to do things the other way around: write the top level functions and then fill out the base functions.

So I'd start a module with

def whatever(something), do: something |> function1 |> function2 |> function3

Then I'll write function1, 2, and 3 and whatever helper functions they need. And so on until it works. Maybe doing it your way is a better approach: helps you think it through first.

(although I'm aware some would say that tests should come before everything else anyway)

2 comments

It is useful and necessary to use both directions at times. You can't always presuppose the relevant details. But do be ready to factor away functions at a moments notice
"some would say that tests should come before everything else anyway"

Which some others consider a cargo-cult practice if done mandatorily for it's own sake.

Good luck on your studies!