On 15/04/17 03:38, Alex Kleider wrote: >> Whatever he does he will need to separate his UI from his >> logic - a good programming skill regardless of UI. > > Can anyone suggest a good tutorial that explains exactly what this means > and how to achieve it? > (separate UI from logic I mean.)
I don't know of a tutorial as such but the principles are enshrined in the Model-View-Controller (MVC) design pattern and there are lots of articles and tutorials on that. One caveat is that there are almost as many variations on MVC as there are articles so you can expect some contradiction in the details. That's ok, just focus on the big ideas. At the most basic just do as I suggested in the post. Identify the functions that do the work(the logic) and make sure they take all of their input via parameters and deliver a result back to the caller with no UI (eg input() or print()) statements inside the function. Then write the code that interacts with the user as a separate function which calls the logic functions as needed. You should be able to put the core functions into a separate module and import that into the UI module/main program. That's quite a good check that you have made your logic reusable. This is good practice for all programming projects but its essential for GUI and Web projects. Finally, if you can find a copy of my recent book "Python Projects" there is a rolling project within that which demonstrates how the same logic code can be used to build a CLI, a GUI and a Web app. [ In fact it goes even further by demonstrating how to break an app into 3 tiers - data, logic and UI - which is industry best practice, but usually overkill for small projects.] -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor