Why developers don't need Object Oriented Programming

ColdFusion , Rants

I'll admit straight away that my background is in procedural code, way back before Object Oriented Programming (OOP) had not been dreamt up, or maybe just no one bothered to tell us humble COBOL programmers!

I started coding with ColdFusion on version 4.5 and the code I wrote was very much like this Form posts to action page that relocates somewhere that displays some links that show more Forms etc.

No framework no structure, spaghetti of the worst sort.

So I looked round and decided to adopt fusebox as a framework and this improved my code a great deal separating out data access, business logic , and display code.

Later versions of fusebox made this even better by forcing the use of XML in the flow of control from request to request, stopping the leak of business logic into the flow control.

Now like every good developer I'm lazy, so if I find myself coding something twice I start to wonder how I can make that code common and call it. The answer of course is to get data access and business logic which is liable to be called from multiple places into cfcs.

I learnt to make my functions as cohesive as possible (focused on as tight a purpose as possible) because that helps to make the API's clean and simple.

I found that making functions only dependant on their arguments, with no other dependencies on variables in shared scopes, made changing code much easier and more predictable. Not like the days of relying on variables passed up from nested custom tags!

So I started to believe that maybe I'm doing OOP already?

Well... NO because I'm still think procedurally.

If someone says to me we need a program that makes a cup of tea, my first thought is not

I'll call the kettle factory and the tea pot factory, inject the tea pot and the kettle into the cup of tea object and then call the makeTea service method which will know how to make a cup of tea by magic.

I expect that's how you guys make your tea, but us 'ol folk work through a process :-)

Kettle must be available

Teapot must available

Ingredients must be available from the 'Tescos' datasource.

Need to 'display' my tea to the user in a 'cup view'.

(work with me here ok?)

So since my system regularly needs to make tea I have Kettle and TeaPot cfc's instantiated in application scope with any init() method already run. But NO injection of other objects.

(gasps of horror already)

So earlier I said I didn't make my functions dependent on any shared scopes; well I lied because they do call other cfc functions by directly referencing functions something like this application.teaPot.openLid().

(more gasps of horror)

I don't have a service layer, data access layer and domain layer as such, but I do have functions grouped logically together in cfcs and by following the principles of cohesion and loose coupling the functions inside those cfcs start to adhere to that pattern automatically as you think through and re-factor code.

There is NO inheritance. So if I see a call to application.kettle.switchOff() I can open the kettle.cfc and find a function called switchOff and see what it does. I don't have to chase up some inheritance tree to find the actual function.

I have NO beans. CF gives us queries as a great way to pass around record sets. Sometimes a structure or an array might be more suitable, but either way CFQUERY and a bit more CF is all you need. If I need to maintain the code that saves an address record to add a new column because of a database change I want to see only a handful of SQL queries and the CF code that works with those record sets. I don't want to see multiple layers of code encapsulating the address record as a bean with bean factories and getter and setter for each column, too many additional lines of code to look at to understand, to go wrong or get wrong.

What about Aspect Oriented Programming (AOP) I here you cry. How do I handle cross-cutting concerns such as logging and security?

You know what? I would rather have the ugly but easily understood

application.utils.log(stuffToLog=stuff)

wherever I need it than the very clever but much more hidden and tricky to understand XML of ColdSpring.

Security can be nicely handled as a plug-in at the application.cfc or fusebox level.

I think much cleverer people than me have taken some very good concepts and developed them to their logical conclusions, but in so doing have lost sight of the wonderful speed and agility that makes CF such a great language in the first place.

Keep the principles foremost but also the KISS principle 'Keep it short and simple' or 'Keep it simple stupid!' And if it makes sense to break a rule once the pros and cons have been considered, then break it!

If this has enraged you mightily please let me know where I have gone wrong :-)

subclipse 1.4.8 in ganymede eclipse

eclipse , subclipse , SVN No Comments »

I have experienced an annoying bug with switching my projects between SVN branches in eclipse.

It tended to freeze eclipse at the end of the swtich - forcing me to crash eclipse and restart.οΎ 

When I restarted eclipse I would generally find that the swicth had actually happened.

Anyway I have upgraded the subclipse plugin to the latest version 1.4.8 (update site here) and have now done 4 big switches with no freezing, hoorah!

It also seems faster - so thanks subclipse guys.

Using Aptana's Sync Manager

eclipse 1 Comment »

I use the free version of Aptana - an eclipse plugin. I use it mainly for CSS and Javascript editing. One day I will delve more into its support for various Javascript libraries - including JQuery (which is the only one I bother with these days....).

Anyway I had a large site to ftp to a remote host from home and my uplink speeds where rather slow. I left it running. When I came back the laptop had decided to hibernate at some point during the process!

It looked like most of the site had transfered, but how to be sure?

I used the Aptana Sync Manager. You can setup the two sides to sync one being over ftp, and it will merrily run through all the files and inform you of any mismatches. There are plenty of options to configure exactly how this works. I just wanted to know if any files had been missed and sure enough there were a handful missing.

One of the many extra Aptana goodies.

Switching to mangoblog from blogcfc

No Comments »

I decided to get back to some blogging and while I was at it change blog software.

I was using blogcfc and the main reason to move to different blog software was that anytime I wanted to make changes to blogcfc, I was a bit frustrated finding my way around the code and always wanted to restructure it. However blogcfc has served me well and I thank Ray Camden for providing such a great tool, but I began to look around for an alternative.

It had to be CF based and needed to be extendable if I need to tinker.

If you search for coldfusion blog engine, mangoblog is the top of the list, and I also found this endorsement from remote synthesis. I thought that the software has probably improved since this post and so far I have not encountered any big problems.

The installation was very easy with a wizard leading you through each step. I was expecting to have some pain with the migration of existing posts but found that the migration wizard did it all with no hitches!

I look forward to trying out the themes and plugin API to really customise this blog.

There is only one downside. This blog makes extensive use of objects and in some shared hosting enviroments it can be slow to load initailly - in fact this one often fails on the first attempt (I'm assuming if the application has timed out). For a busier site I guess this would not be a problem, but for humble bloggers such as myself may be a reality sometimes :-(

Others have mentioned this on the mango forums.

I'm planning to have a scheduled task that pings this blog say once an hour to get round the problem.

Mango Blog is available here

Development/Testing Efficiency and using Selenium Firefox plugin

ColdFusion No Comments »
One of the snippets of advice in the Neal Ford's Productive Programmer (reviewed here) was to use the Selenium firefox plugin to speed up repetative testing processes

To paraphrase Neal Ford....

So imagine a wizard like set of screens and you are testing step 3, you have to repeatedly fillout the forms for steps 1 and 2 to see the latest change you have made for step3.
With each change and test you think - 'ah just one more change and I'll be done....' ten changes later you are still working on this!

I found myself in just such a loop and eventually downloaded and installed the Selenium plugin to firefox and created a macro to run through steps 1 and 2.

No setup is required. You will find the plugin under the tools menu and it opens a popup window already in 'record' mode for the current site you have open. Go through the screens as normal and Selenium records all clicks and key strokes.

Next time you need to test just click on play in the Selenium popup window.

This was a really big time saver - I wish I had done it right from the start!
Powered by Mango Blog. Design and Icons by N.Design Studio
RSS Feeds