On approximately 11/3/2008 3:38 PM, came the following characters from the keyboard of Paulo J. Matos:
On Mon, Nov 3, 2008 at 10:19 PM, Aaron Brady <[EMAIL PROTECTED]> wrote:
On Nov 3, 3:45 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
"Paulo J. Matos" <[EMAIL PROTECTED]> writes:

On Mon, Nov 3, 2008 at 12:32 PM, Ben Finney
<[EMAIL PROTECTED]> wrote:
I'm wondering a more fundamental question: What are structures?
That is, what do *you* mean by that term; without knowing that, an
answer isn't likely to be meaningful.
Well, I guess that everyone pretty much gets since it exists in
every other language as struct, or define-structure, or whatever is
the syntax.
Take care with broad sweeping statements about "every other language",
or even "most other languages". They are usually flat-out wrong:
there is a stunning variety of different approaches and concepts in
programming languages, with very little common to even a majority of
them.
Yea, verily.  How many languages do you think that is?  Feel free to
count C and C++ as different ones.

"Four shalt thou not count, neither count thou two...."
http://en.wikipedia.org/wiki/Holy_Hand_Grenade_of_Antioch#Usage_instructions

Well, I wouldn't dare to say I know a lot of languages but the ones I
do provide mechanisms to define structures / records: C, C++, Scheme,
Common Lisp, Haskell, SML, Ocaml.
This is obviously a minority if you count all available programming
languages in the world, but I would dare to say these cover a lot of
ground.

There are languages that do not have structs; but usually there is some way to obtain something similar.

However, I wouldn't dare to say Python needs structures to be a good
language, or anything similar. My question was more directed to : if
there aren't structures in Python, what do Pythonists use instead?
(I have seen dicts might be an alternative, but as I said in previous
post, they seem to flexible [making them a canon to shoot a fly, and
they probably lack constant-time access, right?]

Dicts have constant time access. On the other hand, the constant is significantly larger than the constant for accessing a C struct.

Note that classes, by default, are based on a contained dict! There are games to be played with slots that can apparently improve that. I am not yet experienced enough with Python to know if a slot is as fast as a C struct, but perhaps it is. You can have both slots and a dict, to get both speed and flexibility, or you can eliminate the dict and use slots only, but that limits your flexibility. But structs aren't flexible, except at compile time, so that might not be a problem for you.

Another thing I don't know is if slots are as fast as tuples. Perhaps a slots-only class and a tuple might be speed rivals? But the former is mutable, and the latter not.

Perhaps a more experience Python user can answer that question, at least for some particular implementation.

--
Glenn -- http://nevcal.com/
===========================
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to