Creating your blueprint

This chapter covers

■ Refactoring and how it improves code

■ Separating the Model and View

■ Unit testing a GUI program

■ Testing user events

GUI code has a reputation for being hard to read, hard to maintain, and always looking like spaghetti—long, stringy, and tangled. One prominent Python GUI module (not written with wxPython) includes this note in its comments: "Why is it that GUI code always ends up looking a mess, despite all the best intentions to keep it tidy?" It doesn't have to be that way. There's no particular reason why UI code has to be any harder to write or manage than any other part of your program. In this chapter we'll discuss three techniques for taming your UI code. Since layout code is particularly susceptible to poor structure, we'll discuss refactoring the code to make it easier to read, manage, and maintain. Another area where a UI programmer can get tied into knots is the interaction between the display code and the underlying business objects. The Model/View/Controller (MVC) design pattern is a structure for keeping display and data separate to allow each to change without affecting the other. Finally, we'll discuss techniques for unit testing your wxPython code. Although all the examples in this chapter will use wxPython, many of the principles are applicable to any UI toolkit—although the Python language and wxPython toolkit make some techniques particularly elegant. The design and architecture of your code is the blueprint of your system. A well thought out blueprint will make your application simpler to build and easier to maintain. The suggestions in this chapter will help you design a solid blueprint for your program.

Was this article helpful?

0 0

Post a comment