Thursday, February 02, 2012

PHP Goes Mobile postponed

The PHP Goes Mobile event scheduled for tomorrow in Milan has been postponed due to the exceptional weather, which has slowed down and in some cases blocked transportations. The next date is not fixed yet.

Sunday, January 29, 2012

Biweekly roundup: PHP goes mobile

This week I will be at PHP Goes Mobile, a single day event in Milan centered on mobile platforms and a BarCamp in the afternoon where everyone can propose a topic. In the morning there will be some interesting talks by Francesco Fullone, Enrico Zimuel and others. I'm thinking about proposing a BarCamp short talk on PHPUnit_Selenium.

Here are the original articles published this week on DZone.
Practical PHP Refactoring: Extract Superclass explains how to create a two-level hierarchy by extracting a superclass where to move duplicated code.
Python Hello World, for a web application is my first step into the Python world: how to respond to GET and POST requests from a Python script with Apache and mod_python.
Practical PHP Refactoring: Extract Interface is one of the most underrated techniques in the PHP world.
PHPUnit_Selenium is an howto explaining everything you can currently do with the Selenium 1/2 support in PHPUnit.
Practical PHP Refactoring: Collapse Hierarchy is about simplifying a design by collapsing classes in a hierarchy that are not really different.
Ajax requests to other domains with Cross-Origin Resource Sharing is one of the possibilities for using the XMLHttpRequest object to connect to external websites.
Practical PHP Refactoring: Form Template Method is about eliminating non-obvious duplication with the Template Method pattern.
Unit testing when Value Objects get in the way explains the usage of the Derived Value pattern to simplify a bit tests that involve Value Objects as a fixture, or as collaborators.

Sunday, January 15, 2012

Weekly roundup: the coming war

Now, it may seem like SOPA is the end game in a long fight over copyright, and the Internet, and it may seem like if we defeat SOPA, we'll be well on our way to securing the freedom of PCs and networks. But as I said at the beginning of this talk, this isn't about copyright, because the copyright wars are just the 0.9 beta version of the long coming war on computation. -- Cory Doctorow
I advise you to read the full transcript of Cory Doctorow's talk (or watch the videoThe Coming War on General Purpose Computation to get a feel of where the closed&special purpose devices trend may head (or is already heading) in the future. Sacrificing Turing-completeness is something no engineer can dream for.


Here are my articles published this week on DZone.
Practical PHP Refactoring: Push Down Field explains how to move a field down into a class hierarchy to simplify the involved superclasses.
Object-oriented Clojure is a tutorial on how to use Java objects from Clojure and how to define new interfaces and classes (actually protocols and records).
Practical PHP Refactoring: Extract Subclass explains how to extract a new subclass, something we assumed already existed in the previous articles of the series.
Open/Closed Principle on real world code is an implementation of the Command pattern in PHPUnit_Selenium, displaying production code instead of the usual self-contained examples.

Sunday, January 08, 2012

Weekly roundup: Wirfs-Brock's book

I have started reading Rebecca Wirfs-Brock's 2003 book, cited by XPers as one of the books that teach the lost art of object-oriented design. So far I have filled one page of notes while reading the first chapter, and reached the first code sample on Double Dispatch; it's a very dense book.
It's too soon to tell if this book's content is obvious or mind-blowing - but it can succeed in instilling a design mindset different from the modern OOP one; for example, based on roles and responsibilities instead of "records with functions attached to their heads".

These are my articles published this week on DZone.
Practical PHP Refactoring: Pull Up Constructor Body completes the miniseries on pulling up duplication into a superclass, as one of the ways to eliminate it.
TDD for multithreaded applications is my attempt at test-drive the design of a distributed applications without resorting to sleep() calls and non-deterministic tests.
Practical PHP Refactoring: Push Down Method is one of two articles on simplifying superclasses by pushing down pieces of code that are specific to a subclass.
Web application in Clojure: the starting point is an howto for using Ring, the equivalent of the Servlet API in the Clojure world. I probably will try out higher-level tools in the next weeks, like Compojure or Noir.


Sunday, January 01, 2012

Biweekly roundup: waterfall resolutions

No new year's resolution for me; I've come to think they have the trait of a waterfall process: what if you realize the established goal is revelaed to be not so good for you? Even with "universally" recognized beneficial habits, you may discover they're not so important after a change in priorities. Exercising every day may be superceeded by practising a sport; learning a new programming language may be by a new job where you specialize in a single one. To me, it sounds waterfall-ish to establish an yearly goal and work towards it without revising the situation at least monthly.

By the way, in the last two weeks of the year I have published a few articles on DZone that may interest you.
Practical PHP Refactoring: Replace Error Code with Exception explains how to write object-oriented PHP also in dealing with errors.
The Spark micro framework is a concise, self-contained framework for quickly develop Java web applications.
Practical PHP Refactoring: Replace Exception with Test attempts to avoid unnecessary exceptions when an error condition can be early detected.
3D experience in a browser with Three.js is a review of a library for building 3D scenes in a browser over WebGL, the canvas element or SVG.
Practical PHP Refactoring: Pull Up Field explains how to eliminate the duplication of a field within an inheritance hierarchy.
Clojure libraries and builds with Leiningen explains how to pull Clojure and Java libraries and compile with them from the command line, like you could do with Ant and Maven.
Practical PHP Refactoring: Pull Up Method explains the use of inheritance to eliminate the duplication of a method.
Open source PHP projects of 2011 is a non-scientific review of the most popular and exciting projects in the PHP landscape.

Sunday, December 18, 2011

Biweekly roundup: more and more languages

I am a PHP developer and a student by day, but I don't want to limit my options: I'm currently experimenting with Clojure and exercising with Rails. Each new language or platform teach us something general about programming; I advise you to abandon any prejudice if you decide to dive into a new language in your practice time (which for a PHPer programming Ruby is essential.)

Here are my articles published in the last two weeks.
What I learned in the Global Day of Code Retreat is a summary of my experience at the Code Retreat in Milan during the Decembed edition.
Practical PHP Refactoring: Remove Setting Method is about guaranteeing immutability or simplifying the interface of an object by throwing away a method.
Testing and specifying JavaScript code with Jasmine is an example of usage of the popular BDD JavaScript testing framework.
Practical PHP Refactoring: Hide Method is about information hiding: limiting the scope of a method to be able to easily evolve it later.
Practical PHP Refactoring: Replace Constructor with Factory Method transforms a giant constructor into several well-named Factory Methods.
Rails from the point of view of a PHP developer is about me trying out Rails 3 (again, without prejudices).
Practical PHP Refactoring: Encapsulate Downcast (and Wrapping) is about the PHP version of downcasting: converting primitives and wrapping them in Value Objects.
jQuery plugins with jsTestDriver is an example of real world JavaScript development with TDD.

Sunday, December 04, 2011

Weekly roundup: the code retreat

Yesterday was the Global Day of Code Retreat, an event where local groups of developers get together to hone their skills. It consists of six iterations of solving a problem (simulating the Game of Life) in pairs, where at the end of each hour the code is deleted and the pairs mixed. This combination enforces a focus on the method, not on the result; and allows to try out many different approaches (outside in, bottom up, functional and object-oriented languages, using no else or primitive types, closed eyes and an hand tied behind your back...)

I will write more about the experience in Milan in the next days on DZone. Here are my articles published in the past week.
Practical PHP Refactoring: Replace Parameter with Method is about simplifying a method's argument list by eliminating premature parameterization.
Clojure for dummies: a kata is the FizzBuzz problem implemented in Clojure, a now-popular Lisp dialect.
Practical PHP Refactoring: Introduce Parameter Object is about replacing a list of parameters with a single object.
HTML5 Drag and Drop uploading outlines how this technique works, when it breaks and how you can get it in your application in a few minutes.

Thursday, December 01, 2011

XPUG Milano, November 30th

Yesterday Uberto Barbini held the second part of his Agile Day presentation at the eXtreme Programming user group in Milan. Here are the topics of the talk and the discussion, that you can also follow on the slide deck.

At the conference (video in Italian), Uberto covered only part of the presentation, so he restarted from the half presentation check:
  • many bugs are caused by shared, inconsistene state
  • the procedural paradigm doesn't care how you organize state
  • OOP encapsulates state inside objects
  • functional programming expels state from pure functions.
An example of OOP went wrong was a MyBag object which allows read and write access to any item inside. The Singleton pattern used for no reason and the absence of any form of Dependency Injection are other common pitfalls: just because a piece of code contains many classes and methods it does not mean it is object-oriented.

The Blackboard
An interesting thing came up while this non-OO code was presented to us: we cannot judge a design without knowing which is the underlying problem it solves. While changing class names simplifies a slide, the same Blackboard metaphor can be implemented with wildly different results:
  • in the case of a list of actions to perform, it couples the actions in a certain order; the first or second action populates the blackboard for the other ones and cannot be moved.
  • in a distributed scenario, it decouples different processes from knowing the rest of the system, and allows new configurations.
Yet the scenarios are identical if not for the names of classes and methods.
The presentation went on to compare the object-oriented and functional approach as different tools for solving different problems: they are not always in competition, but code can contain a mix of both according to the problem at hand. For example, Uberto cited simulations as a really natural place for objects, and transformations of data into different formats (XML, JSON) as a call for pure functions.
This reminded me of the Expression Problem and of how new requirements favor either the functional or object-oriented solution.


Rebecca's book
I'm not sure I will understand the Centralized/Dispersed/Delegate control comparisons before reading Rebecca Wirfs-Brock's book on design, but an issue that came up is that this kind of books is disappearing, despite being very handy in teaching design. Today we see many technical books which teach how to code in Java or Clojure or Ruby, but not book on how to model and solve problems with code.


Elegance and familiarity
A final note is Rick Hickey's (inventor of Clojure) quotation:
Elegance and familiarity are orthogonal.
Just because we see functional code as strange and different from the object-oriented approach, it does not mean it's inelegant: probably just that we are not familiar with it. It is closed against different changes than the equivalent OO solution; and a functional programmer will see our objects as inelegant too.

PHPUnit_Selenium 1.1.1 has been released

Yesterday Sebastian reviewed my PHPUnit_Selenium master branch and release a new package in the phpunit PEAR channel. You can install it along with PHPUnit easily:
$ sudo pear install phpunit/PHPUnit_Selenium
Before this release, PHPUnit_Selenium was broken when used with PHPUnit 3.6.

I'm closing several more issues and I plan to cover with tests the 2K lines of code contained in the package: currently the test coverage is terrible. After the current features are covered, we can start thinking about supporting the Selenium 2 API (based on WebDriver). In any case, I will keep backward compatibility: support for WebDriver will come with another base Testcase Class.
If you want to contribute, consider providing tests for the functionality you are using. For example, the following areas are uncovered:

  • running Selenese tests
  • all the Custom Assertion methods
  • running tests in multiple browsers.

Acceptable tests comprehend an HTML page to use as a target and the actual test, written in Selenese or using PHPUnit_SeleniumTestCase. If you want your pull request to be immediately accepted, provide a test along with the rest of the code. You can take some inspiration from the existing ones in the Tests folder, which will serve as examples.

There is an undocumented, experimental feature in this release: call PHPUnit_Extensions_SeleniumTestCase::shareSession(true) in your bootstrap and the browser session will be shared between tests; a new session will be restarted only after non successful tests.
 It will be up to you to reset the state of the browser to perform new tests, and will leave the browser windows open after the end of the run: it's called experimental for a reason.



Sunday, November 27, 2011

Weekly roundup: PHPUnit_Selenium

I am now the maintainer of PHPUnit_Selenium, the PHP library for writing PHPUnit test cases that make use of Selenium RC to drive a real browser (usually to perform end-to-end tests). PHPUnit will continue shipping the library, and PHPUnit_Extensions_SeleniumTestCase will continue to be compatible with the Api in the manual.
Right now, you should use PHPUnit_Selenium in tandem with Selenium 2. Selenium 2 integrates WebDriver (not supported yet from PHP code) and implements the old Selenium RC Api, so it will continue to work and be maintained. If you encounter a backward compatibility break, open an issue.
PHPUnit_Selenium was not maintained and was broken in PHPUnit 3.6; with the next release, it will resume working. I'm integrating all sort of pull requests initiated during 2011, so if you want to contribute or to merge back one of your forks, you will be welcome!

Here are my original articles published this week.
Practical PHP Refactoring: Replace Parameter with Explicit Methods explains how to break up a method into a few, finer-grained ones.
Setting up a LAMP box with Puppet is an how to on writing Puppet manifests for provisioning packages and services like Apache, PHP and MySql in a machine (instead of writing long scripts containing apt-get, yum and /etc/init.d/ calls).
Practical PHP Refactoring: Preserve Whole Object explains how to pass an entire object to a method instead of extracting its state and passing a series of variables.
PhoneGap: native applications written in HTML is a review of a mobile application frameworks which promises to wrap your Ajax-based applications into an Android or iOS one.


ShareThis