2 ms·
> Second function requires parsing two fragments of code. foo1 is used to illustrate a point not that you'd name functions like that. The whole thing would be
by rdtsc 11y ago
> Second function requires parsing two fragments of code.
foo1 is used to illustrate a point not that you'd name functions like that. The whole thing would be probably:
foo(bar) -> void;
foo(_) -> undefined.
I don't know, I see that better than the case statement.
- biokoda 11y agoAppending 1 to functions is quite common in Erlang for cases such as that. You cant find a good naming scheme for small fragments of ideas.
- rdtsc 11y agoI don't know, I find I do it with variables more than functions. With functions I seprate them by arity, so there could be a foo/0 and foo/1 maybe. But usually I haven't seen much fun1 fun2 fun3 ... pattern. And if you don't see a way, don't split it. I mean, make your code look good and easy to understand for yourself and others, that's the point.
- masklinn 11y agoAppending 1 to functions might be used for utility/internal functions with a slightly different (and less convenient) signature than the base[0], usually because the original signature does not allow for tail-recursion. That's not the case here.
- polack 11y agoAlso, adding an "catch all" is usually not recommended in Erlang (even though it's good for some things), so most of the time you would do just: foo(bar) -> void. And then let it crash if the value is something else than expected.
- rdtsc 11y agoAh! Very good point. Yes I agree.