The application is the framework

I find it interesting that some web applications have matured to the point that they basically become frameworks in and of themselves. Take WordPress as an example. Originally written as a blogging tool, it has evolved into a framework of its own through its various hooks and actions that, if you were feeling adventurous, allow you to do pretty much whatever you want, from creating new tables to creating entirely new functionality.

Playing with a system that’s evolved into a framework is very different to playing with a system that was written as a framework first and foremost. I’ve been developing a plugin for vanillaforums to allow classified listings on a forum site, and it’s interesting to look at the architecture. On some levels, vanillaforums feels over-complicated for just a forum. But then you look a bit deeper and find a whole MVC framework coded up, with the forum module essentially just an application written on top of the framework. I do wonder sometimes why someone would go to the trouble of re-inventing their own framework when there are so many available ones out there. But I can, at the same time appreciate the desire to create a framework that follows your own opinions rather than falling in line with someone else’s.

I wonder at what point we could consider an application to be a framework? Because any well designed system is or should be easy to extend. I think what makes an application into a framework is documentation. Good documentation that allows moderately skilled developers to jump in and be productive immediately turns a simple app into a framework in it’s own right. That and a .org domain name 🙂

Vanilla Forums plugins – escaping SQL strings on Setup

chemical element for vanilla

Vanilla Forums is basically built upon a customised MVC framework called Garden. It makes developing plugins for Vanilla fairly neat, but documentation is somewhat thin on the ground for the actual Garden framework. When working on the Setup() function of my plugin, I was doing some initial data insert into a new table I was creating. Since I was inserting a fair amount of data, I was populating an array which would subsequently be used by the Vanilla/Garden data layer to do the insert; something like this:


$ret = $SQL->Insert('eub_NewTable', 
        array(
          array('Name' => 'Grand father', 'TreeLeft' => 1, 'TreeRight' => 28, 'TreeLevel' => 0, 'LevelOrder' => 0, 'ParentID' => 1),
          array('Name' => 'Bill's father', 'TreeLeft' => '2', 'TreeRight' => '365', 'TreeLevel' => '1', 'LevelOrder' => '2', 'ParentID' => '0')
        ));

Woops….there’s a single quote in there….

Unfortunately, unless I am doing something very wrong, it seems that Vanilla/Garden doesn’t escape these for you. I suspect there is a function somewhere in the framework to do the escaping for you, but I decided to hack it for the sake of speed…..like this:

array('Name' => 'Bill's father',

And we have a winner. And I gan get onto more exciting things than populating my base data.

Principles not techniques

I like to think of coding in terms of principles vs techniques. I’ve met tons of good coders with lots of technique. Good technique. Rote technique. I’ve met very few coders who have good principles. A principle will let you look at anything code related…..and understand it….and if need be troubleshoot it.
Continue reading Principles not techniques

Dreamhost, Google App Engine and the naked domain forwarding fun

What are we trying to achieve:

We want a domain (both naked and with the www prefix) to point to our Google App Engine hosted project. For purposes of our demonstration, we will use the domain of my quick ‘n’ dirty project that I put together to play with GAE.

This doesn’t sound too difficult in theory. The gotcha is that google doesn’t support naked domains (i.e. the non prefixed version of the domain name) for some reason. The google documentation suggests that you add a CNAME record for your www prefixed domain to ghs.google.com and then forward or redirect your naked domain to your www prefixed domain.

I’m going to assume you have your project in GAE all set up and that you have followed google’s instructions on getting the domain name through to google apps, insane though it is that you have to do that instead of just having it all in the app engine admin side, but hey….I’ll jump through hoops for a free hosted nosql implementation.

Ok, on to the Dreamhost side – problem is, choosing the “fully hosted” option at Dreamhost, I couldn’t add a CNAME record for my domain because there is a non-editable CNAME already added by Dreamhost. Choose the “Google Hosted” option, and the www.example.com works, but I could not forward the naked domain to the www sub-domain because the domain was no longer hosted at Dreamhost and I couldn’t insert a redirect anywhere….. Arrrg!

This is what I did:

  • Enable the “DNS only” in Dreamhost.
  • Add a custom CNAME record for www.example.com.
  • Enable “Fully hosted” in Dreamhost with the “Remove WWW:” option.
  • Weyhey….now www.example.com goes to the google app engine hosted project, and example.com points to a directory at Dreamhost.
  • Last step – set up a .htaccess file in said directory to redirect the naked domain to www.example.com.

And it works!

Telerik Radgrid and filtering on ListTextField with a GridDropDownColumn

Another story in what it’s really like to develop software. These are the kinds of hacky bodges you will end up making in any system that is more than a few months old and is in production. 🙁 These hacks do not make me happy. Especially when they are hacked because of pre-built components that are meant to save you time!

The Telerik Radgrid is both a blessing and a curse at the same time. How can a grid, that seems designed to have a dropdown column in it and comes with default filtering, not take into account the fact that you are going to have foreign keys in a grid that you want to filter on?

This is an ongoing rant of mine. Getting good foreign key support on large enterprise applications seems like an uphill struggle every single time. I wrote about how I like to see books on programming jump right in and show me how to get my foreign key drop downs hooked up almost right off the bat, since it is almost entirely unavoidable in any application that has any sort of usefulness in my opinion.

My goodness getting the RadGrid to do your bidding can be an infuriating ride. Personally, I think components should just work out of the box. I know the RadGrid is extremely complex and there are layers upon layers of documentation and examples on the Telerik site, but to me, I shouldn’t have to find out about how difficult it is to filter on ListTextField after I’ve knocked up a prototyped to a client. Heck the documentation should have a large caveat at the top telling you the limitation of the software. Really, I shouldn’t need to read that far into the documentation just to use the component in my opinion. I want something quick and easy to take the pain out of grid based data admin, not a whole new bloody thing that I have to learn inside out.

As per Telerik’s website:

he built-in GridDropDownColumn will be filtered by its ListValueField when the default filtering feature of the control is used. Filtering by ListTextField is not attainable in the present version of Telerik RadGrid

Great. Thanks! This is burried in the How To section. Okay, not too obtuse, but still, all the basic examples show filtering on example datasets that are things like Customer listings (with Customer, Contact Name, Company). Heck, it is reasonable to assume that Company was being looked up using the GridDropDownColumn column. Isn’t it?

So, Telerik provide a solution – have a hidden field that is the text description. Capture the ItemCommand on the grid and then if it is a filter command, pop the filter text into the hidden field’s filter text box and run the filter based on that criteria. The problem is, out of the box this breaks user experience because the filter text they typed in disappears.

Now you have to hack around to find a way to keep the filter text there. Come on Telerik, get this one together. Not pleasant. I gave up, because I didn’t have time to delve that deeply into the RadGrid. I needed something quicker. Option 2 given by Telerik – implement a custom drop down in the actual filter area of the grid. The example code was long and I didn’t feel like going through it – again time constraints. I just couldn’t spend time exploring all of this because I have deadlines. Why couldn’t they just build this into the grid? If they have solutions, it shouldn’t be that difficult to put it into the base functionality.

One more thing – putting a drop down in that is based on an id field (and let’s be honest it probably is if it’s a lookup into another table) means you get the default “number” filtering options. This means that the filtering options out of the box are things like “greater than”, “less than” etc etc. These don’t make sense for a user who is filtering based on text. This is another fault with their default solution outlined above of using the hidden field and substituting values in. I know you can overide this and put your own filtering menu in, but say it with me…..deadlines. 🙁

By now, I’m not a happy bunny. What did I do in the end? I amended my stored proc to bring back a complete result set with description fields (making things slower for me because now I have table joins). Then I hid the drop down list field until the user wanted to edit the row or add a new row in. Then I hid the description fields and showed the drop down fields.

What a bodge.

Stupid SQL mistakes – more from the land of application support

Here’s a lovely little one that just took me much to long, probably because I’m tired, or having an off day or something:

Select [Name]
         [Surname],
         [Address],
         [Telephone],
         [Email]
From ATableAboutPeople

See, the error isn’t obvious, because the SQL compiles and runs, but the result set just doesn’t bring back what you expect…..because [Name] is now aliased as [Surname] – all because of a missing comma.

Hate it when that happens.

Rails on Windows – nil object when you didn’t expect it

If you jump between Linux and Windows XP like I do, sometimes you’ll pull your Rails app into the dreaded M$ platform, fire it up and be greeted with a lovely “Internal Server Error”. Naturally it goes on to say something like “You have a nil object when you didn’t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each” despite the fact that you’ve changed no code since last night when your app was running rather nicely in a Linux environment thank you very much. Sometimes you just need to hack your way out of a problem without worrying about the whys and wherefores – and that’s exactly what we are going to do here. So……open up configenvironmentsdevelopment.rb and find this line :

config.logger = Logger.new(config.log_path, 2, 10.kilobytes)

comment it out comme ca

#config.logger = Logger.new(config.log_path, 2, 10.kilobytes)

and fire it up again. All good? Yes? Excellent. Fixed. Why? Um. Log rotation in XP apparently. Something funny about it. Don’t really know. Haven’t investigated it much further because there is no way in hell I’m going to run a production Rails app in Windows. Ever.