Is D more cryptic than C++?

Abrahm abe2007 at nospam.net
Wed Nov 30 03:57:13 PST 2011


"Peter Alexander" <peter.alexander.au at gmail.com> wrote in message 
news:jb4sjp$1dnr$1 at digitalmars.com...
> 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

OK, but I was considering the syntax-level rather than the process-level 
things. Hence my use of 'cryptic'. I wasn't looking for an overall 
assessment of developing software with D vs. with C++.

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

Having syntax-folding editors these days has caused me to lately leave 
everything in the C++ header files and only move code in .cpp  files when 
there are circular references or when I want to hide something from 
library USERS. IOW, let the compiler figure out that most of the code 
can't be inlined.

Care to comment on how the "only header files in C++"strategy compares to 
"no header files in D"? Seems similar to me.

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

Even more minor than you show above for C++11 has improvements over the 
traditional 'for' loop and the 'auto' keyword allows building similar 
constructs (haven't used my 'foreach' lately so I forget if it was just 
for containers, but probably).

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

I don't think I like that. D's 'sort' is some kind of construct instead 
of a function? Not intuitive at all. Seemingly incorrect from a design 
standpoint (but I'm not thinking about it heavily).

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

I avoid using templates for the most part except where they clearly make 
sense (containers, other things). Sometimes even if a template will only 
be used to generate 2 distinct versions, I use it to ensure some delicate 
code will be only in one place (the template), but in general, most of my 
templates make sense for a lot of types. 




More information about the Digitalmars-d mailing list