Support for functional programming paradigm

Don Clugston dac at nospam.com.au
Tue Jan 2 02:50:01 PST 2007


Glen Perkins wrote:
> My coding style seems to take on more functional flavor with each passing
> year. Especially when I don't know what I'm doing, meaning I'm doing something
> interesting, I like to build up from small functions, use a lot of recursion, etc.

> What support does D offer with respect to inlining and tail recursion?

I think it's quite poor at the moment (in fact, in DMD, I don't think 
anything with a loop gets inlined :-( ). Essentially, it performs the 
same optimisations that the back-end (shared with the C++ compilers), 
there are no D-specific optimisations at present.

But Walter's made very clear statements that the situation will improve.
The D language enables much much more aggressive optimisation than is 
possible in similar languages.  Post-1.0, I think Walter will start to 
put more emphasis on performance.

> For those of you who are functional programmers yourselves (I am, but it's not
> the only paradigm I use, and I'm hardly a purist about it when I use it), what
> features does D have (if any) that might enable a more functional style of
> programming than you can get from, say, Java or C++?

* Inner functions. (This actually opens up a whole programming style 
which isn't possible in those other languages).
* Delegates.
* Anonymous delegates.
* The template metaprogramming system forms a far purer functional 
programming language than C++'s templates do.

There's probably more, but all those features are highly significant.



More information about the Digitalmars-d mailing list