|
|
Darren New wrote:
> nemesis wrote:
>> Darren New <dne### [at] sanrrcom> wrote:
>>> You're saying "a hastable is for lookups. It doesn't have an order.
>>> Therefore, Python is right to base its data structures on hash tables."
>>
>> It's supposed to be a hashtable.
>
> What is "supposed" to be a hashtable?
Remember we're talking about Python's dict here? A Python dict is
supposed to be Python's builtin hashtable feature. They also employ it
behind the scenes to hold objects' attributes.
> If you need a hashtable, PHP's arrays give that to you. If you need a
> list, PHP's arrays give that to you. If you need order-preserving
> keyed-access data structures, PHP's arrays gives that to you, and Python
> doesn't.
If you need a hashtable, Python's dicts give that to you. If you need a
list, Python's lists give that to you. If you need order-preserving
keyed-access data structures, you may derive a new class from Python's
dict and implement that custom behavior.
I thought specialization was a good thing, specially performance-wise.
If you want just an order-preserving list for your items, PHP most
likely will still incur in a performance loss by calling a hash function
over the item, a Python list won't.
Well, why speculate when we have the sources available?
Here's how to get the PHP ones:
http://br2.php.net/get/php-5.2.9.tar.bz2/from/a/mirror
And here's how to get the Python one:
http://python.org/ftp/python/2.6.1/Python-2.6.1.tgz
Doing so reveals a lot. For instance, now it's not simply in the
correct specialized behavior, consistent semantics and crystal clear
syntax that Python gets my vote as a top-notch language: comparing it's
source with PHP's is also an incredible testament to all the bad things
that go into open-source projects you mentioned, except when done right.
PHP's source is a hell of a mess and tracking down the exact location of
array definition was not easy at all and I had to look up quite a few .h
and greap a bit to find out the one directory it was in:
php5/ext/standard/array.c
Looking inside is like looking into the Devil's guts. Few comments,
lots of macros defined elsewhere, no clue on how to decypher it.
Python's one is a breeze to find:
Objects/dictobject.c
very logical and just as beautiful to look at as Python code.
Both are in C.
And yes, PHP does incur into the hash cost at all times, even if you
just intend to use arrays as a simple list. See
"php5/ext/standard/array.c", array_push, zend_hash_next_index_insert.
Python's lists don't have such problem, as any specialized data structure.
It's amazing you can nitpick and even pick a fight for tools you most
likely don't even care, Darren...
Post a reply to this message
|
|