The Many Faces of D - slides

Russel Winder russel at russel.org.uk
Sun Oct 3 07:15:59 PDT 2010


On Sun, 2010-10-03 at 09:59 -0400, bearophile wrote:
[ . . . ]

> Page 10, and in other pages I'd like a non-proportional font for the
> code, because I find it a little more readable (even better if it's
> colorized, there are online tools able to produce colorized HTML from
> D1 code too).

I continue to be intrigued by people who believe that code, unlike text,
is more readable in a monospace font.  Personally I think monospace
fonts make code unreadable, I always prefer proportional fonts for code.
Currently I use Ocean Sans MT.

Colourized though, I agree, makes things more readable -- as long as the
colourization theme matches the semantics of the code fragment,
obviously.

[ . . . ]

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

Coming from a Pythonic realization of these ideas, list comprehensions
seems to be the best way out of this sort of thing, so instead of:

        def sumOfSquares ( sequence ) :
            sum = 0.0
            for item in sequence :
                sum +=  item * item
            return sum

it is better to write:

        def sumOfSquares ( sequence ) :
            return sum ( [ item * item for item in sequence ] )
        
So the question is whether there is an idiomatic D version of this.

[ . . . ]

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20101003/64cc7aa7/attachment.pgp>


More information about the Digitalmars-d mailing list