First update on progress
Hi again!
So, for this, the first real post in our new Development Blog, I’d like to fill you in on what I’ve been up to PHP-wise in recent weeks.
Alpha 3 was released about 12 weeks ago (Jan 23rd). It was the first release of v2.0 that had really started to look like a useful application, with phpBB integration working in some respects (albeit missing some features and a bit buggy). However, soon after the alpha was released I kind of hit a brick wall with my coding. I kept coming up against problems with the OOP nature of my design that I couldn’t overcome, and I was starting to make some bad decisions to avoid them.
So, although it sounds crazy just as Alpha 3 was showing signs of promise, I actually went right back to the drawing board. Not in terms of overall design of the project (channels, chains, filters - these are all still very much in the picture), but the actual way I describe the classes in PHP. It is by no means starting again - basically I am copying the old Alpha 3 code and pasting into a new, better-designed framework for the application.
The main problem I was up against was that I had developed an enormous tree-like structure of inherited classes. As a fairly inexperienced OOP-based programmer, I made some fundamental mistakes in how I approached Inheritance and Composition. It meant that the whole codebase was tied together in terms of dependence, and any changes to one part would affect another.
So, in reorganising the code, I’ve been much more disciplined in certain areas to ensure I don’t get caught out again. Let me explain a few of my design philosophies.
Test Driven Development
This is the big one! This technique has completely changed the way I write PHP. The concept is very simple, but takes quite a long time to get used to. Rather than try and explain it myself, I’ll let an expert take over. Please read this introduction, even if you’re sceptical. The idea is that you use Tests to specify what your application should do. Write the test first, then the code to satisfy the test. Write no more code than is necessary. In doing this, you get some amazing bonuses:
- all your code is covered by Unit Tests. If a change in code makes a class behave differently, a tests will fail and you will notice it
- You have no more code than you specifically need - no ‘code bloat’ with unused functionality
- If a bug is found, write a test that fails because of the bug. When the test passes, the bug is solved, and should not reappear because of the test
I use Simpletest as my TDD framework. I store my tests in well-organised directories, and run the whole test suite at least once a minute as I develop. My tests are grouped into Unit Tests (testing each class behaves as it should as a separate entity), Acceptance Tests (check groups of classes work well together) and Web Tests (check the Admin Control Panel behaves as expected, producing the correct XHTML).
Advanced PHP 5 OOP techniques
Well, if you’ve used them, you won’t think they’re that advanced. But I have now fully embraced many of the additional features that PHP 5 brings to OOP. I’m using Exceptions to trigger errors now, so that my classes don’t need to return true or false any more. I’m using Interfaces to enforce certain design from my classes, rather than Inheritance. I’m making use of the SPL (Standard PHP Library) to add useful features to my objects with very little code.
External Libraries
Since we’ve left PHP 4 behind, I have now been able to bring on board some of the cutting-edge PHP libraries. The two big ones I’ve gone for so far are the Zend Framework and Doctrine ORM.
Zend is kind of a two-in-one solution in this context. I’m using some parts of the library (in a similar way to PEAR in earlier m2f versions) for things like Mbox access, Caching, Configuration files, etc. I’m also using Zend’s MVC framework. Although I’d written a pretty good one for Alpha 3, I was learning on the job, and just realised that Zend supplied everything I’d done, only better, plus 500% more!
Doctrine again replaces functionality I’d started to build into Alpha 3. It’s ORM, which basically means we just do this:
$chain = new M2f_Chain; $channel = new M2f_Module_Channel_Phpbb; $channel->phpbbRoot = '../phpBB3'; $chain->channels[] = $channel; $chain->save(); |
and our chain is saved in the database. Doctrine uses very simple configuration files to specify the design of database tables, which means both that they are DB-engine-agnostic (great for supporting as many users as possible), and that developers will be able to develop 3rd-party channels and filters with ease.
Summary
So, where have I actually got to with this reorganisation? Well, I’ve got the framework up and running, so I need to add back all the pages from Alpha 3, so you can create chains, configure channels, etc. In terms of channels, Filewriter and RandomTestGen are working. Mbox is finished, as is the Uppercase filter. The phpBB channels will take longer, but hopefully not too long.
In keeping with Agile Development principles, I’d like to release what I’ve been doing soon. However, what I propose is that I actually release my reorganised code before I get back to the same level of functionality as Alpha 3. The reasons for this are many - you can see what I’ve been up to, I can ask you to run the Test Suite and report any bugs, any interested parties can start looking at the code and contributing ideas.
I’d appreciate any comments on all this - post them in the Alpha Testers forum.
Thanks, and bye for now!
Posted in Blog