[Python-ideas] why not try without except?
spir
denis.spir at free.fr
Sun Apr 26 11:52:40 CEST 2009
Le Sun, 26 Apr 2009 19:05:01 +1000,
Steven D'Aprano <steve at pearwood.info> s'exprima ainsi:
> On Sun, 26 Apr 2009 06:51:08 pm spir wrote:
>
> > Now I realise that what I miss is a kind of handy, clear, and not
> > misuseable idiom for coping with undefined
> > variables/attributes/parameters.
>
> The best way to deal with undefined variables is to make sure that there
> never are any. In other words: an undefined variable is a bug. Fix the
> bug, don't hide it.
I understand your position, indeed.
Mine is: optional things and optional actions are basic and common notions. Even more in modelizing / programming fields. Are they important enough (for you) to require a dedicated idiom in a (your favorite) PL?
class Shape(object):
def __init__(self, ..., ?fill_color)
.......
?self.fill_color = fill_color
def show(self):
.......
?self.fill(self.fill_color)
Moreover, imagine NoReturnValueError instead of None; raised by python when a func call is used as an expression.
x = f() # may raise NoReturnValueError
# will never bind None except explicitely returned
This would first avoid numerous bugs, often difficult to catch because silent:
y = x.sort() # awa!
(*) (**)
Also one could then write, for instance:
def show(self):
.......
?self.fill(self.fill_color)
?self.showTansforms(user.getTransforms())
(if NoReturnValueError belongs to the set of error types caught by optional actions)
OK, won't fight for this anyway ;-)
denis
(*) I would also love a way to prevent the opposite bug:
s.strip() # awa!
(**) Actually, I must be a fan of Pascal's procedure vs function distinction. Find it sensible and meaningful.
------
la vita e estrany
More information about the Python-ideas
mailing list