Code Reuse & Modularity in Python

Code Reuse & Modularity in Python#

We’ve previously been introduced to the concept of code blocks. From Busbee and Braunschweig’s “Code Blocks” from Programming Fundamentals:

  • “A code block, sometimes referred to as a compound statement, is a lexical structure of source code which is grouped together. Blocks consist of one or more declarations and statements. A programming language that permits the creation of blocks, including blocks nested within other blocks, is called a block-structured programming language. Blocks are fundamental to structured programming, where control structures are formed from blocks.”

Approaching a program as a series of components that each accomplish tasks that are part of the larger workflow gets us to a new concept: modularity or modular programming

From Busbee and Braunschweig’s “Modular Programming,” in Programming Fundamentals:

  • “Modular programming is a software design technique that emphasizes separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality.”

Code blocks are one way to think about these discrete parts of a program. A more precise term used in programming languages is function. “Functions are important because they allow us to take large complicated programs and to divide them into smaller manageable pieces. Because the function is a smaller piece of the overall program, we can concentrate on what we want it to do and test it to make sure it works properly” (Busbee and Braunschweig, Modular Programming).

Acknowledgements#

When building this chapter, the author consulted materials developed by:

Definitions and explanations in this chapter are adapted from Kenneth Leroy Busbee and Dave Braunschweig, Programming Fundamentals: A Modular Structured Approach, 2nd Edition (Rebus Press, 2018)

Chapter Contents#

Application#

Your answers to this chapter’s application questions should be added to the notebook template.

Submit the Colab link on Canvas for the assignment submission.