Remember Two Things

Yesterday I learned two new things.  You may be thinking ‘just two?’ or ‘really, only two?’ but this is just two things as related to the job I do most days.  The worst part is, I feel they’re really basic things that I’d just been overlooking, and now feel like kicking myself, but I won’t, because that wouldn’t help matters.

The first one was just something new about the coldfusion tag cfmodule.  Dreamweaver and CFEclipse (CFBuilder too I suppose) show up with these code complete tags so when I type in <cfmodule (and the space that I can’t show in text very well) and then a list of optional tags pops up.  One of these is ‘attributecollection’ which I’d never thought about using before until I realized what I could do with it.  I can pass through a structure of arguments, like a form.  Genius, why I didn’t see that before? I don’t know.  I guess I  wasn’t paying attention.  Anyway, I can pop in a module that can process my form action easily like this: <cfmodule template=”mymodule.cfm” attributecollection=”#form#” /> and then inside the module, I would just have to reference the form fields as attribute fields with the same form name.  Simple and lovely.

The second thing I learned was the value of cfcomponent “extends”.  No not the herbal supplement.  Now it’s not that I didn’t know that I could extend cfc’s, I just never really thought about the purpose of doing so.  I’ve used the extends in building application proxy cfcs to extend my application.cfc file down through directories, but I never made the really logical connection as to what it does.  I like the idea of encapsulation, such that no cfc should ever have to call an application or session variable within itself, that the information should be addressed through arguments as needed. For many projects now I’d been through the application variables that tell cfcs what datasource to use.  This means every cfc init call I’d pass through the dsn, username and password ( I found another duh a few months ago where if the datasource is defined in CF Admin, you don’t need to pass through the username and password, just the DSN, but yeah…).  It got tedious.  Then I’d have to set up functions in all my cfcs to set and get these items and it seems like I was writing the same code over and over (ok, copy paste, but still).  Here’s where the genius of extends comes in handy.  I make one cfc that just takes care of the db connection information and I can extend that in any of my cfcs that need db info.  Then all of that get and set garbage is all taken care of for me and I can just call the functions as they were native to the cfc.

I know both of these things may seem really basic to the average CF user, but when your main focus every day is just to get product out the door, sometimes innovation takes a while. You learn what you need to when you need to and there the occasional ‘aha!’ moments that you feel like facepalming yourself, but it’s the way things are.  Many people in my position want nothing more than to learn (or maybe just to know EVERYTHING) which is why we actually like our programming jobs.  It’s days like yesterday that remind me of that.