Code state, conventions & structure

by Rob Chant on October 13, 2008

I figured we’d start with a brief overview of Renaissance’s code, the basics of how it works and is structured and, um… the state it’s currently where it currently finds itself.

First off, the real basics. Renaissance uses:

  • Fully OO PHP4 (I’ll re-write it for PHP5 soon)
  • MySQL
  • mod_rewrite (optional, but very recommended)
  • JSON configuration files
  • AJAX and lots of other JavaScript, running our own web JavaScript library
  • cURL for web services and whatnot

So in that respect it’s pretty straightforward.

I’ll be explaining more over time how the code itself works. Something important to note, however, is that unlike a lot of PHP applications, it makes no use at all of jumping in and out of PHP tags in order to write code to the page. It also echo anything from anywhere apart from just once at the end, to write the entire page. In other words, it builds the page in memory before outputting it all in one go (note: For back-end pages, that’s not yet entirely true, it does do some chopping around, although still no echos from methods or anything like that. It’ll be inline with the rest of the code soon, however).

I believe that this is a very important point. So much PHP writes code straight to the output from inside functions and methods. That makes the code so much harder to maintain, and more importantly, reduces the flexibility of how one can structure one’s code considerably.

Another basic is that all POST data is sent to pages (well, two pages, one for front end interactions and one for the back end) that the user never sees. They redirect to a target page without writing anything to the output. A pretty obvious point really, but important nonetheless and often missed.

Conventions

As noted on the about page, I don’t really follow the coding world at all, so the code features quite a few of my own conventions, notably how I write comments (yes, it’s almost totally commented, of course… well, it’s mostly commented… actually, some of it’s commented) and one or two other bits and pieces. Some of this stuff is slowly moving over to the more conventional conventions, some isn’t.

  • anything that writes to the output is called a scribbler and starts with ’scribble’
  • [more here as I get round to filling in stuff]

State

As with any long-winded project such as Renaissance, it’s been through a lot of iterations. It’s code structure has changed completely several times. Needless to say, there are still bits and pieces of legacy code in there (not much, and not much that’s used much, but there’s some). There are still static classes. There’s still uncommented code. There’s still stuff hanging out in the wrong place. But overall it’s not bad at all.

I’ll probably be editing this post a little bit over time, so please check back for more information.

No related posts.

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>