Thanks Alan,

The functions do not share variables, I don't use global vars, and I
don't need a new instance.
So in my case the only use of a class would be that all related usb
code will be grouped together, even though I do not need any of the
Class special abilities, as far as I understand.

I think I will make a usb class to keep it better organised.

I have attached the module that contains the usb and related code, to
give a better view of what I'm talking, and I would appreciate any
feedback on it.

Thanks,
Rob



On 9/11/06, Alan Gauld <[EMAIL PROTECTED]> wrote:
> Hi Rob,
>
> > For example, I may need to mount the usb storage device at some
> > point
> > in the program.
> > For this end I made the following functions:
> > - usbMount() -> main function.
> > - usbUmount() -> main function.
> > - usbMounted() -> help function. Checks if usb already mounted.
> > - usbConnected() -> help function. Checks id usb connected to
> > computer.
> > - usbValid() -> help function. Checks if usb contains certain info
> > (only these may be mounted).
> > The help functions are called from the main functions.
> > So I have multiple help functions, while only two are actively
> > called.
> >
> > What is a good way to keep this organised?
> > - Just put it in a usb.py module?
>
> Thats a very good place to start.
>
> > - Should I make a class?
>
> I think, without seeing the internals of the code, that this is
> likely to be a good idea in this case. If you have a number of
> shared global variables between functions then I'd certainly
> say yes.
>
> > Are there any advantages if I put this in a class, instead of in a
> > module?
>
> The advantage of a class is that if you ever need more than
> one USB device mounted then the instances of the class can
> each hold their own state information, whereas with global
> variables you would be limited to one mounted instance
> - unless you stuck very rigorously to functional programming
> principles...
>
> > This is only a small example, but I run into the same problem with
> > other parts of my program, that are larger, and where the functions
> > also depend on each other, while only a few are called (and the rest
> > just clutter my view in the IDE).
>
> Where things depend on each other a module is the minimum
> organising device. Where functions share data a class is usually
> a good idea on top of that.
>
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to