Book Review: PHP 5 Social Networking

16th book reviewed, this time about how to build a social network with PHP. Relatively big book (540 pages) with tons of code.

The next one or next ones will probably be about Javascript as I seriously need to improve my skills.

Review

PHP 5 Social Networking

Title: PHP 5 Social Networking
Author: Michael Peacock

This book walks chapter by chapter about the process of building a social network, with a structure and features mostly grabbed from Facebook ones (friends, statuses, profiles, events and groups).

It is done from scratch using PHP5 & MySQL, with a custom built lightweight REST-like MVC and a basic templating system (looks like grabbed from PHPBB forums).

The author does a nice selection of design patterns to apply to the architecture, with clear and concise definitions of them, but then the code… starts to get messy.

  • There is almost no OO (sometimes looks as Composition, but in general just looks as non-refactored code). Structuring the code to use a /lib/ folder (ok for helpers) to place Model related code there (and sometimes even with presentation logic) is neither clean nor good.
  • Uses PHP tricks (like func_get_args() ) instead of well defined parameters, how builds the views and templates is not the most flexible way (but at least is clean).
  • Does some ugly but typical PHP developer things, like using 0 instead of NULL/FALSE, modifying function parameters to store temporal data... I disagree with such unproper practices.
  • Classes dont respect much the layers. The controllers have a mess of Model access and DB queries, the authentication component sets template errors (html format included!) and reads POST params…
  • Variable names are sometimes terrible: $pp, $u, $ike... Also there is almost no use of PHP switch statements (why?).
  • DB Queries are unoptimal, apart from doing really expensive paging calculations. Using strings to store DB dates is really ugly, and forces to use LIKE statements which are costly in processing time.
  • Doing DB queries on class constructors ins one of the ugliest and worst things you can do, because so many things can fail.
  • Proposed erorr handling is pretty weak and even unsafe in some parts (at least could break the site).

That said, almost all the code is explained (sometimes even line by line), perfect for reading instead of paragraphs and then big chunks of code.

Has some mentions to CAPTCHA systems, importing contacts/friends from other networks, and other interesting features (but no actual code is provided).

In the later chapters, builds a proof of concept of a REST-like API, unversioned and tightly coupled with the website. The book then ends with a quick pass about some pretty basic hosting, SEO, monetization and growth/scaling.

The code can be more or less easily ported to other languages, and the foundations are not bad for a typical low-scale web project, but if you plan for a medium size, you will need to do some serious refactoring and cleaning to the code.

Not bad for beggining into the social networks development segment, but if you have experience on them this book will be too basic and without any advanced technique.

Posted by Kartones on 2011-02-27

Comments?

Share via: Twitter Linkedin Google+ Facebook