Associative arrays in D and default comparators

Steve Horne stephenwantshornenospam100 at aol.com
Fri Sep 8 08:56:38 PDT 2006


On Fri, 08 Sep 2006 14:26:46 +0200, xs0 <xs0 at xs0.com> wrote:

>But if you hide the implementation via AA syntax sugar, those many 
>programmers won't have to deal with templates at all?

To me, code generated by the compiler is really just a hidden
template. The only reason a template wouldn't be able to do everything
that a built-in feature can is because the language doesn't have the
template handling features to do it. But D has excellent template
support.

Syntax sugar? Well, yes, to a point. But too much can make you very
very sick. And while sugar and salt look the same...

Sure, templates can cause bloat. Any language feature is bad, when its
used badly. And C++ templates are cryptic. So what? D is a better C++!
So long as your not pushing the limits for the fun of it, D templates
are much cleaner. Too much to cope with? Take a look in a builders
van. Are programmers really so much more stupid than builders? We
really can't cope with a full set of tools?

OOP was considered a new, cryptic, inefficient and scarey concept
once. And structured programming, too. In fact, the current template
FUD is really just an echo from when the first high level languages
came out. It's all been said before... "bloat, inefficiency, me
scared, wah!!!"

And all the time, off people go, grabbing perl, python and even XSLT
to generate template code! I mean - have you ever tried to read an
XSLT code template? The obfuscated C guys were humiliated!

To me, D is like the salvation I've been waiting for - its template
handling is good enough that maybe I'll never have to reach for Python
(at least as a code generator) again. No disrespect to Python, but
it's always easier to write each project in one language.


BUT - much as I like templates, I also like D's built-in associative
arrays. And not just because of syntax sugar.

The thing about generating code using templates is that, like
anything, the better the tools you have, the more efficient and
maintainable the end result can be. You can use the right tools for
the job. Since you're not wasting time abusing the wrong tools, you
can do the job properly. So it won't all fall down the first time
someone leans on it.

D already beats C++ easily, but a good solid AA available at compile
time is an attractive idea. Better still, when those AA literals
arrive.

Its not either-or at all. Two complimentary features :-)

-- 
Remove 'wants' and 'nospam' from e-mail.



More information about the Digitalmars-d mailing list