[Tutor] global variables/constants versus volatile variables/constants

diliup gabadamudalige diliupg at gmail.com
Sat Jun 14 14:53:08 CEST 2014


Thank you all for those great clarifications. I learnt a lot from these.
My roots in programming are from the early 80s and with a gap of nearly 30
years till I restarted again last year in March with Python. :) So some of
the new concepts like classes are a bit alien to me but I am catching on.
I made a mistake by using the word variables on variables and constants
both. My design structure would most probably be quite unconventional to
most like Allen Gauld says. I am still learning and I like to jump into the
deep end and learn to swim there and so far have managed to stay alive! :)
I have gained immensely from these few emails and hope I can gain more
knowledge to write better code.

Say if I have a lot of Lists, strings and variables used to carry data to
and from various functions why can't I have a class with all these in it? I
thought on the lines of blood carrying various things to different organs
in the body. One common container class. Containers for data exchange
between all classes and functions.
so I declare

class Containers():
    def __init__(self):
self.last_selected_scale= ""
self.scale_notes = ""
self.arpeggionotes = ""
self.handplayed_notes = []
self.MIDIscale = []  # the MIDI scale to be played is here
self.play_MIDIscale = False
self.play_MIDIarpeggio = False
self.play_MIDI_scale_note = False
self.play_MIDI_arpeggio_note = False
self.MIDInote_inscale = 0

now i initiate the class with
v=Containers()

now say if I play the MIDI keyboard, I collect the notes played which will
be appended to the list v.hanplayednotes. This will be done from a function
which will scan the keyboard and append played notes to that list.

This is how I have used these variables, lists and strings in this program.
So far it has run error free.

Is this not correct or bad design. I know it is not the normal way of using
class but is it wrong?

Thank you all in advance.


-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**********************************************************************************************
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**********************************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140614/86318afd/attachment.html>


More information about the Tutor mailing list