Optimize my code =)

bearophile bearophileHUGS at lycos.com
Sun Feb 16 16:50:51 PST 2014


Robin:

> I always thought that D would be much easier to learn than C++ 
> as all the people always say that C++ is the most complex 
> language. After what I have learned so far D seems to be much 
> more complex which isn't bad in general, but the learning curve 
> doesn't feel so well atm as I am mainly confused by many things 
> instead of getting what happens behind the scene.

D is not a small language, it contains many features, but 
compared to C++ it has less corner cases, less traps, and on 
default it's often safer than C++. In C++ you need to take care 
of many details if you want to write correct code. Writing D code 
should be faster and safer than C++.


> immutability which result in zero performance boost in 
> non-paralell environments,

A good D compiler like ldc2 is sometimes able to optimize better 
the code that uses immutable/const. But immutability is also for 
the programmer: to make the code simpler to reason about, and 
safer.


> the fact that classes are by-ref and structs are by-val is also 
> confusing from time to time to be honest.)


> D seems to be more problematic when it comes to learning how to
> optimize the code.

Perhaps because D also focuses a little more on correctness of 
the code. You see this even more in Ada language.


> I would love to see how much performance a D vetaran like you 
> is able to grab out of my codes. Just tell me where I shall 
> upload them and I will do so.

I guess your code is composed by just one or two small D modules, 
so you can post it here:
http://dpaste.dzfl.pl/
You can also upload there the Java code, to help me compare and 
to know what you were trying to write :-)


> However, what is true is, that it is (at least for me) harder 
> to learn how to write efficient code for D than it was to learn 
> it for C++.

But I think on average it's a little harder to write correct code 
in C++ compared to D.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list