Recommendation: "functional" keyword
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sun Jan 9 18:42:58 PST 2011
On 01/09/2011 04:31 PM, Sean Eskapp wrote:
>> That's.. ehem.. quite limiting. :) (you probably meant heap)
>
> I meant what I said, and I said what I meant. Stack allocated implicitly would be
> fine, but explicit stack allocation, like declaring variables, doesn't happen in
> purely functional languages.
>
> Personally, I like being able to impose this contract on myself to write
> functional code, just like I like being able to use const and @safe. Apparently
> I'm in the vast minority!
You may always use immutable to enforce such a contract.
Walter and I introduced the relaxation that private transitory variables
are allowed inside pure functions deliberately, and we take great pride
in it. I personally consider the desideratum of "writing functional
code", when taken to extremes, as damaging and devoid of meaning as
setting out to write "object-oriented code" or "generic code" at all costs.
Good functional code is not feel-good. It means what it says - functions
with functional semantics. Private transitory variables are extremely
useful because they make it easy to implement a variety of algorithms
without contortions that are typical of FP, such as threading state as
additional function parameters when implementing Fibonacci correctly, or
using a helper function to implement the factorial function correctly. I
strongly believe that we've hit a great sweet spot there, and that there
will be lasting influence following this relaxation.
Andrei
More information about the Digitalmars-d
mailing list