I don't hate Mach II

I was doing a remote presentation last night on "Object Orienter Programming for ColdFusion Developers" and it eventually moved over to the topic of optimizing ColdFusion Components. While I was showing what I do for speed, I relayed a story about a client of mine who is using Mach II. I was brought in to speed up the clients site which was timing out on a regular basis.

After a review, I found some places that could be optimized and one major place was the Mach II code. I rebuilt most of it and the time savings was immense. Of course, in order to make it faster I had to cheat and break many of the accepted 'rules' of OOP and CFCs. Not something that I suggest anyone doing without a full understanding of the how and why of it (which I'll talk about another time).

After telling the story and showing what I did, someone assumed that I did not like Mach II and asked what Framework I used. I quickly corrected his conclusion and told him not only do I have nothing against Mach II, but it's a really well thought out and solid framework. I don't use it because I don't use any of the public frameworks. I'm obsessed with optimizing my code for speed and performance and really optimal code doesn't go hand in hand with frameworks. On the other hand, I stressed that using a framework is a MUST in almost all situations and that people should not go my route unless they really know what they're doing and have very strict control over who has access to their code.

Bottom line is that unless your a paranoid, obsessive, hermit programmer, use a framework!

FAQ-U 2 - OOP for CF and Frameworks

Yep, the second issue of the Fusion Authority Quarterly Update is not only in my hand, it's packed and ready to go to all subscribers. But of course, anyone who subscribes before the end of the year gets this issue as well as the previous one in PDF format as well. Trust me, PDF is nice to read once in a while, but nothing beats the solid feel of this journal.

As for content, we're talking an actual book worth of Object Oriented Programming for ColdFusion as well as Frameworks. 120 pages of it to be exact (20 pages over what we expected for this issue). But why listen to me when the table of contents speaks for itself:

Editorial

OOP in Your Toolbox
by Judith Dinowitz

Columns

What's Hot? What's Not?
by Raymond Camden, Simeon Bateman, Charlie Arehart, Kurt Wiersma, Michael Dinowitz
Tipical Charlie - How do I Call Thee (CFC)? Let Me Count the Ways!
by Charlie Arehart

Features

Object-Oriented Programming: Why Bother?
by Brian Kotek
The Object-Oriented Lexicon
by Hal Helms
Design Pattern Safari
by Peter J. Farrell
From User-Defined Functions to ColdFusion Components
by Michael Dinowitz
Base Classes: Better Than Your Knew!
by Peter Bell

Concepts

Introduction to Frameworks
by Jared Rypka-Hauer
Fusebox 5 Fundamentals
by Sean Corfield
Mach-II Fundamentals
by Matt Woodward
Model-Glue Fundamentals
by Joe Rinehart
Lessons I Learned from My First Model-Glue Application
by Jeffry Houser
ColdSpring Fundamentals
by Chris Scott
Reactor Fundamentals
by Doug Hughes

Tools

FusionDebug Explained: Interactive Step Debugging for CFML
by Charlie Arehart

And no, we're not going to kill you with advertising. We don't even have advertisers. What we have are supporters who are helping to make sure that we can get the journal to you. A big thanks to:

Adobe Systems, inc. - Makers of ColdFusion, Flex and much, much more

Intergral Information Systems - makers of Fusion-Reactor and Fusion-Debug

WebApper Services, LLC- Makers of SeeFusion

Quill Design - Maker of the SiteDirector shopping system

Straker Interactive - Makers of ZoomFlex

Liquid Image Studios - More creative design than you can shake a forest at

House of Fusion - Providers of quality ColdFusion and related technical content

You can order the journal right away and we'll not only get it to you ASAP but we'll give you access to a PDF of it to hold you over.

http://www.fusionauthority.com/quarterly

We accept orders through Google Checkout (USA Only - Preferred method), Paypal (World wide), or contact us for bulk orders and we'll work with you.

Interfaces - Why bother?

I've been watching people talk back and forth about including interfaces into the ColdFusion language or not and I've been wondering why bother. From what I know, interfaces (the Java keyword rather than the general term) are used to define what is basically a "rules class". This rules class contains the names of methods and any arguments that they may need. Any class that uses this rules class (implements it), must have a method within it of the same name (and arguments) or else an error will be thrown.

Basically an interface is a contract between a class and a rules class that says that the class has to have all of the rules' methods to be legal.

In ColdFusion terms, this means that there is a 'rules' component (an interface component) that only contains cffunction tags. The cffunction tags can have cfargument tags, but these are not required. Nothing else can be in this component other than these functions.

Some other component will include this interface component and basically have to create a function for each of the functions in the interface component. How this will be done is all theory to the community at the moment, but the theory will follow the steps above.

Now if my definition is correct, then this sounds more like something that would be useful at development time to make sure that a component being written follows certain rules. If it's going to be used at runtime, then it 'feels' like it would just be more overhead and unneeded validation. Am I wrong? Is there something I'm missing here? What are the issues and why should I (or anyone else) care?

Flock the Duck

You know, duck typing is really easy. It's a simple concept for a simple job. Do you know why it's so hard for people to learn it? Do you know why it took me so long to understand it? Because it's a simple concept hiding behind a stupid phrase. Walks like a duck, talks like a duck, acts like a duck. Flock the duck! Really - Remove the stupid phrase and the stupid euphemism and what you get is something that's really easy to understand.

So what is duck typing? Duck typing is a concept where you pass an object reference, and only an object reference, into a CFC. It has nothing to do with variables; it has to do with object references.

Inside the CFC, you're going to have some code that's going to make use of an object reference that's been passed in. You can pass in 10 different object references, and as long as they have the same method that the CFC is going to be making use of, then it's duck typing.

So let's do a really simple example. Let's say you have a CFC that's trying to make use of the FlocktheDuck() method. You can pass in a reference to the orangeduck CFC that contains FlocktheDuck(). You can pass in a reference to the mallardduck CFC that contains a FlocktheDuck() method. You can pass in a reference to the rubberduck CFC, as long as it contains a FlocktheDuck() method. As long as these references that you are passing in contains the FlocktheDuck() method, then the CFC that you're passing them into will use the FlocktheDuck() method, and that's Duck Typing. What the FlocktheDuck() method actually does depends on the object reference being passed in - and we don't care what it is! Because it's all the same method name using the same method variables. What it returns we also don't care about, because it's going to return something. But it has the same method name and the same method arguments.

That's it. Simple. To the point. Now all you have to do is hide it behind a stupid phrase, and no one knows what you're talking about.

Duck Typing Lite

My background is not in Java or C++. My first steps into real programming was ColdFusion and I later learned those other languages (and many more). This has left a conceptual hole in my education. This has led to me being confused by some of the writings that people in the ColdFusion community are posting about Duck Typing.
I've read article after article on it and there seems to me to be no clear definition. There are concepts mixed into most articles that seem to have nothing to do with Duck Typing like Mixins and Interfaces. There are concepts thrown around that seem to muddy the understanding of what should be a simple idea. What follows will be my understanding of Duck Typing with a concrete example. Unfortunately, this understanding is neither perfect nor what Duck Typing is according to those in the know. This is why I refer to it as Duck Typing Lite.

Duck Typing is a conceptual approach to creating CFC methods where the method does NOT use the CFFUNCTION or CFARGUMENT tags to try and validate the data being passed in or out. Instead, the focus is put on the value of the data and if it 'works' for the method. To explain it better, lets look at a UserInfo method. This method will accept an identifier for a user. This can be the users ID number or their user name. Both are valid 'messages' that will be sent to the method and the method will decide how to deal with it.

<CFFUnction name="UserInfo" access="public" output="false">
   <cfargument name="UserID" required="yes">
   
   <CFSET var qUserInfo="">
   
   <CFIF IsNumeric(Arguments.UserID)>
      Run query to get user info based on numeric userid
      <CFIF qUserInfo.RecordCount>
         <CFRETURN qUserInfo>
      <CFELSE>
         <CFRETURN "no user for this user id">
      </CFIF>
   <CFELSEIF IsSimpleValue(Arguments.UserID)>
      Run query to get user info based on numeric userid
      <CFIF qUserInfo.RecordCount>
         <CFRETURN qUserInfo>
      <CFELSE>
         <CFRETURN "no user for this user name">
      </CFIF>
   <CFELSE>
      <CFRETURN "Invalid user info message passed">
   </CFIF>
</cffunction>
This method will either return a query 'object' (data collection) to the calling template or a string with an error message. It is up to the calling template to decide what to do with the 'message' being returned from the method.
So basically duck typing is where a message is sent to a method, the method deals with the message and then returns a message to the calling template. What makes it different from what your doing now is that there is no validation of the data 'types' being passed in or out. Focus is on the data being passed, not what type it is.
This was my understanding of Duck Typing and I was told I'm on the right track, but not exactly. Problem is, the example I was given still has me confused as to the specifics. As soon as I have a clean and clear understanding of the subject, I'll post it here.

BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Blog Owner
House of Fusion | ColdFusion Jobs @ House of Fusion | Fusion Authority