Page 13 -
P. 13

table of contents


                                     functions
                            3        Let’s get organized



                                     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!                                78
                                             What does the new program need to do?                    79
                                             Don’t duplicate your code...                             81
                                             Reuse code with functions                                82
                                             Always get things in the right order                     84
                                             Return data with the return command                      87
                                             Use the Web, Luke                                        93
                                             The function always sends the same message               94
                                             Use parameters to avoid duplicating functions            96
                                             Someone decided to mess with your code                   102
                                             The rest of the program can’t see the password variable      104
                                             When you call a function, the computer creates a fresh list of variables   105
                                             When you leave a function, its variables get thrown away      106
                                             Starbuzz is fully stocked!                               110
                                             Your Programming Toolbox                                 111


















           xii
   8   9   10   11   12   13   14   15   16   17   18