Is D more cryptic than C++?

Peter Alexander peter.alexander.au at gmail.com
Wed Nov 30 01:30:08 PST 2011


On 30/11/11 6:30 AM, Abrahm wrote:
> I get the feeling that it is from reading the threads in here. Is there
> somewhere that has non-trivial D and C++ code that does the same thing,
> side by side, so that I can evaluate D better? Links if you got 'em
> please. Maybe even a small entire application would be good to download
> and perusal. This request really calls for code that is not part of D, so
> the D front end compiler and the like is inappropriate.

If you care about non-trivial programs and want to compare D with C++, 
here's all you need to know:

No header files
- Seriously, this makes all the difference. Several times I have quit D 
to go back to C++, then I remember header files. I use C++ at my day 
job, so I am used to having to maintain header files, but if you switch 
from D to C++, you WILL feel the pain.

Range-based foreach for integral types
- foreach (i; 0..n)
   vs.
   for (int i = 0; i < n; ++i)
   It's a small thing, but makes all the difference.

Sorting on some member or member function.
- sort!("a.weight < b.weight")(things);
   vs.
   sort(things.begin(), things.end(), [](Thing const& a, Thing const& b) 
{ return a.weight < b.weight; });
   And that's if you're using C++11. Huge amounts of pain if you're not.


In general, things just work and do what you expect without syntactic 
nonsense. If you use templates a lot then you'll definitely notice a 
difference there.


More information about the Digitalmars-d mailing list