Ideal way to separate GUI and logic?

asimjalis at gmail.com asimjalis at gmail.com
Mon Jul 15 13:06:30 EDT 2013


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



More information about the Python-list mailing list