Skip to content

estvoyage/fizzbuzz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fizzbuzz

A PHP east-oriented implementation of FizzBuzz

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.

Requierements

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.

How to use it?

Install FizzBuzz dependencies using Composer, just do from the root directory:

$ composer install

After that, just do php run.php from the root directory.

Code organization

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\number class, go in src/number.php;
  • fizzbuzz\analyzer\iterator\fifo class, go in src/analyzer/iterator/fifo.php.

What is an east-oriented implementation?

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

Unit Tests

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

FAQ

What is the origin of the east-oriented programming concept?

A James Ladd's blog post but messaging is an Alan Kay's concept.

Why name of your function is so strange?

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.

Why there is a statement return $this->value; in fizzbuzz\output\value::__toString()?

Primary types of PHP are not object, so you must use magic method like __toString() to simulate a string object.

What is fizzbuzz\nill?

It's an implementation of the null object pattern.
This pattern is usefull to avoid if and decreasing code complexity.

Have you got any resources about east-oriented programming?

There is no "silver bullet" to understand east-oriented programming, but there are some resources with very interesting or indirect informations about it:

License

This FizzBuzz implementation is released under the FreeBSD License, see the bundled COPYING file for details.

Greetings

Thanks to:

About

A PHP east-oriented implementation of FizzBuzz.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages