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
  • PrintPrint
Share this Page URL
Help

35. Building Objects Out of Arrays > Arrays Can Prevent Misspellings

Arrays Can Prevent Misspellings

If we were really determined to use hashes, we could do what Graham Barr did to avoid collisions and always put the class name in the keys to avoid ambiguity. So a Child’s email address would be $obj->{CHILD_EMAIL}. This works, but it’s cumber-some and involves a lot of extra typing. Furthermore, deep subclasses will have extremely long keys, such as Person_Worker_Blue_Collar_Construction. The longer the name, the more opportunities there are to misspell it.

People—especially programmers—are lazy. If we want someone to go along with our idea, we have to show him how we can help him save some effort. Our shortened attribute names are simpler to spell. And there’s an added bonus: if our class uses the strict pragma, we’ll be notified at compile time if we misspell a key!


  

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
  • PrintPrint