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

diliup gabadamudalige diliupg at gmail.com
Sun Jun 15 06:56:57 CEST 2014


Thank you very much Allan! 100% clear.
I thank each and every one of you who contributed to all my question on the
above subject.
A lot of things became very clear.
May you all be well.



On Sun, Jun 15, 2014 at 3:15 AM, Alan Gauld <alan.gauld at btinternet.com>
wrote:

> On 14/06/14 13:53, diliup gabadamudalige wrote:
>
>  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?
>>
>
> You can but it should also have the functions that operate on the data
> too. Thats the point of classes they link function and data together
> so you don't need to pass lots of parameters around. If you have a class
> that jusat holds lots of disparate data items you might as well just use a
> list/tuple or dictionary. The value of classes is when you add behaviour or
> methods to the mix.
>
>
>
>  I thought on the lines of blood carrying various things to different
>> organs in the body.
>>
>
> But even there the blood has a distinct set of related items, it doesn't
> carry the food to your stomach or the video signals from
> your eye to your brain. And blood has operations - it can flow,
> coagulate, increase/decrease red-cell count etc. It has
> behaviour as well as data.
>
>
>  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 that could be a Tune... And it might have record/play/pause operations
>
>
>
>  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.
>>
>
> But that could be a method of the Tune sub-class, MidiTune, which knows
> how to record from a MidiSequencer object.
>
>
>  This is how I have used these variables, lists and strings in this
>> program. So far it has run error free.
>>
>
> The issue is not how to make it run - you can do that in assembler.
> The issue is how easy is it to read and how easy os it to modify and fix
> later. 80% of the cost of commercial software is in "maintenance"
> The goal of professional software engineers is to reduce maintenance
> costs even if that increases the initial 20% development budget.
>
>
>  Is this not correct or bad design. I know it is not the normal way of
>> using class but is it wrong?
>>
>
> Almost certainly, because it adds a layer of complexity for little or no
> gain.
>
> Whereas adding the methods to the class improves the maintainability and
> readability (and sometimes the performance, although that's a secondary
> benefit).
>
> HTH
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
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/20140615/5453331d/attachment-0001.html>


More information about the Tutor mailing list