FizzBuzz is a kata posted on codingdojo.org.
According to this site, Michael Feathers and EmilyBache performed it at agile2008 when competing in "Programming with the stars" in python, in 4 minutes.
It was using the 04-27-2016 in Lyon, France, at Norsys to illustrate east-oriented programming.
PHP version used to develop fizzbuzz was PHP 5.6.18, but minimal version is PHP 5.5.
And fizzbuzz use composer as dependencies manager.
Install FizzBuzz dependencies using Composer, just do from the root directory:
$ composer install
After that, just do php run.php from the root directory.
The main file is run.php in the root directory.
All classes are in the src directory.
All unit tests are ine the tests\units\src directory.
Fizzbuzz use PSR-4 autoloader, so if you want read the code of:
fizzbuzz\numberclass, go insrc/number.php;fizzbuzz\analyzer\iterator\fifoclass, go insrc/analyzer/iterator/fifo.php.
In context of an east-oriented implementation, all public methods return $this.
Why? Because the rigorous application of this unique rule decreases coupling and the amount of code that needs to be written, remove code duplication while increasing the clarity, cohesion, flexibility, reuse and testability of that code.
In fact, using east-oriented principle force using abstraction and the lack of getter force using the tell, don't ask principle, inversion of control and dependency injection.
Procedural code gets information then makes decisions. Object-oriented code tells objects to do things.
– Alec Sharp
This kata was implemented using TDD, aka Test Driven Development.
To execute unit tests, install FizzBuzz using Composer with the --dev option:
$ composer install --dev
Run unit tests using atoum:
$ vendor/bin/atoum
A James Ladd's blog post but messaging is an Alan Kay's concept.
PHP syntax for method declaration is not very convenient for east-oriented programming, unlike Smalltalk or Objective-C syntax which use interleaved declaration.
So, a method like outputForNumberIteratorIs(number\iterator $iterator, output $output) is strictly equivalent to interleaved declation outputForNumberIterator: number\iterator $iterator is: output $output.
Primary types of PHP are not object, so you must use magic method like __toString() to simulate a string object.
It's an implementation of the null object pattern.
This pattern is usefull to avoid if and decreasing code complexity.
There is no "silver bullet" to understand east-oriented programming, but there are some resources with very interesting or indirect informations about it:
- The original blog post by James Ladd;
- Enlightments about east-oriented programming and Java by James Ladd;
- Object thinking by David West;
- Growing Object-Oriented Software, Guided by Tests;
- Practical Object-Oriented Design in Ruby: An Agile Primer by Sandi Metz;
- Eastward Ho! A Clear Path Through Ruby With OO by Jim Gay;
- The blog post Dazed and confuzzled by Peter Di Salvo;
- The blog post Putting the kibosh on getters and setters by Peter Di Salvo;
- The blog post Shower idea: keyboards and object-oriented design by Peter Di Salvo;
- A discourse about an east-oriented chess game between Peter Di Salvo and James Ladd;
- The early history of Smalltalk;
- An Alan Kay's post on the Squeak's mailing-list about messaging;
- The Deep Insights of Alan Kay by mythz;
- The IRC channel
##east(yes, two sharp, no typo here) on Freenode (essentialy cool french guys here); - Some gist;
- A french blog post and the associated talk.
This FizzBuzz implementation is released under the FreeBSD License, see the bundled COPYING file for details.
Thanks to:
- Norsys for wifi and room;
- Lyon Tech Hub for support and organization;
- Matteo Vaccari & Antonio Carpentieri for The Open/Closed Principle Dojo.