Idea: Python Shorthand (was Re: Why a class when there will only be one instance?

Peter Otten __peter__ at web.de
Thu May 27 03:36:18 EDT 2004


Ville Vainio wrote:

>>>>>> "Ryan" == Ryan Paul <segphault at sbcglobal.net> writes:
> 
> Ryan> the line. It's a good OO strategy. I do understand your
> Ryan> dislike of 'self'.  It does seem like clutter. In my code, I
> Ryan> shorten it to 's'. In ruby, class variables are prefixed
> Ryan> with an '@', which makes them easier to discern in code, and
> Ryan> it is easier than typing 'self'. I wish python had something
> 
> Prefixing names with symbols like $ and @ is a great idea - it makes
> the "nouns" (variables) stand out from "verbs", and makes the code
> flow like a natural language, making reading it easy and writing it
> fun!

As a preliminary measure you might want to apply the following patch:

*** this.py     2002-02-08 21:41:34.000000000 +0100
--- $this.py    2004-05-27 09:34:01.000000000 +0200
***************
*** 18,24 ****
  Nygubhtu arire vf bsgra orggre guna *evtug* abj.
  Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.
  Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
! Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!"""

  d = {}
  for c in (65, 97):
--- 18,24 ----
  Nygubhtu arire vf bsgra orggre guna *evtug* abj.
  Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.
  Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
! $Flzoby $cersvkrf @ner &bar !@ubaxvat &terng $vqrn -- /yrg'f @qb &!zber
&bs $gubfr!"""

  d = {}
  for c in (65, 97):

As you can see I didn't find the proposed distinction between nouns and
verbs always convenient. A little randomness immediately leads the eye to
the really unimportant stuff - just like the ugly new hat of a friend you
haven't seen for some time. 
Yet another case where practicality beats purity :-)

Peter




More information about the Python-list mailing list