Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

2.7. Functions

One problem you'll inevitably encounter when programming is code duplication. Sometimes it's because of the sheer quantity of code; other times it's the result of a lazy programmer. Either way, code duplication can cause a whole world of pain if not dealt with; from simply wasting your time creating it all, to completely ruining your day because you've got to edit 50 different lines of the same code.

Now, anyone with their head screwed on is probably wondering why you would ever duplicate code. What's the point? The simple answer is that some pieces of code will be used over and over again because you want to perform a similar action multiple times. For example, a piece of code that lets you output a full name by combining a first name and last name:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint