To begin in D coming from Python

bearophile bearophileHUGS at lycos.com
Mon Jul 21 07:22:14 PDT 2008


Jarrett Billingsley:

bearophile:
> > - CPython is written in C, so C is much better integrated with Python than 
> > D.
> Uh -- Pyd?

My post refers to Pyd too, do a Find on it.

But what I have written there is correct, CPython is written in C, and you have Boost.Python, Weave, Python Inline, ShedSkink, Pyrex, Cython, Swig, etc etc etc. I like Pyd, but for C you can find 20 more things to use it with/through/along Python.


> > int[string] aa;
> > aa["hello".dup] = 10;
> > etc.
> 
> I don't know why you're .dupping there.

Maybe it's useless, sorry.
But in D V.1.x the management of literal strings is awful, so I often dup them to avoid nasty bugs later. In the past I have described in this newsgroup two different kinds of bugs derived from string literals, that was mostly ignored. In D 2.x strings are immutable so many of those problems may be solved if you use "string".


> Or, you know, use another hash implementation.

I presume the OP was asking about a built-in one, because you can use a hash_map in C++ too (even if it may sometimes be slower than Python dicts).

So far I haven't seen external and reliable hash libs that can be used with Phobos that are fast enough. Tango ones too aren't fast enough, I think.


> Like Tango's HashMap, which 
> is consistently faster than the built-in AAs.

They are just a bit faster, their syntax is much worse (and I am using Phobos, but that's not a fault of Tango).

Note that I am not saying this to bash D or Tango, I know D is a young language still, I was just stating a fact regarding how I now see things.


> Or write your own.

A really good hash implementation may take few weeks to be written and some years to be tuned/refined :-) If you take a look at the Lua language, you can see that they have recently found ways to speed up their associative arrays significantly.
You can't expect a D newbie coming from Python and not knowing C to write a first-class hash implementation. Probably only few (2? 5?) people here are able to do it, and I am not among them :-)

Bye,
bearophile



More information about the Digitalmars-d mailing list