Warnings/What should I know?

simendsjo simendsjo at gmail.com
Fri Oct 18 00:21:15 PDT 2013


On Friday, 18 October 2013 at 06:13:38 UTC, DDD wrote:
> I'm learning D. I'm curious about surprises I may get. I 
> typically use C++, C# and javascript

Some stuff from the top of my head. Remember that you're asking 
for gotchas and
surprises rather than the nice features of D :)

* D has built-in support for three different character types. 
UTF-8, 16 and 32.
   The default, char and string, is UTF-8. This means .length 
gives the number
   of bytes, not necessarily the number of symbols.

* Private protection is private to the module, not to the type.
   This means a private class method can be called from anywhere 
in the module.

* Array slices are great, but they require some understanding on 
how the
   underlying runtime handles them. See the array slice tutorial.

* D has compile-time reflection rather than runtime. There are 
some features
   related to runtime reflection, but it's quite minimal. It's 
possible to get
   runtime reflection by using compile-time reflection though.

* Templates in D is actually useful, so use them :)
   For example, in C#, generic type constraints isn't part of the 
signature, so
   you cannot overload generic functions. In D, this is not a 
problem.
   You can look at std.typecons to get a glimse of how powerful D 
is (warning:
   it still blows my mind, so it's not for the faint of hart, and 
you should
   probably delay this - most D code is actually very nice and 
readable and not
   at all this complex).

* D doesn't have a preprocessor. You can solve much of the same 
stuff by using
   string mixins, template mixins and debug and version 
statements. Note that
   version statements is quite minimal and doesn't support stuff 
like && or ||
   by design.

* The GC isn't as fast as in other languages (yet?), so if you 
are experiencing
   performance problems in a tight loop, try disabling the GC 
during that loop.

* Not a gotcha, but you should look into D specific features like 
transitive
   const/immutable, pure, nothrow, safe, DbC, unittest, -cov, 
final switch,
   scope guards, templates, foreach etc. These change the way you 
code and is
   idiomatic D, so it's nice to learn them early on.


More information about the Digitalmars-d-learn mailing list