Re: [Tutor] When to use classes

2017-08-22 Thread Neil Cerutti
On 2017-08-19, Cameron Simpson wrote: > Personally, I do this a lot. It does cost some time, but it > also has advantages. You get to explore the problem space from > the point of view of your own needs, and you get insight into > the costs/benefits of various ways of doing

Re: [Tutor] When to use classes

2017-08-22 Thread Alan Gauld via Tutor
On 20/08/17 02:08, Steven D'Aprano wrote: > Raymond Hettinger has a good video presentation about the use of classes > and inheritance for delegating work. (That is not to be confused with > delegation as an alternative to inheritance.) No, but I think it would have been useful if he had made

Re: [Tutor] When to use classes

2017-08-20 Thread boB Stepp
On Sat, Aug 19, 2017 at 8:08 PM, Steven D'Aprano wrote: > The Art of Subclassing > > http://www.youtube.com/watch?v=miGolgp9xq8 > > If its the one which starts off with him talking about his newly born > child, it is the one. This is indeed the "one"! > The traditional

Re: [Tutor] When to use classes

2017-08-20 Thread Jim
On 08/20/2017 03:12 AM, Alan Gauld via Tutor wrote: On 20/08/17 02:47, Steven D'Aprano wrote: since then feels like going back to the Dark Ages. Having to care about low-level details like creating buttons, installing callbacks and so forth just feels wrong. To be fair most GUI frameworks

Re: [Tutor] When to use classes

2017-08-20 Thread Alan Gauld via Tutor
On 20/08/17 02:47, Steven D'Aprano wrote: > since then feels like going back to the Dark Ages. Having to care about > low-level details like creating buttons, installing callbacks and so > forth just feels wrong. To be fair most GUI frameworks come with a GUI builder that remove the manual

Re: [Tutor] When to use classes

2017-08-19 Thread Steven D'Aprano
On Sat, Aug 19, 2017 at 11:34:10AM -0600, Mats Wichmann wrote: > It makes some sense though; computational code just goes ahead and > computes. In the graphical UI world, interesting things happen when an > event you can't exactly plan for takes place. From the point of view of > a computer

Re: [Tutor] When to use classes

2017-08-19 Thread Steven D'Aprano
On Sat, Aug 19, 2017 at 11:00:51AM -0500, boB Stepp wrote: > I try to keep this in mind. Another thing I'm currently struggling > with is when to use inheritance vs. separate, independent classes. Raymond Hettinger has a good video presentation about the use of classes and inheritance for

Re: [Tutor] When to use classes

2017-08-19 Thread Steven D'Aprano
On Sat, Aug 19, 2017 at 10:52:45AM -0500, boB Stepp wrote: > This thought had occurred to me. Sometimes I wish there was a > mechanism in Python to create a binding to data where both were > unchangeable/immutable. Yes, I could use an immutable data type, but > if I bind an identifier to it

Re: [Tutor] When to use classes

2017-08-19 Thread Cameron Simpson
On 19Aug2017 11:00, boB Stepp wrote: On Sat, Aug 19, 2017 at 4:04 AM, Peter Otten <__pete...@web.de> wrote: [...] The lesson is that Python already provides some powerful ready-to-use classes that take you a long way without having to write your own custom classes.

Re: [Tutor] When to use classes

2017-08-19 Thread Alan Gauld via Tutor
On 19/08/17 17:00, boB Stepp wrote: > I try to keep this in mind. Another thing I'm currently struggling > with is when to use inheritance vs. separate, independent classes. The golden rule is if the child is not a kind-of the parent then it should be delegation not inheritance. Never use

Re: [Tutor] When to use classes

2017-08-19 Thread Alan Gauld via Tutor
On 19/08/17 10:04, Peter Otten wrote: > nicer interface. Nobody would want to write > > a + b * c > > as > > add(a, mul(b, c)) Unless they program in Lisp perhaps :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow

Re: [Tutor] When to use classes

2017-08-19 Thread Mats Wichmann
On 08/19/2017 10:00 AM, boB Stepp wrote: >> (That was easy; but I wonder what tkinter would look like without >> callbacks...) > > I wish I knew more so that I could fully wonder about this myself. > You might even be making a clever joke and I am clueless. All graphics frameworks depend

Re: [Tutor] When to use classes

2017-08-19 Thread boB Stepp
On Sat, Aug 19, 2017 at 4:04 AM, Peter Otten <__pete...@web.de> wrote: > Steven D'Aprano wrote: > >> Mostly for Bob, but also for anyone else interested: >> >> When To Use Classes >> >> http://kentsjohnson.com/stories/00014.html > > Just a minor nit, but you don't even need a custom function for

Re: [Tutor] When to use classes

2017-08-19 Thread boB Stepp
On Sat, Aug 19, 2017 at 3:07 AM, Alan Gauld via Tutor wrote: > On 19/08/17 08:52, Alan Gauld via Tutor wrote: > > Following up my own post - a sure sign of failure to communicate :-( > >> On 19/08/17 05:26, boB Stepp wrote: >> >>> related methods needs to share the same values

Re: [Tutor] When to use classes

2017-08-19 Thread Peter Otten
Steven D'Aprano wrote: > Mostly for Bob, but also for anyone else interested: > > When To Use Classes > > http://kentsjohnson.com/stories/00014.html Just a minor nit, but you don't even need a custom function for the callback result = [] db.query(sql, result.append) The lesson is that Python

Re: [Tutor] When to use classes

2017-08-19 Thread Alan Gauld via Tutor
On 19/08/17 08:52, Alan Gauld via Tutor wrote: Following up my own post - a sure sign of failure to communicate :-( > On 19/08/17 05:26, boB Stepp wrote: > >> related methods needs to share the same values and a class would tidy >> this up nicely without the need for any globals > Indeed, but

Re: [Tutor] When to use classes

2017-08-19 Thread Alan Gauld via Tutor
On 19/08/17 05:26, boB Stepp wrote: > related methods needs to share the same values and a class would tidy > this up nicely without the need for any globals or needless passing of > the exact same values around as parameters/arguments. Indeed, but its important to remember that class attributes

Re: [Tutor] When to use classes

2017-08-18 Thread boB Stepp
On Fri, Aug 18, 2017 at 9:56 PM, Steven D'Aprano wrote: > Mostly for Bob, but also for anyone else interested: I guess I'm the "Bob" being referred to. > When To Use Classes > > http://kentsjohnson.com/stories/00014.html > > > He says: > > You may have several functions

[Tutor] When to use classes

2017-08-18 Thread Steven D'Aprano
Mostly for Bob, but also for anyone else interested: When To Use Classes http://kentsjohnson.com/stories/00014.html He says: You may have several functions that use the same state variables, either reading or writing them. You are passing a lot of parameters around. You have

Re: [Tutor] When to use classes

2014-04-10 Thread Ni hung
Thank you Alan, Dave and Cameron (and folks managing this email group)! Your replies were very helpful. Regards ni On Wed, Apr 9, 2014 at 4:25 AM, Cameron Simpson c...@zip.com.au wrote: On 08Apr2014 22:58, Ni hung niih...@gmail.com wrote: I am learning programming using python. I think of

[Tutor] When to use classes

2014-04-09 Thread Ni hung
Hi I am learning programming using python. I think of solving a problem using functions and for this reason all/most of my code consists of functions and no classes. I have some understanding of classes/Object Oriented Programming. I can write simple classes but I do not understand when to use

Re: [Tutor] When to use classes

2014-04-09 Thread Alan Gauld
On 09/04/14 06:58, Ni hung wrote: functions and no classes. I have some understanding of classes/Object Oriented Programming. I can write simple classes but I do not understand when to use classes. If you are just learning it may be that the programs you have written are too small to make

Re: [Tutor] When to use classes

2014-04-09 Thread Dave Angel
Ni hung niih...@gmail.com Wrote in message: (Please post in text format, not html. It doesn't matter for your particular message, but several things can go wrong, where some or most of us do not see what you meant to post) I am learning programming using python. I think of solving a

Re: [Tutor] When to use classes

2014-04-09 Thread Cameron Simpson
On 08Apr2014 22:58, Ni hung niih...@gmail.com wrote: I am learning programming using python. I think of solving a problem using functions and for this reason all/most of my code consists of functions and no classes. I have some understanding of classes/Object Oriented Programming. I can write