[IPython-dev] Re: Changes to Notebook Format

Fernando Perez Fernando.Perez at colorado.edu
Fri Jul 22 13:42:42 CDT 2005


Toni Alatalo wrote:

> BTW, if i may suggest a style issue: the nbshell code seems to include 
> 'getters' that would be naturally properties in current Python (they 
> came already in 2.2 so no version prob.), e.g. these in PythonPluginFactory:
> 
>    def GetString(self):
>         """ Returns the type string of the plugin. This is used when a 
> notebook
>         file is loaded. See notebookformat.txt for more info"""
>         return "python"
>    
>     def GetType(self):
>         """ Returns the way data should be passed to the plugin. Currently
>         supported types are "raw" and "encoded". See notebookformat.txt for
>         more info"""
>         return "raw" #Probably only the python code plugin should be raw
> 
> those are currently unnecessary, but could be just .string and .type (or 
> perhaps .type and .input_type?). then later if they need to wrapped to 
> some method just make them properties ( 
> http://www.python.org/2.2/descrintro.html#property ).

+1 on properties.  I _hate_ code littered with getX/setX everywhere.  This is 
not Java.  I've been convinced to use XML, but that's about as far as you'll 
get me to go ;)

In fact, make X a regular attribute unless it really requires extra 
validation, synchronization, or work to read/write.  But none of this, please:

def getX(self):
   return _X

If that's all we need, then X can just be read as foo.X, set as foo.X='bar', 
and we're done.  As Guido likes to say, python is a language for adults :)  If 
in the future things evolve to the point where X needs fancier access 
controls, it can be turned into a property, and user code (which still 
respects the validation constraints) will be unaffected.

Cheers,

f




More information about the IPython-dev mailing list