Hi Alan,
On 01.08.07, Alan G Isaac wrote:
> On Wed, 1 Aug 2007, Andre Wobst apparently wrote:
> > For read-only attribute no copy is necessary and should
> > not be made.
>
> Perhaps use a tuple instead of a list for read only
> attributes? (Sadly tuples still lack some useful methods
> they should have: are these needed?)
-1 to that. Tuples are tuples and not lists. As I'm writing rules of
thumb today, let me add a whole list here.
- Tuples containing no elements should never occur.
- Tuples containing only one element should never occur.
- Tuples should usually contain different elements of different
type, or at least different meaning. A point (x, y) is perfect.
That's a tuple, not a list. X is one coordinate, y the other.
Different meaning.
- Tuples are basically a simple (and ugly, but speedy and
memory-efficient) way of expressing:
class point:
def __init__(self, x, y):
self.x = x
self.y = y
This means p = (x, y) should better be written as p = point(x, y)
and p[0] and p[1] should become p.x and p.y. The bracket notation
of tuples looks like tuples are similar to lists, but they aren't.
To my mind they are just a quick and dirty way of expressing some
code as shown in the point example above.
- Tuples are useful as dictionary keys, and that's about it.
(I know not all off the points are valid in all cases, but they are
good coding rules to start with ... at least if you ask me. :-) )
Overall, don't use tuples. If you're a python beginner, never use
tuples at all ... :-)
Well, I'm a bit crude today, but ... this advice it not that bad.
André
--
by _ _ _ Dr. André Wobst
/ \ \ / ) [EMAIL PROTECTED], http://www.wobsta.de/
/ _ \ \/\/ / PyX - High quality PostScript and PDF figures
(_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user