What features of D are you using now which you thought you'd never goint to use?
monarch_dodra
monarchdodra at gmail.com
Sat Jun 22 13:08:59 PDT 2013
On Saturday, 22 June 2013 at 19:40:28 UTC, Joseph Rushton
Wakeling wrote:
> On 06/22/2013 05:17 PM, Andrej Mitrovic wrote:
>> Anyway, what features are you using now that you thought you'd
>> never
>> use when you started out using D?
>
> Ranges, of course :-)
>
> When I was first using D I knew that there were these things
> called ranges that
> were supposedly D's superior solution to what C++ did with
> iterators, but I
> didn't really understand what they were in practice, beyond the
> fact that they
> were these things that one could foreach() over.
>
> It didn't take too long to get the hang of using some of the
> entities from
> std.range (iota is a favourite), but what I hadn't imagined was
> that I'd
> actually start writing ranges myself as a habitual part of
> program design.
> These days I do so all the time.
Personally, I've found ranges to be a very useful and powerful
*high level* abstraction. They lend themselves work very well for
adapting and chaining (which iterators don't). However, they do
come with *some* downsides (IMO):
#1: Performance issues: No matter how I use them, it seems that I
can never get the same raw performance I could get with raw
iterator iteration.*
#2: Extremelly bad compatibility with simple no bidir/non-slicing
ranges: There is no way to iterate over a specific part of a
range, and making a range out of what was just iterated over. For
example "Get the beggining of this range until the first x": not
possible without slicing.
#3: Take up more room when all you want to do is to keep a
reference to a single item.
*Overall*, I think they are win of course, and much easier to use
and scale much better than iterators, but iterators *can* do
things that ranges can't.
*: #1 is subject to simple iteration: Once things scale in terms
of adaptors, ranges win because of the "single item empty"
mechanic
More information about the Digitalmars-d
mailing list