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

Vidar Wahlberg vidar.wahlberg at gmail.com
Thu Mar 28 20:01:40 PDT 2013


On Friday, 29 March 2013 at 01:13:36 UTC, Jonathan M Davis wrote:
> In either case, I'd suggest reading this if you want to know 
> more about
> ranges:
>
> http://ddili.org/ders/d.en/ranges.html

Thank you, I will read that (when the time is not 0400).
I feel I need to stress that this is something that quite 
possibly will scare away newcomers, that static arrays, dynamic 
arrays and ranges looks very similar to each other, but behaves 
differently. This is not the first time I fall in this pit, and I 
suspect it's not the last time either.
And well, sorry for continuing to nag about this, but take a look 
at the documentation for read(), write() and append() in 
std.bitmanip:
T read(T, En­dian en­di­an­ness = Endian.​bigEndian, R)(ref R 
range);
void write(T, En­dian en­di­an­ness = Endian.​bigEndian, R)(R 
range, T value, size_t index);
void ap­pend(T, En­dian en­di­an­ness = Endian.​bigEndian, R)(R 
range, T value);
append() and write() are practically identical, just with write() 
having an extra parameter. The documentation even comes with 
examples for write() that use "ubyte[] buffer; 
buffer.write!ubyte(42, 0);", is it really odd that I assumed I 
could use append() in a similar matter when its parameters are 
exactly the same as for write() (minus the index)? Or is it 
unthinkable that I mistook arrays and Ranges for being 
interchangeable when the examples pass an array to a function 
that takes a Range?
Ranges is something that's going to be new for a lot of people 
entering this language. When you know how arrays and ranges works 
in D I'm sure this makes perfect sense, but until you learn that, 
this is something that likely will confuse many people.

Hopefully the article about ranges will clear things up for me.


More information about the Digitalmars-d mailing list