Chapter 6. Modular Programming: Keeping things straight

image with no caption

The code that you write will make its way into many programs.

And, although sharing is good, you need to be careful. One programmer might take your code and use it in an unexpected way, while another might change it without even letting you know. You might want to use one function in all your programs and, over time, that function’s code might change to suit your needs. Smart programmers take advantage of modular programming techniques to keep their workload manageable. Let’s find out how in the pages that follow...

Head First Health Club is upgrading some systems

Head First Health Club has a new CEO, and he loves new technology. He was shocked when he saw how old the sales systems were.

image with no caption

A point-of-sale (POS) system is just a computer program that works like a cash register. The boss doesn’t want to replace all of the cash registers immediately. He wants to begin with a trial system in the coffee bar.

Note

It would be nice if the systems you produce were modular in design. You’ll get to that AFTER you’ve spent some time understanding what’s required.

Let’s see what the coffee bar POS needs to do.

The program needs to create a transaction file

The POS program will record credit card sales in a file called transactions.txt. At the end of ...

Get Head First Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.