The Many Faces of D - slides

retard re at tard.com.invalid
Sun Oct 3 15:44:04 PDT 2010


Sun, 03 Oct 2010 12:43:07 -0700, Walter Bright wrote:

> Russel Winder wrote:
>> On Sun, 2010-10-03 at 09:59 -0400, bearophile wrote:
>>> Page 20: is that functional? It even contains a mutable "sum" value.
>>> It may be seen as kind-of-functional. A more functional style is to
>>> use a reduce (fold) there, from std.algorithm.
>> 
>> I agree this is a weird sort of an example of "functional".
>> sum_of_squares as a function has no external side-effects (though
>> clearly the iteration has a side effect internally) and is
>> referentially transparent.  So as a thing that can be used as a
>> "functional programming" function it is fine, its implementation is
>> though very much imperative programming -- at its worst ;-)
>> 
>> Given an imperative language with no tail recursion capability then one
>> has to declare a non-functional floor even when doing functional style
>> programming.  In effect the execution graph has to be allowed to have
>> leaqf nodes that are implemented imperatively.
>> 
> 
> This is quite deliberate on my part, and I'm glad it piqued your
> interest. D's support for functional programming is NOT about all data
> being immutable. It is about being able to draw a circle around a block
> of code (i.e. a function) and saying that "THIS block of code has no
> side effects." If it modifies variables internally that is of no import
> if those modifications are not visible outside of that block.
> 
> This is, in my not so humble opinion, of great value in that one does
> NOT have to rethink one's approach to coding in order to gain the
> advantages of functional programming. I.e. one can write a normal loop
> such as the sum one, rather than trying to figure out list
> comprehensions and tail recursion.
> 
> It's like what's wrong with C++ metaprogramming - you have to learn a
> whole new language. D metaprogramming can be done using ordinary D
> functions. Nothing new to learn.

Is this also true for Haskell/OCaml/SML/Erlang/Clojure/Lisp programmers? 
Nothing new to learn when using the "functional" features of D? Does TCO 
work well? Other common optimizations such as common deforestation 
techniques? The sad fact is, there's no need to learn new stuff ONLY when 
one comes from C/C++. Users of every other language have very much to 
learn. Not necessarily in a good way.


More information about the Digitalmars-d mailing list