dsimcha wrote: > == Quote from Walter Bright (newshou...@digitalmars.com)'s article >> D is an extremely powerful language, but when I read complaints and sighs >> about >> other languages, few seem to know that these problems are solved with D. >> Essentially, we have a marketing problem. >> One great way to address it is by writing articles about various aspects of D >> and how they solve problems, like >> > http://www.reddit.com/r/programming/comments/cb14j/compiletime_function_execution_in_d/ >> which was well received on reddit. >> Anyone have good ideas on topics for D articles? And anyone want to stand up >> and >> write an article? >> They don't have to be comprehensive articles (though of course those are >> better), even blog entries will do. > > This probably won't be replied to because I'm starting a new sub-thread in a > mature discussion, but I wonder if we could write about the advantages and > disadvantages of duck typing vs. static typing, comparing Python vs. Java at > first, then bring D into the picture to show how, to a greater extent than C++ > templates or C#/Java generics, it solves may of the problems of static typing > without introducing the pitfalls of duck typing. > > Here's a simple example of something that would be awkward to impossible to do > efficiently in any other language: > > /**Finds the largest element present in any of the ranges passed in.\ > */ > CommonType!(staticMap!(ElementType, T)) largestElement(T...)(T args) { > // Quick and dirty impl ignoring error checking: > typeof(return) ret = args[0].front(); > > foreach(arg; args) { > foreach(elem; arg) { > ret = max(elem, ret); > } > } > > return ret; > } > > Do this in C++ -> FAIL because there are no variadics. (Yes, C++1x will have > them, but I might die of old age by the time C++1x exists.) > > Do this in any dynamic language -> FAIL because looping is so slow that you > might > die of old age before it executes. Besides, who wants to do computationally > intensive, multithreaded work in a dynamic language? > In python: max (map (max, args)) should have reasonable performances and is *much* more elegant...
Jerome -- mailto:jeber...@free.fr http://jeberger.free.fr Jabber: jeber...@jabber.fr
signature.asc
Description: OpenPGP digital signature