News for hackers. Stuff that matters.
Re:Functional Programming Doesn’t Work (and what to do about... by davidw on Tuesday December 29, 2009 @05:07AM (#1020309)
That example actually appears fairly regularly in Erlang code.

    A1 = ...
    A2 = ...
And it leaves a bad taste in one's mouth.

I see putting stuff in a variable as a way to 'take a breather' in the middle of code:

    A = some(hairy(function(that() + does() * lots()));
    B = back(into(A) + the(A) fray());
I guess that's not the best example because A is used twice and you could just pop the 'A' calculation out into its own function, but sometimes it's nice to make code easier to read by breaking stuff into discrete steps that are easy to read later, rather than one huge line that does everything and then returns it.
Re:Functional Programming Doesn’t Work (and what to do about... by silentbicycle on Tuesday December 29, 2009 @09:01AM (#1020463)
The "A1 = ..." thing is a convention from Prolog, from which Erlang inherited its single-assignment variables (and many other relatively unusual features). People who write code with several levels of X1 = ..., X2 = ... vars are probably writing Erlang (or Prolog) with a thick imperative accent. It's like writing Python for loops using integer indexes - unless there's a specific reason to do so, it's a sign that the author is probably new to Python.

While putting intermediate steps of a calculation into variables can help clean up the code, if there's any sort of conceptual significance to that value, it's worth choosing a better name than X1. "ATC" (with "Avg. Triangle Count" as an end-of-line comment), for example, would actually mean something.

Re:Functional Programming Doesn’t Work (and what to do about... by ajross on Tuesday December 29, 2009 @12:52PM (#1020872)
I think the cleaner way to describe that in functional terms is "giving a symbolic name to sub-expressions". There's nothing "stopping" or "starting" about the communication, you're just splitting out some part and labelling it. Obviously "A1" doesn't convey much, but somethign like "successFraction" does. I do this in imperative languages too.