Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    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)))).


I 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).


Elixir has pipes for this, effectively solving this painpoint.


Ya, 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: