How does D improve design practices over C++?
Don
nospam at nospam.com
Wed Nov 5 00:31:44 PST 2008
Tony wrote:
> "Janderson" <ask at me.com> wrote in message
> news:gepsn2$21jr$1 at digitalmars.com...
>> Tony wrote:
>>> Let me be facetious with Janderson's list plz...
>>>
>>> "Janderson" <ask at me.com> wrote in message
>>> news:ge8tpd$1f6b$1 at digitalmars.com...
>>>> Hi,
>>>>
>>>> I was talking with some collages at work and they asked me how D
>>>> enforces good programming practices. For course I mentioned a couple
>>>> of the ones I knew of hand -
>>>>
>>>> - Unit checking
>>> Not sure what is meant by this, but it sounds minor.
>> Sure C++ can do unit checking, but its not built in. You have to use
>> macros or templates in something that is not really designed to work
>> correctly with the language. Even if you ignore that there's a barrior to
>> entry by not having something like this in the language. By having it in
>> the language good coding practices are encouraged.
>
> I write unit tests. I don't know why I'd need or want language support for
> that.
Yes, it's simple syntax sugar. But in practice, it really seems to
dramatically affect the number of unit tests that actually get written.
>>>> - More restrictive casting
>>> Ouch!! I prefer to slice bread with a knife rather than having a machine
>>> do it. (Bad analogy, but y'all get the point).
>> I'd rather the machine catch something at compile time rather then
>> runtime.
>
> As long as I'm not prevented from doing casting I know is safe, it's fine.
D doesn't restrict your ability to do casting in any way. It just makes
it a bit more difficult to cast by accident.
>
>>>> - No C style Macros
>>> Implementing a template or template system with a good preprocessor is
>>> something completely different than macros. I value the preprocessor for
>>> such uses (I wish it was more powerful than in C++ though).
>> Macros in C++, powerful yes but I think they are over used.
>
> Macros and using the preprocessor as a template machine are apples and
> oranges. Every use of the the C++ preprocessor does not fit the definition
> of "macro", thought everyone pounces on the obvious as you do below:
One of the main original motivations of the C++ template system was to
provide a typesafe equivalent to the preprocessor. It turned out to be
much more powerful than the preprocessor, but there's still major
functionality which you can only do with the preprocessor. D templates
are _significantly_ more powerful than C++ templates, so they are
capable to doing almost all preprocessor jobs.
D also has string mixins which can do stuff you'd do in C with
preprocessor token pasting, but it's typesafe and a hundred times more
powerful.
So I wouldn't list "no C-style Macros" as the benefit. I'd rather say
the benefit is that the preprocessor tasks are integrated in the main
language (they are not simply discarded, the way they are in Java etc).
Bear in mind that the list was not "what's better about D" but rather
"what DESIGN PRACTICES are better in D". Which is not exactly the same
question.
More information about the Digitalmars-d
mailing list