Python complaints

James Logajan JamesL at Lugoj.Com
Thu Nov 25 00:25:09 EST 1999


Gareth McCaughan wrote:
>   - if/then/else works on *statements* (strictly, suites of
>     statements) rather than on *expressions*, so I can't
>     say
>       print "You scored %s point%s" % (score, if score==1 then "" else "s")
>     or anything like that. (Or, as some people prefer to put it,
>     Python has no ? : operator.)

Thanks to Python's dynamic typing you can easily add the C "?:" expression
to the language by defining a single function that will work with all types:

def ifexp(cond, trueVal, falseVal):
   if cond:
      return trueVal
   else:
      return falseVal

print "You scored %s point%s" % (score, ifexp(score == 1, "", "s"))

Note that you'd have to define a whole set of these functions in a
statically typed language, one for each type of the Vals.

>   - Memory management is by refcounting instead of GC. This
>     has its good points (it means that one can define more
>     precisely when e.g. finalisation happens), but it does
>     mean that if you build structures with cycles in the
>     reference graph then they won't get GCed when you want
>     them to. This is a real nuisance, for instance, when
>     you're exploring ideas or debugging: suppose you have
>     a piece of code that builds a big data structure out of
>     class instances; then every time you make a small change
>     and run it again (you have to run it again, because
>     existing instances belong to the old versions of the
>     classes) you can be leaking a lot of memory.

Sorry, but I think the price paid for "true" GC is too high for the small
number of programs that benefit from this. Perhaps one should learn to clean
up after oneself when cycles are expected.




More information about the Python-list mailing list