My thoughts & experiences with D so far, as a novice D coder

Vidar Wahlberg vidar.wahlberg at gmail.com
Wed Mar 27 11:06:45 PDT 2013


I'm impressed and most grateful for the feedback, I've learned 
some new things today :)

> int i = 5;
> auto foo = new int[][](i,i);

Won't this create an array (with 5 elements) of arrays (with 5 
elements), also called a "jagged array"? Where memory is not 
necessarily continuously allocated and looking up values adds 
another layer of indirection?


> It is much more simple actually, "typeof(match(string.init, 
> Regex.init)) variable;" and no extra functions or source 
> digging is needed.

Many of you pointed this out, thanks, this a better solution than 
what I had. I needed to write "Regex!char.init" and not just 
"Regex.init", but that's just a minor detail.


> Yea, I'd imagine there would be some value-type/reference-type
> confusion from a lot of newcomers just because D *has* both 
> value types
> and reference types. As opposed to, say, Java where (almost?) 
> everything
> is a reference type, or C++ where everything is a value type, 
> etc.
> 
> Personally, I find it very much worthwhile to have both value 
> and
> reference types. But you're right it is something many people 
> will have
> to learn to get used to, and particularly so with arrays.

I find it quite nice that you have both value and reference 
types, and for the most part it's rather clear in D when you're 
dealing with a reference and when you're dealing with a value. It 
was just arrays that caught me off guard, and I think others with 
a similar background may do the same mistake, so my comment about 
this really just is "arrays may require more explanation aimed at 
Java developers" :)


> But D has an easy solution - just use RDMD instead:
> 
> rdmd --build-only -I{include paths as usual} {other flags} 
> main.d

That's a good tip! Somehow I had the notion that rdmd was purely 
a tool for "scripting", as in dynamically parsing code (like 
Python, Perl, etc), so I never looked much into it.


More information about the Digitalmars-d mailing list