O'Reilly logo

Head First Programming by Paul Barry, David Griffiths

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Functions: Let’s get organized

image with no caption

As programs grow, the code often becomes more complex.

And complex code can be hard to read, and even harder to maintain. One way of managing this complexity is to create functions. Functions are snippets of code that you use as needed from within your program. They allow you to separate out common actions, and this means that they make your code easier to read and easier to maintain. In this chapter, you’ll discover how a little function knowledge can make your coding life a whole lot easier.

Starbuzz is out of beans!

The Starbuzz buyers love the program you created in the last chapter. Thanks to your efforts, the Starbuzz CEO is only buying coffee beans when the price drops below $4.74, and his organization is saving money as a result.

But, now there’s a problem: some Starbuzz outlets have run out of beans.

image with no caption

When the coffee beans start to run low in an outlet, the Starbuzz baristas need to be able to send an emergency order to the CEO. The outlets need some way of immediately requesting the purchase of coffee beans at the current price, regardless of what that price is. They also need the option of waiting for the best price, too, just like in the current program.

The program needs an extra option.

What does the new program need to do?

The new program ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required