Being an effective programmer

Now that you have seen just how useful modular programming techniques are, you might wonder why anyone would not want to use them. Other than a lack of understanding, why would a programmer eschew modular principles and techniques?

The Python language has been designed from the ground up to support good modular programming techniques, and with the addition of excellent tools such as the Python Standard Library, unit tests, and docstrings, it encourages you to apply these techniques to your everyday programming practice. Similarly, the use of indentation to define the structure of your code automatically encourages you to write well-formatted source code where the indentation of your code reflects the logical organization of your program. These are not random choices: Python encourages good programming practices every step of the way.

Of course, just like you can write poorly structured and incomprehensible spaghetti code using Python, it is possible to avoid using modular techniques and practices while developing your programs. But why would you want to?

Programmers sometimes take shortcuts when writing programs that they consider to be "throwaway" code. For example, perhaps you're writing a tiny program that you expect to only use once, and then never need to use again. Why take the extra time to apply the recommended modular programming practices to this throwaway program?

The thing is, throwaway code has a funny habit of becoming permanent and growing into something much larger. Often, what begins as throwaway code becomes the basis for a large and complex system. Code you wrote six months ago can be found and reused in a new program. In the end, you never know what is throwaway code and what isn't.

For these reasons, it is a good idea to always apply modular programming practices to your code, no matter how large or small it might be. While you won't want to spend a lot of time writing extensive docstrings and unit tests for a simple throwaway script, you can still apply basic modular techniques to help keep your code organized. Don't just save modular programming techniques for your "big" projects.

Fortunately, the way Python has implemented modular programming makes it extremely easy to use, and after a while, you begin to think in modular terms before you even start writing a single line of code. I believe this is a good thing, because modular programming techniques are an essential part of being a good programmer, and you should practice these techniques whenever you sit down to program.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.144.228