7 ms·
f(X) -> X1 = foo(X), X2 = bar(X1), baz(X2). If I use the pointless variable names like that, sure, I run into trouble, but this means I'm a s
by phoe-krk 8y ago
f(X) ->
X1 = foo(X),
X2 = bar(X1),
baz(X2).
If I use the pointless variable names like that, sure, I run into trouble, but this means I'm a shitty programmer who cares little about program readability.
f(X) ->
fooedX = foo(X),
baredX = bar(fooedX),
baz(baredX).
f(X) ->
fooedX = foo(X),
fabedX = fab(fooedX),
baredX = bar(fabedX),
baz(baredX).
Or just
f(X) ->
baz(bar(fab(foo(x)))).
- didibus 8y agoYa, actually, I often use this style in other languages to be clear about the intermediate steps. My understanding though is that the problem is mixed with Erlangs pattern matching it can cause issues, because it won't necessarily fail to repeat the variable name, it'll just behave wrong. At least that's what I heard.
- cygned 8y agoI am not an Erlang programmer, but that style of programming bothered me, too. This variable per function application is a code smell in my point of view and should be handled with function composition or partial application (not sure how Erlang handles these, though).
- jxub 8y agoElixir has pipes for this, effectively solving this painpoint.