• 28 January 2009Behind the scenes

    So what's going on lately? I've been quite busy the last few weeks on the infamous refactoring I was talking about on the forums now and then without seemingly getting anywhere ;)

    I feel chatty today so warning... here follows a long boring post about the joys of programming web sites.

    When I started the Reviewing the Kanji website I was learning php and like every self respecting programmer would do after many years of hardcore C and assembler programming, guess what I did ? Of course I stuck to php4 instead of moving to php5, I completely forgot about OO practices, was oblivious to such concepts as "decoupling", "domain logic", "data model" etc etc. And just plain wrote a real monster of flat files and would-be classes that were really just a collection of code that was starting to repeat itself. Whew! ^_^

    Funny thing is that I had the exact same experience with Javascript last couple years. I wrote some really nasty javascript for at least a year, and then discovered that *gasp* you can write decent object oriented code in Javascript. I started relearning seemingly everything I had learned about programming before.

    Fast forward to about a year ago. I put up an Alpha version of Trinity and then development slowed down to almost a halt. I realized I couldn't work on the site like this anymore. I didn't have the heart to add any new features because I knew the more I added to it, the more unwieldy it became.. and eventually the more difficult it would be to clean up the mess.

    Last year I spent a while looking at different php frameworks such as CakePhp, CodeIgniter, Zend... but I kept coming back to Symfony.

    Introducing the "Core framework" :



    At its heart this framework is a very simplified version of Symfony. It is basically all the core features of Symfony's MVC, the front controller, actions components, helpers and templates, the ability to extend the core classes, to have multiple applications under one root project folder; a solid error and exception handling with error 404 and 500 pages.

    The url routing system is where I started becoming more practical and instead of cherry picking functions I've imported the whole routing class as is.

    Where I departed from Symfony is for the database access. I wanted something simpler and I liked the fluent interface of Zend Database and Zend Select, but because of the huge number of include files, I ended up rewriting the Database and Select objects.

    I thought this was interesting... using existing documentation as a design documentation for writing your own code. Many times I wondered, shouldn'tt I stop this whole fiasco and just use the damned framework as it is? But in retrospect I have learned a LOT about Php while dissecting Symfony and Zend, so I think it was well worth it. I discovered many functions in Php that I had no idea even existed.

    An interesting aspect of using another framework as a design document was that for example, should I decide later to move on to the real Zend Database and Zend Select, in theory at least, the transition should be easy, because the function calls are identical.

    So here I am, finally... rewriting THE ENTIRE website code in an MVC architecture.

    As of writing I am about 40% done. I've been working mostly on the sign in/sign out, register, edit account, update password pages, and the static pages (learn more, about, ...). I've intentionally kept the actual site functionality for the second phase to "warm up" so to speak to the MVC logic before attempting to design classes for the most critical part of the site. Thankfully doing the sign in/sign out procedure, the email confirmations, password update etc exposed many little holes that were still unplugged in the Core framework and it feels now almost complete.

    The screenshot shows the "live documentation" as I call it. I honestly can't read anything out of phpdoc generated documentation, so while I've gotten used to documenting in the code with phpdoc, I hand edit the documentation with basic html code to cover the main points of the framework, and document methods of classes as I add them. The documentation itself is the first app I wrote with the framework and so it is itself at the code level both a test and a demonstration of the use of the helpers and other features of the framework.

    I'm hoping to push the refactored site online before the end of February, but it may take up to the end of March, I don't know... the Study page and the Flashcard Review page are going to be the most challenging to rewrite. The code itself is fairly simple but I'll have to redesign those classes very carefully. If done well, I may be able to add Google Gears someday for offline support.

    Cheers

By Month