Federico Cargnelutti

Simple is better than complex. Complex is better than complicated. | @fedecarg

Archive for March 2007

The importance of User Experience

without comments

user_experience.jpg

It’s all about the user, right? User experience, often abbreviated UX, is a term used to describe the overall experience and satisfaction a user has when using a product or system. It most commonly refers to a combination of software and business topics, such as selling over the web, but it applies to any result of interaction design. Interactive voice response systems, for instance, are a frequently mentioned design that can lead to a poor user experience.

The importance of User Experience

A usability poster like this one will look great in your office. At least your boss will think that you love users and that you have upgraded to version 2.0. You can buy this poster from here . And no, I’m not attaching any referral code to this link… yet ;)

Written by Federico

March 31, 2007 at 10:59 pm

Posted in Web

The observer pattern

with one comment

Loose coupling is critical to any large-scale project, but few people actually understand what the term really means. Have you ever made a small change in a project, and it seems that as a result, almost everything else has to change as well? This occurs all too often because of tight coupling among the modules in the program. Each module relies on the exact state or function of several other modules. When one fails, they all fail. When one changes, they all must change.

Read the rest of this entry »

Written by Federico

March 31, 2007 at 10:21 pm

Referential integrity

without comments

Recent versions of MySQL have implemented support for foreign keys through the new InnoDB table engine. We explain how it works

Referential integrity is an important concept in database design. The term refers to a state when all the references in a database are valid and no invalid links exist between the various tables that make up the system. When referential integrity exists, any attempt to link to a record which does not already exist will fail; this helps prevent user errors, producing a more accurate (and useful) database.

Read the rest of this entry »

Written by Federico

March 30, 2007 at 11:50 pm

Posted in PHP

DB Error Handling

with 2 comments

One of the aspects that separate the great coders from the rookies is not just making usable or working code but taking care of unforeseen eventualities. When working with more than one process (PHP and MySQL), sometimes unforeseen incompatibilities or server hiccups can cause an unwanted problem. To ensure the integrity of your web applications, it is important that, if such a problem occurs, the web application dies gracefully and provides a means for the developer to track the error.

Read the rest of this entry »

Written by Federico

March 30, 2007 at 11:44 pm

Posted in PHP

Taking a look at PHP 6

without comments

While most web hosts are still in the PHP 4 era, the PHP developers are already planning and working on PHP 6. Lets have a look at what’s been keeping them busy.

Unicode on/off modes

Currently it is possible to have Unicode on or off on a per request basis, requiring the storage of both non-Unicode and Unicode variants of class, method and function names in all the symbol tables.

Having to allow both a non-Unicode and a Unicode versions of names in the symbol table is deemed unnecessary and we agree on allowing only a server wide configuration setting to enable or disable Unicode support. This makes implementation easier for some parts of the engine, it causes less problems for opcode caches and it is slightly faster as no runtime conversion of the names is necessary. We also discussed whether we should even allow Unicode mode to be turned off as current micro benchmarks show that the Unicode implementations of some of the string functions are up to 300% slower, and whole applications up to 25% slower. Disallowing Unicode mode to be turned off is expected to slow down the adoption of PHP 6 too as many ISPs would be reluctant to install a version that immediately slows down the applications of their users. When we provide a switch they can start by turning it off and users would have an easy way of asking their ISPs to turn Unicode mode on by simply reconfiguring it in php.ini. This is also why we chose to pick a runtime configuration setting as opposed to a configure-time configuration switch. We do need some trickery in order to be able to parse the setting from php.ini as we need to know whether to enable or disable Unicode mode before we activate our extensions. Another reason for providing a runtime switch instead of an compile switch is that distributions would only have to create one binary.

Different String Types

A number of people are unhappy with the current implementation where there are either too many different string types (binary, string, unicode) or the multiple implementations of many internal engine functions and helper functions.

After some discussion everybody attending seems to agree that only having two string types (binary and string) makes sense. The Unicode semantics switch will control what type the string literals are by default, of course. Documentation will need to mention that with the switch on, all “strings” are Unicode and with the switch off, all “strings” are Binary.

The major important thing with PHP6 is that register_globals, magic_quotes and safe_mode functions will disappear, features which was causing lot of problems specially for security. Secondly the work of Rasmus and all other PHP developers around APC (Alternative PHP Cache) will be the major performance key in PHP6 since it will be included in the core.

More information in the Minutes PHP Developers Meeting

Written by Federico

March 30, 2007 at 11:41 pm

Posted in PHP

Polymorphism

without comments

The subject of polymorphism is probably the most important in OOP. Using classes and inheritance makes it easy to describe a real-life situation as opposed to just a collection of functions and data. They also make it much easier to grow projects by reusing code mainly via inheritance. Also, to write robust and extensible code, you usually want to have as few as possible flow-control statements (such as if() statements). Polymorphism answers all these needs and more.

Read the rest of this entry »

Written by Federico

March 30, 2007 at 11:39 pm

Creating a Web Service with NuSOAP

with 2 comments

At http://dietrich.ganx4.com/nusoap/, you will find NuSOAP, one of the best-known SOAP classes for PHP. Some might even know its predecessor, SOAPx4. For some time, releases weren’t done very often, but now the project is active again. Nevertheless, you might be better off to check the Concurrent Versions System (CVS) system for the most recent code. Even though you might find several files there, nusoap.php is the one you want.

Calling an XML-RPC Web Service (xmlrpc-pear-client.php)

<?php
  require_once 'nusoap.php';

  $soap = new soap_server;
  $soap->register('add');
  $soap->service($HTTP_RAW_POST_DATA);

  function add($a, $b) {
    return $a + $b;
  }
?>

NOTE

As of this writing, NuSOAP only works under PHP 4, but a PHP 5 port is rumored to be under way.

Creating a Web Service with NuSOAP is really simple because the module takes care of all the painful things, including SOAP. Just follow these steps:

  • Write the function you want to expose as a web method.
  • Instantiate the soap_server class.
  • Register your function with the SOAP serve.
  • Call the service() method and submit $HTTP_RAW_POST_DATA as the parameter.

Written by Federico

March 30, 2007 at 11:20 pm

Posted in PHP

Creole: Database abstraction layer for PHP5

without comments

There are many database abstraction layers, some easier to use, some better coded that others. My personal choice is Creole. I use Creole in production environment with MySQL and Oracle.

Creole provides the following distinguishing features:

  • Built for PHP5: new object model, Exceptions
  • Interface-based system allows easy creation & registering of custom drivers or classes that wrap existing drivers to provide additional functionality (e.g. to log queries for debugging, do query performance analysis using EXPLAIN, etc.).
  • Fully object-oriented API
  • ResultSet scrolling: next, previous, first, last, relative, and absolute row fetching.
  • ResultSetIterator (SPL) provides an additional means for iterating over recordsets.
  • Comprehensive database metadata (database, table, full column info, pimary keys, foreign keys, indexes) using simple OO API.
  • Full unified type system (based on JDBC Types)
  • Simple, un-exceptional OO API for handling BLOB and CLOB data.
  • Type-specific methods handle any necessary conversions and escaping for inserting and retrieving values.
  • Native (no emulation) handling of autoincrement / sequence id generation.
  • Extensive unit test framework tests each driver using real databases.

Written by Federico

March 30, 2007 at 10:27 pm

Posted in PHP