A small suggestion for Python

Emile van Sebille emile at fenx.com
Fri Jan 12 12:30:29 EST 2001


This follows the explicit is better than implicit concept,
so outside of adding a keyword and breaking backward
compatibility (bad things), this is probably a good thing
;-).

If such a thing were to be added, might it also be
good to raise an exception when not assigning the return
value?   If so, perhaps a nothing would not object to being
a sink hole (ala /dev/null).

---
class test:
  def mysort(self):
    "method w/o return"
  def retval(self):
    return "retval"

def retval():
  return "retval"

def mysort():
  "function w/o return"
---
y = test()
y.mysort()       # ok
??? = y.mysort() # fails
??? = y.retval() # ok
mysort()         # ok
??? = mysort()   # fails
??? = retval()   # ok

not-holding-my-breathe-le y'rs

--

Emile van Sebille
emile at fenx.com
-------------------


"Edward C. Jones" <edcjones at erols.com> wrote in message
news:3A5F27F7.30268D9A at erols.com...
> I have been programming in Python for several years. I
still
> occasionally make mistakes with functions (such as sort)
that
> return only "None". I suggest that functions like sort
should
> return either "Nothing" or nothing. "Nothing" would be
exactly
> like "None" except it can't be assigned. Whether "Nothing"
or
> nothing is used, the statement "x= y.sort()" would raise a
> run-time Exception.
>
> Thanks,
> Ed Jones
>
>







More information about the Python-list mailing list