Archive for May, 2008

Book review; “UML 2.0 in Action: A project-based tutorial”

Monday, May 26th, 2008

A while ago I received, from packt, a copy of “UML 2.0 in Action: A project-based tutorial” by Patrick Grassle, Philippe Baumann, Henriette Baumann. This book certainly lives up to it’s byline of being “a detailed and practical walk-through showing how to apply UML to real world development projects”.

UML is a standardized visual specification language for object modeling and is short for “Unified Modeling Language” that includes a graphical notation used to create an abstract model of a system, referred to as a UML model. There are many software tools available which can be used for code generation and reverse engineering, such as the new PEAR package PHP_UML which generates a UML representation of existing PHP source code.

This book assumes no prior knowledge of UML and this works very well. It is by no means comprehensive but that it’s what the authors set out to write – this book is focused on being a practical tutorial for learning the essentials of modelling business systems, IT systems and systems integration – no more, no less. It does this admirably and I’ll recommend this book as a reference and introduction for developers performing system analysis and design activities.

Validation in Depth – a retort to using just regular expressions

Monday, May 26th, 2008

I’ve noticed that Richard Heyes, who professes himself to be a php guru, deleted my comment on his “Some common regular expressions” posting which simply pointed out his expressions didn’t quite do the job and suggested a few PEAR packages that should be used instead of the expressions that he proffered for the following:

  • Email addresses
  • Usernames
  • Telephone numbers
  • Postal codes
  • IP addresses
  • An SQL date
  • A domain
  • A UK sort code

Why he deleted it is anybody’s guess – he deleted a few others too.

Anyway, for the record I thought I’d reproduce my comment from memory (I didn’t think to make a backup copy for obvious reasons but hey nobody expects the Spanish Inquisition).

The problem with just relying on a regular expression for validating data is there is no “defense in depth” to that solution. Sure the expression might catch the main bulk of data entered but there’s always going to be data that get’s through.

For example a simple regular expression for validating phone numbers won’t catch area codes or country that don’t actually exist and another that’s used for validating entered dates might not catch leap-year based exceptions.

  • Email addresses – use the PEAR Validate package for email address validation
  • Usernames
  • Telephone numbers – use Validate_UK; this package will also validate UK specific details such as:
    • SSN (National Insurance/IN)
    • Postal Code
    • Sort Code
    • Bank AC
    • Car registration numbers
    • Passports
    • Driver license
  • Postal codes – use Validate_UK or counterpart as appropriate.
  • IP addresses – use the Net_Check PHP5 port of Net_CheckIP or the original Net_CheckIP for php4 if you really have to.
  • An SQL date – what Richard provided validates the form of a date in yyyy-mm-dd format but not that the entered value is a date; one could enter 2008-13-42. Again, I’d suggest using the Validate package.
  • A domain – You could, in theory use the Validate package’s uri method, prefixing the domain with ‘http://’.
  • A UK sort code – Validate_UK.
  • If you follow these suggestions it should make your input validation more robust than simply relying on regular expressions and nothing more.

    Book review: “Mastering phpMyAdmin 2.11 for Effective MySQL Management” by Marc Delisle

    Monday, May 12th, 2008

    Mastering phpMyAdmin 2.11 for Effective MySQL Management” by Marc Delisle

    This book on phpMyAdmin is written by Marc Delisle, one of the core developers of the application which I think just about any software developer utilising MySQL has dabbled with at the least. I can honestly say that anyone that experimented with phpMyAdmin before reading this book will use it much more thoroughly and more productively afterwards.

    This is a well written, easily read, book that is fully comprehensive regarding how to use phpMyAdmin for both casually inserting and maintaining data in a mysql database; checking queries before utilising them in your code; data transformations; and actual database and user administration, such as changing the structure of your databases, collations, creating system documentation, assigning privileges and more.

    I scarcely believe this book could be much more detailed, especially as it often has more than two screen shots per page – it is no wonder that I now know much more of what phpMyAdmin is capable of!

    The troubleshooting chapter at the back seems invaluable and the chapter covering MySQL 5 additions seems a useful refresher for those of us that may need to be reminded of new functionality present only in that more recent version of MySQL, and after reading this book I fully expect that I shall be using phpmyadmin more and not using either the MySQL Query Browser or Oracle’s SQL Developer as much.

    The blurb on the back of the book says that it is for every serious phpMyAdmin user who would like to use this outstanding application to its full power – after reading it I am very much inclined to agree and would recommend it to anyone that uses phpMyAdmin on a daily basis.

    The Date_Holidays package, a pack of splitters and a pear tree.

    Friday, May 9th, 2008

    Some of you may know that I am a lead developer of the pear Date_Holidays package.

    Date_Holidays helps you calculate the dates and titles of holidays and other special celebrations. This is all driver-based so it is easy to add new drivers that calculate a country’s holidays.
    Until recently all of these drivers for individual countries were grouped together into one package.

    We decided that this one package should be split into subpackages: one subpackage per region/country. Some advantages of this approach are that each driver / filter / subpackage gets it’s own stability and version number – we wouldn’t have to keep increasing the version number of Date_Holidays each time a new driver is added or when an existing driver gets a significant number of fixes.

    Therefore we now have subpackages such as Date_Holidays_Austria, Date_Holidays_Brazil etc etc.

    If you want to use the new set of [sub]packages, the simplest thing to do is uninstall the package that you have installed:

    $ sudo pear uninstall Date_Holidays

    and then install the new package, with a group directive which will install all subpackages:

    $ sudo pear install Date_Holidays#all

    Impromptu PHP User Group meeting in Dublin tomorrow (7th May)

    Tuesday, May 6th, 2008

    Jan Lehnardt , he of couchdb fame, and I will be at the Longstone tomorrow from about 19-20:00 onwards. I’ll bring along some elephpants for the taking!

    And I think some apache folks may be there too.

    Book Review: Object-Oriented Programming with PHP5

    Thursday, May 1st, 2008

    Ok, packt sent me another book to review. This time it’s “Object-Oriented Programming with PHP5” by Hasin Hayder.

    If I hadn’t read in the Author’s Profile at the start of the book that Hasin is from Bangladesh, and that English is in all likelihood not his first/native language, I would have realised that he does not have a fluent grasp of the English language anyway and this detracts from being able to focus on what he is trying to communicate.

    Putting the aspects of Hayder’s grasp of the English language aside, the book is rather good as an introduction to the various technologies that it covers. If you’re already up to speed with OOP then you mightn’t want to bother with the first few chapters; but after that the book covers phpunit testing, design patterns (Hayder uses the Patterns chapter to introduce MVC and later devotes an entire chapter to it), SPL and PDO.

    I got a stunning feeling of deja vu when reading the main OOP chapter: it seemed very reminiscent of the online php manual and user contributed notes at php.net – a resource which Hayder makes the occasional reference to.

    The book’s section on phpunit testing is rather good as an introduction to that concept; though it does conclude with ten pages of text from the PHPUnit Pocket Guide by Sebastian Bergmann. I have to question the rationale behind this: PPG is available freely online and I think mentioning the website for that version of the book would have been a better thing to do.

    I think I will definitely be picking this book up rather often for reference and that it is worth the money (that I admittedly didn’t have to pay).
    But what would I do to make the book even better than it already is?

    1. I was expecting some coverage of UML for representing classes and interactions between them – not a lot but just enough to be useful.
    2. Avoid mentioning topics that are outside the scope of the book – it makes the content appear weak and less comprehensive than it is. I’d simply have a “recommended reading” section or appendix at the end of the book.
    3. This may seem petty but it’s actually quite important, especially as regards the environment – don’t place braces in the example code on seperate lines. It doesn’t matter as much when on screen but when printed out that’s a lot of wasted paper/trees.