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 heavily on callbacks, to the point where I'm starting to recognize that callback laden code in other contexts was probably written by a (former?) graphics programmer :) 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 program, waiting for somebody to move a mouse and click it is a slow, infrequent, and unpredictable event, so you set up callbacks which are invoked when one of those events happens, and in the meantime you can either do other productive work, or do nothing at all (let other programs on the computer do work). I'm finding it hard to imagine tkinter without them... >>> - if you can't, encapsulate it in classes. >> >> I think it's important that you say "classes", not "class". As with >> functions three small dedicated classes are much better than one big know- >> it-all/do-it-all class. > > I try to keep this in mind. Another thing I'm currently struggling > with is when to use inheritance vs. separate, independent classes. or when to use a class that contains an instance of another class... It ought to feel natural... there's a lot in common, but we want to do a little bit of specialization, that's a decent case for inheritance. So they claim. Except the examples are always so simplistic in the literature: write a class called Human, then specialize it into Man and Woman to deal with gender differences. Sure. And as recent political kerfuffles have highlighted, what about an instance that is not clearly one or the other? What about all those pesky little details that are not as simple as "has two arms" that are never part of the "real world" models, but are very much part of the programming environment when you go to implement something? Inheritance describes a relationship - "is a". a Volvo is-a Car. A Checking Account is-a Bank Account. If you can't make that feel natural, then it's probably not the right model. (my opinions only) _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor