Why D is annoying =P

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Oct 24 13:05:46 PDT 2012


On Wed, Oct 24, 2012 at 09:41:41PM +0200, Mehrdad wrote:
> On Wednesday, 24 October 2012 at 19:34:15 UTC, H. S. Teoh wrote:
> >I don't know if there is any struct-specific problem here, but AA
> >comparison right now is horribly horribly broken (search on the
> >bug tracker for "AA" and you'll see a bunch of issues on that
> >end). You're incredibly lucky that two AA literals actually
> >compared equal. In some cases, not even that is guaranteed.
> 
> 
> Yeah, I was a little aware that AAs were semi-broken, but I thought,
> hey, if it seems to work then it obviously works.
> Turns out that wasn't so true. :\

The AA implementation badly needs to be revamped. But the problem is
that it's non-trivial, may break existing code, etc.. I do have a (semi)
working version of a prospective AA replacement, though:

	https://github.com/quickfur/New-AA-implementation

You might be able to make use of it if you're willing to live with
broken IFTI (which is no big deal if you just explicitly type what you
instantiate the AA with).


> >I've tried to clean up the AA code but it's a tangled messy ugly
> >labyrinth with fragile hacks sprinkled in, and didn't get to the
> >point where it's ready to commit. One major obstacle is that parts
> >of it are implemented in compiler hacks, and part of it is
> >schizophrenically duplicated in object_.d, not necessarily
> >consistently, and it's just Not Nice in general. That it works at
> >all is reason enough to be thankful. I don't expect things to be
> >pretty once you start poking into the intricacies of AA's, sad to
> >say.
> 
> Yeah, the trouble is, none of the set-based data types (including
> maps) in D seem to be working...
> 
> - AAs are broken
> - AssociativeArray is the same as above, I think?

Yes it's the same. It's not meant to be used directly by user code,
though. The two are supposed to be the same.


> - RedBlackTree is useless (how do I keep a "set of sets"?)

What's wrong with RedBlackTree? You can just do something like:

	RedBlackTree!(RedBlackTree!MySet) setOfSets;


[...]
> So you can't really write a real program in D, to put it blunty.

That's a bit harsh. It's not hard to write your own hash implementation
in D, given the expressiveness of its templates and compile-time
features. The bugginess of the built-in AA is lamentable, definitely,
but it doesn't *prevent* you from writing your own data structures. All
programmers worth their salt should be able to roll their own where the
current implementation is inadequate, anyway. ;-) In any case, as they
say in the open source community, patches are always welcome.

Plus, you *can* use AA's for all sorts of stuff in general, if you just
avoid some of the most glaring bugs. It only takes 15 minutes to write
your own opEquals() in a struct that wraps around an AA, and it's
equally fast to parametrize that struct to take arbitrary types, and
provide wrapper functions that work around the current bugs. None of
the current issues are showstoppers, as annoying as they may be.


T

-- 
Do not reason with the unreasonable; you lose by definition.


More information about the Digitalmars-d mailing list