More range woes: composed ranges are unsafe to return from functions

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Oct 18 22:17:13 PDT 2012


On Fri, Oct 19, 2012 at 04:24:53AM +0200, Marco Leise wrote:
> Am Tue, 16 Oct 2012 17:28:47 -0700
> schrieb "H. S. Teoh" <hsteoh at quickfur.ath.cx>:
> 
> > On Tue, Oct 16, 2012 at 09:47:36PM +0200, jerro wrote:
> > > >Hmm. There *is* a delegate being passed to map(). Would that
> > > >cause problems? Theoretically it shouldn't, but as you said, if
> > > >dmd isn't handling it correctly that could cause problems.
> > > 
> > > I'm looking at the disassembly of cprod
> > > (http://pastebin.com/ngTax6B8) and there doesn't seem to be a call
> > > to _d_allocmemory in it. AFAIK it should be if the memory for the
> > > variables that the delegate uses was allocated on the heap?
> > 
> > Filed bug:
> > 
> > 	http://d.puremagic.com/issues/show_bug.cgi?id=8832
> > 
> > Whew, what a day! Two compiler bugs, no less, and a whole bunch of
> > Phobos issues. I think I may need to take a break from D for a day
> > or two. :-/
[...]
> And that's where all the good projects end... :D
[...]

Actually, I just went back to working on my personal D project for a
bit. I was a bit disappointed that what I thought would be a quick
side-job (implement cartesianProduct in std.algorithm) turned out to get
stymied by compiler bugs and Phobos issues.

I have to say, though, that in spite of all these problems with the
current implementation of D, it is still pretty dang powerful, and I
would still never go back to C++ again (for my personal projects,
anyway). I have managed to implement in ~2 weeks the vector computation
part of my geometric computation project (that took a whole lot longer
to write in C++ many years ago), and with much cleaner code too. The D
implementation has already far exceeded the original implementation,
both in terms of functionality, and in terms of code cleanliness.

It's just all the little things that D did right: delegates that
simplified the list-processing operator implementation greatly;
templates that allowed me to use the same code to both parse and build
an expression tree or evaluate it on-the-fly (just by passing an
appropriately-crafted subclass to the template); ranges that allow
generic code instead of writing 20 variants of what is essentially the
same code, one for each incompatible container type, etc..
Functional-style code like non-trivial combinations of map and reduce,
which are great for simplifying complex code to just a couple o' lines
-- which are very painful to write in C++ and even harder to debug.

So yes, D still has a ways to go, and it does have its warts, but it's
heaven compared to C++.


T

-- 
Let's not fight disease by killing the patient. -- Sean 'Shaleh' Perry


More information about the Digitalmars-d mailing list