preferring [] or () in list of error codes?

Albert van der Horst albert at spenarnc.xs4all.nl
Fri Jun 19 06:49:00 EDT 2009


In article <pan.2009.06.09.03.18.23 at REMOVE.THIS.cybersource.com.au>,
>
>
>But practicality beats purity -- there are many scenarios where we make
>compromises in our meaning in order to get correct, efficient code. E.g.
>we use floats, despite them being a poor substitute for the abstract Real
>numbers we mean.
>
>In addition, using a tuple or a list in this context:
>
>    if e.message.code in (25401,25402,25408):
>
>is so idiomatic, that using a set in it's place would be distracting.
>Rather that efficiently communicating the programmer's intention, it
>would raise in my mind the question "that's strange, why are they using a
>set there instead of a tuple?".

As a newby I'm really expecting a set here. The only reason my mind
goes in the direction of 3 items is that it makes no sense in
combination with ``in''.  That makes this idiom one that should be killed.

"
point1 = (0,1,0)
point2 = (1,0,0)
point3 = (0,0,1)
for i in (point1,point2, point3):
    ....
"  ???

I don't think so.
At least I would do

"
        for i in [point1,point2,point3]:
            statements
"

But I greatly prefer a set

"
        for i in {point1,point2,point3}:
            statements
"
Because a set is unorderded, this would convey to the
the compiler that it may evaluate the three statements concurrently.
For a list I expect the guarantee that the statements are
evaluated in order.
For a tuple I don't know what to expect. That alone is sufficient
reason not to use it here.

[Yes I know { } doesn't denote a set. I tried it. I don't
know how to denote a set ... ]

>--
>Steven

Groetjes Albert.

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst




More information about the Python-list mailing list