Game Programming Patterns

Game Programming Patterns By Nystrom, Robert Book – 2014

Programmers will want to read this book. Not just game programmers, but also any programmer. Program structure is important for maintainability of large or medium programs. C++ language programmers will get the most benefit from the book. Other languages are also discussed, and all languages require some attention to structure.

Nystrom’s book is very readable and, perhaps I should add, entertaining. He has a dialogue on the go: the margin notes (his inner critic) are in counterpoint to the main discourse.

He gives credit to the Gang Of Four book (noting that it is 20 years old now,) as a foundation for his proposed new set of patterns.

Dependency Injection

book coverDependency Injection : design patterns using Spring and Guice / Dhanji R. Prasanna, Manning, 2009

Java programmers will find this valuable. 300 pages, contents:

  1. – Dependency injection: what’s all the hype?
  2. – Time for injection
  3. – Investigating DI
  4. – Building modular applications
  5. – Scope: a fresh breath of state
  6. – More use cases in scoping
  7. – From birth to death: object lifecycle
  8. – Managing an object’s behavior
  9. – Best practices in code design
  10. – Integrating with third-party frameworks
  11. – Dependency injection in action!

appendix A – The Butterfly Container
appendix B – Smarty Pants for Adobe Flex

2016 Update: This book is still the only one in OPL with a decent discussion of Dependency Injection. After 7 years! Programmers using the AngularJS framework will want to understand this well, as will programmers of any mid to complex system.

PHP Design Patterns

Learning PHP Design Patterns, William Sanders, O’Reilly 2013

Web programmers will want to read this book, in particular users of PHP.

PHP’s success as a web app language comes largely from its freedom from structure: you can hack code together and do almost anything. But what if your app is large, you don’t want errors, and you want to understand it? Think of Vtiger, which combines (yikes) code from SugarCRM, Smarty, ckeditor, antlr, PearDatabase, adodb, freetag, nusoap, phpmailer, tcpdf, PDFMaker, htmlpurifier, php_writeexcel, kcfinder, log4php, AjaxUpload, HTMLSax3, iCal, qCal, PHPMailer, and Image_Graph projects, not to mention several Javascript libraries. The many subprojects are structured using Object Oriented (OO) concepts, which gives you a hope of understanding it.

To succeed in larger projects you need some structure, and PHP Design Patterns proposes that you use the same high level structures that have been useful to C++ and Java programmers for many years. The author read the ‘Gang of 4’ book (Gamma, Helm, Johnson and Vlissides), and has interpreted it in the PHP context. He starts with a refresher on Object Oriented programming, which will be easy reading for anyone with knowledge of OO. Then he shows how to make best use of the OO features in PHP since version 5, referencing the most useful design patterns. Inheritance, polymorphism, encapsulation are all discussed with example code in php.

Returning to the Vtiger example, when the code uses some OO structure, it is often not clear what pattern is in use. A file should start with comments on what design pattern is being used, and if not, then a discussion of how the objects are used. If the designers had started with the common design patterns from this book, then it would all be more clear.

I want you to read this well written book in the hopes that the next php projects I need to enhance will be well structured and easier to work with. This means you! Why would you not just Google The Fine Thing (GTFT)? Because then you get snowed with poorly edited info. Read the book for a well organized presentation of the few important, common patterns.

Disclaimer: I read the electronic version of the book, on a smartphone. The reading experience is quite different from bound, paper books with pros and cons. Disclaimer 2: I got the book through the O’Reilly blogger program.

If this book interests you, then you might also want to read Javascript patterns By Stoyan Stefanov for a complementary treatment of the client side language.

Unfortunately, the OPL does not have PHP Design Patterns yet. 350 pages.