Ideal way to separate GUI and logic?
o at owenmarshall.invalid
Tue Jul 16 02:42:34 CEST 2013
On 2013-07-16, fronagzen at gmail.com <fronagzen at gmail.com> wrote:
> On Tuesday, July 16, 2013 1:06:30 AM UTC+8, asim... at gmail.com wrote:
>> fron... at gmail.com wrote:
>> > So as a general idea, I should at the very least separate the GUI
>> > from the program logic by defining the logic as a function,
>> > correct? And the next level of separation is to define the logic as
>> > a class in one or more separate files, and then import it to the
>> > file with the GUI, correct?
>> > My next question is, to what degree should I 'slice' my logic into
>> > functions? How small or how large should one function be, as a rule
>> > of thumb?
>> The way I do this is to write unit tests against the class and the
>> functions (take a look at the unittest module). The functions methods
>> (take a look at the unittest module). Each function should contain
>> the smallest bit of testable logic.
>> Another way to think about this is that each function should contain
>> the smallest piece of logic that you can describe as one action.
>> Asim Jalis
> Again, thanks for all the responses. I'm curious, though, what exactly
> is the rationale for making functions so small? (I've heard that the
> function calling of Python has relatively high overhead?)
Small functions are _always_ encouraged for every language. This is best
practice for everything, not just Python. Has nothing to do with
More information about the Python-list