Title: Book Review: PHP 5 Social Networking
Slug: book-review-php-5-social-networking
Date: 2011-02-27 09:59:00
Author: Kartones
Lang: en
Tags: Social Networks, Books, Reviews, PHP, MySQL
og_image: https://images.kartones.net/posts/screenshots/book_php_social_networking.jpg
Description: A review of the book 'PHP 5 Social Networking', by Michael Peacock.

<p>Another book reviewed, this time about how to build a social network with PHP. Relatively big book (540 pages) with tons of code.</p>
<p>The next one or next ones will probably be about Javascript as I seriously need to improve my skills.</p>

<p>Note: Free evaluation copy provided by the publisher.</p>

<h3>Review</h3>

<p><img alt="PHP 5 Social Networking" src="https://images.kartones.net/posts/screenshots/book_php_social_networking.jpg"></p>

<p>
<b>Title</b>: <a href="https://www.packtpub.com/eu/web-development/php-5-social-networking">PHP 5 Social Networking</a><br>
<b>Author</b>: Michael Peacock</p>

<p>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).
</p>

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

<p>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.
</p>

<ul>
<li>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.</li>

<li>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).</li>

<li>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.</li>

<li>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…</li>

<li>Variable names are sometimes terrible: $pp, $u, $ike... Also there is almost
no use of PHP switch statements (why?). </li>

<li>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.</li>

<li>Doing DB queries on class constructors ins one of the ugliest and worst
things you can do, because so many things can fail.</li>

<li>Proposed erorr handling is pretty weak and even unsafe in some parts (at
least could break the site).</li>
</ul>

<p>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.
</p>

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

<p>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.
</p>

<p>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.
</p>

<p>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.</p>