The Dopefly Tech Blog

Join Nathan Strutz as he shoots the breeze on techie geeky web dev stuff.

July
   1234
567891011
12131415161718
19202122232425
262728293031 

The Easy Super-Bean

posted under category: ColdFusion on June 8, 2009 at 9:54 pm by MrNate

With CF being OO enough, beans can have a super-type, a common base that all beans share, like genetics for business objects. It's easy to make one.

<cfcomponent extends="superbean">
But what do we put in there?

My biggest hatred about beans is the getters and setters. It's a lot of typing. If you have snippets, that helps. If you have a bean generator, that's better. It's also a big problem if you have to change them (think: adding logging, validation, etc.), or worse re-generate after you've added custom code. So the way to fix the whole lot of these is employing ColdFusion 8's OnMissingMethod.

I know we've seen it before. My favorite probably comes from Kevin Roche's Abstract Object post. That's basically what I'm playing with.

In my playing around, I've got a base bean with an onMissingMethod defined that will catch getters and setters. Here's an illustration:

Illustration of bean hierarchy - generic base bean with concrete type

The _genericGet() and _genericSet() methods were added so that any extending bean can, say, overwrite just the setter for all the properties in a bean or a parent type of another bean. In fact, I would recommend that overriding coders "decorate" the _generic methods, calling the super-action before or after any custom operations.

Benefits of this design, other than the obvious lack of need to type getters and setters, is that the concrete bean can hold any property, plus, I can rename the getters and setters to obj.Name("Nathan").name(); which would return Nathan - somewhat of a jQuery style trick. Another cool thing is that if you wanted to create your own getter or setter for a property, the _generic methods will search for your function and call that instead.

To illustrate:

(in component user, extends BasicGenericBean)
function getName(){return "Bob"}

(Outside, calling methods on the object)
user.setName("Nathan");
user.getName(); // returns Bob

Also, I added an init() constructor method that will populate the bean's properties with any arguments passed in.

Taking the design further, I wanted to let the developer specify what properties the bean has via the cfproperty tag.

<cfcomponent extends="GenericBean">
<cfproperty name="Name" type="string" />
</cfcomponent>

user.setName("Nathan");
user.setNumberOfGoats(16); // throws error: NumberOfGoats does not exist in User.

Then, I thought about adding some optional subtypes for the generic bean. What if I want to track the history of changes to the bean, so it would be easier to do a database update? What if I wanted to put the database update right in there, in a very generic way? This is completely possible.

Illustration of bean hierarchy - base bean, history tracking bean, database enabled bean, with concrete types

So there's my design, something to play with at least, and maybe base your model on too. Download the files all together in 1 zip with some test front-ends just to see them in action. CF8+ only! Download Nathan's Super Beans.

(0 comments)

Where is the ColdFusion+Java application model?

posted under category: ColdFusion on June 5, 2009 at 9:08 pm by MrNate

What happened to the early days of using Java as the model for a ColdFusion-based MVC application? We used to talk all about CF w/Java but I don't hear it anymore. At best, it's rare. I like to keep my ear to the ground in the CF world, and this one has quietly slipped off the radar.

I guess there are only a few likely demises:

  1. The buzz has faded and we all forgot about it
  2. It's being used everywhere and no one talks about it anymore because it bores us
  3. Java is too hard to write for the average CF programmer
  4. The integration is too bothersome, the gain is not worth overcoming
Regardless, it probably comes down to the fact that some shops have done it, and are now quiet about it, the rest ignore it completely. So in order to spur on the conversation a little, to see what went wrong, see if it's worthwhile anymore, and dream about what it could be, let's think for a bit...

OO ruined my business
A good amout of the conversation lately has been that OO is too hard and CF's implimentation of it is too awful to use realistically. I don't actually think so, but it does limit us some. Hal Helms's main argument is that the computation costs of instantiating CFCs is too great, and I agree, it slows down after a few dozen objects, and crawls after a few thousand. Multiply times 5 if you have execution time debugging on. Obviously Java's implementation of objects doesn't have this issue, especially with POJOs, the simpler the better.

So what if the solution to Hal's problem is partially using Java? Even if it's just for those objects that we might create thousands of instances of, the improvement could be huge.

That's possible today, but it's not as simple as we need it to be.

Dreaming
We know that in CF, createObject("component","com.myCFC") will make ColdFusion to check a variety of locations for that object. First one it finds, wins. What if you could just create a .java or .class file and call it in the exact way you call a cfc using CF's smart path finding senses. I'm honestly surprised that we can't do this yet. For me, personally, this would quickly and easily bridge MOST of the gap.

Failing
The problem actually runs much deeper even. Say I want to use my CFCs to run queries. I don't want to hunt down JDBC drivers. I don't want to script my sql calls. I don't want to worry about a thread pool and persistent connections. I don't want to work too hard. I just want to say <cfquery>select * from my_table</cfquery> and have it work every time. CFQuery is and always has been the killer feature of ColdFusion.

So I like my data access layer in CF, but maybe I want my services or beans or what have you in Java, for speed. I want to call myService.getMyData(). The service calls a cfc to get the data, then populates a bean or returns a query or whatever. Problem is, Java can't call methods on a CFC! No, I'm not kidding. Try it. Oh, and yes, I know about the cfc gateway, an asynchronous method for Java to call CF - and no, that doesn't count. Yes it's great and powerful, but that's just not it.

Purgatory
So it looks like the only way to truly integrate Java into our CFC model is to either replace, package-by-package, entire areas of your model-or the entire model-, or only provide one-way objects, that is, Java objects that will never need to call a CFC or anything in CF at all.

Replacing your model is doable for some shops, especially with large Java teams, and is probably indispensable for a handful of them. For the rest of us, we just love our precious cfquery! I think the real heros in this space seem to be Barney Boisvert, who is always blogging about integration with hibernate and groovy, and Mark Mandel with his JavaLoader project.

The one-way objects may work pretty well, but then we've got the classpath and instantiation annoyance still.

The way I see it, integrating Java with your CFC back-end is broken, and it's going to take a lot of "brilliant" (yes, a dig at Adobe marketing) to make it work.

(0 comments)

Microsoft is on fire

posted under category: General on June 4, 2009 at 8:14 am by MrNate

Somehow, Microsoft is the new hotness, hitting nearly every shot they throw out there. According to my favorite game (well, from 1994) NBA Jam, the're on fire.

Windows 7
It's Vista. It just is. It took like a year for them to make it, which is nothing in comparison to Vista's decade dev cycle. They didn't re-do anything, and it's not faster, but the fact is, it's what people want, and they're loving it. The only negative things I've heard are from those who are trying to run it on their macs. Hah!

Bing
Stealing, err, rebranding basically everything from Live Search, Microsoft comes through with a word that people like ("Let me Live Search that for you") and a searching experience that, for some unknowable reason, people like. Google may have the first competition since destorying Yahoo all those years ago. Personally, I'm not convinced, but people are talking.

.NET becoming superior
The programmers have been the core of Microsoft for a long time, but it wasn't until the recent .NET framework 3.5 (and service pack 1) that they gave them Linq and MVC. These tools are finally something on par and superior to the competing Java platform. The quick movement of both C# and VB.NET have thrown these languages much closer to the top of the "cool" stack.

XBOX 360
Ok, second to Nintendo's invincible Wii is a fantastic place to be. The recent exclusive content is a real winner, and the games are head and shoulders above anything from Sony, aside perhaps from Little Big Planet. Further, their just-announced Natal project, which essentially gives you the Minority Report interface for your TV, is just, well, "Ka-boom" (in my best NBA Jam announcer voice).

Of course Microsoft has a number of smaller successes, things that have really started to go right but aren't as big. The XBOX update with mii-like avatars, Netflix on the XBOX and Media Center, and the re-invigoration of the browser war, giving us IE8, which, if nothing else, sucks less than IE7 and 6.

That doesn't mean everything they do is the bomb. I'm not about to go out and buy a Zune or a Windows Mobile phone, I'm just making observations.

(0 comments)

Calling functions with a dynamic name

posted under category: ColdFusion on May 27, 2009 at 11:12 pm by MrNate

For a while now, the CF community has been stumbling around the concept of calling a dynamic function. Well, as it turns out, ColdFusion is more functional that it may seem on the surface. Let's have some fun with what, at first, seems like a difficult problem.

Let's say we have a method that receives the name of another method as an argument: myStaticFunction("myDynamicFunction"). Now what? First, here's the methods (I haven't checked any of this, so let's call it pseudo-code.

function myDynamicFunction(){return true;}

function myStaticFunction(methodName) {
methodName(); // fails for calling a string like a function
variables[methodName](); // fails for a syntax error - []() = bad cfml!
// umm, now what?
}

So here we are in the same old spot. First, the old school method, the one easily turned to in time of need, the cfinvoke tag. Personally, I dislike the cfinvoke tag. It seems to take me out of my flow. It ruins my mojo. It's like longhand syntax for CF - it's somewhat of an oxymoron. Nevertheless, here's what you would do:

<!--- First, note that we have to rewrite it in tags. Not awful, but I dislike the switch. --->
<cffunction name="myStaticFunction">
<cfargument name="methodName" />
<cfset var methodResult = "" />
<cfinvoke method="#methodName#" returnvariable="methodResult" />
<cfreturn methodResult />
</cffunction>

This works, but there's got to be a better way! There has to be a less cheap way, something without all the #'s and stuff. And there is:

// back to cfscript, yay!
function myStaticFunction(methodName) {
var method = variables[methodName];
return method();
}

That's much more like it! Of course this assumes we're in a cfc or something, where the method is in the variables scope. Now, what other magical things can we do?

Well, I wasn't going to share this one until the next entry, but since you're talking me into it, here it is with onMissingMethod, dynamically calling a method with dynamic arguments. This onMissingMethod attempts to call a getter when you just call the property - in other words, user.name() will be automatically translated into user.getName(), to give you a nice jQuery type of syntax:

function onMissingMethod(missingMethodName, missingMethodArguments) {
var f = 0;
if (structKeyExists(variables, "get" & arguments.missingMethodName)) {
f = variables["get" & arguments.missingMethodName];
f(argumentCollection=arguments.missingMethodArguments);
} else {
// choke!
}
}

(2 comments)

Cheating with the 'ol dynamic language function alias trick

posted under category: ColdFusion on May 8, 2009 at 11:08 am by MrNate

One of my favorite little tricks to play with CF, and with other dynamic languages like it, is aliasing function names.

Let's say you have a component, User, and a method, getIsUserNameValid(). It's a "getter" in order to satisfy some other kind of style requirement, but writing it out is verbose and feels wrong:

if (user.getIsUserNameValid()) {...}

You have to leave it as is so you don't break any existing method calls, and to keep the basic style guidelines, but what if you could cheat a little? Consider this:

<cfset variables.isNameValid = variables.getIsUserNameValid />
<cfset this.isNameValid = this.getIsUserNameValid />

In ColdFusion, this creates an alias in the private "variables" scope as well as the public "this" scope to the old method. Now you can change your call to:
if (user.isNameValid()) {...}

(0 comments)

Start Eclipse faster with -initialize

posted under category: IDEs and tools on April 10, 2009 at 1:46 pm by MrNate

There was some good discussion today on the CFEclipse Users email list about getting Eclipse to start up faster, and I offered this suggestion:

Run this command when you log in to your workstation:

eclipse -initialize

According to the most complete reference I could find on Eclipse's command-line arguments, the initialize command:

Initializes the configuration being run. All runtime related data structures and caches are refreshed. Handy with shared installs: running Eclipse once with this option from an account with write privileges will improve startup performance.

The emphasis was mine, and for good reason. It really works!

In a very cheap experiment, using the windows clock as my stopwatch, I closed my open Eclipse (version 3.5, galileo M6), waited about a minute, then started it again. My PC took a full 60 seconds to load my workspace again.

I closed it, and called eclipse with -initialize through a windows shortcut. The initialize command doesn't really seem to do anything, and it took about 5 seconds to complete. After that, I waited 30 seconds and started Eclipse again, this time it took 16 seconds! Closed it, started it, 16 seconds again!

I guess I would have to reboot to get a cold start time, which is more than I'm prepared to do for today's little blog post. I really don't know what -initialize does under the hood, but wow, what a difference it can make.

(0 comments)

Managing your application's emails

posted under category: General on April 2, 2009 at 9:13 pm by MrNate

Here's a recurring problem I've discovered. Many, if not all, of my applications send email, and they tend to do it in an unmanaged, un-object oriented type of way. For instance, if you comment on this blog entry, I and other subscribers are sent an email. The template for this email is tucked away inside a CFC, right below where I insert the record into my database. This, of course, is a problem that can be solved in a repeatable, managed fashion.

I have actually solved this problem before at a previous company I worked at. Obviously all of that code is under lock and key, unusable due to NDAs and basically unethical anyway, so instead, I am planning on recreating something like it, but better, from scratch. Hey, if nothing else, I'll just use it on this blog. Of course I'm talking about open sourcing it - why would I tease readers with a cool toy, and not share it?

Overarching idea: A reusable open source library and API for both the management and sending of emails via templates.

Basic requirements:

  • Manage storage of email templates (CRUD basics, consider varying storage options)
  • Allow dynamic variables in email templates (Dear #user#)
  • Create basic administrative UI, key on easy integration
  • Create simple API for sending email

Groupthink questions: Does anyone else do this? How do you solve it? Why have I not heard of anyone else doing it?

Final thoughts: Sending email from your application is a scenario that I see often, and can be handled by an administrative managed, reusable application. Move your email templates out of your code and reduce the complexity of your application.

Oh, and I don't have a name for it yet. I'd hate to call it the Email Template Manager or something stuffy and boring.

(1 comment)

My experiences working with Google Docs Presentations

posted under category: General on March 5, 2009 at 7:47 am by MrNate

I gave a recent presentation for the AZCFUG on Ant and Groovy. One interesting point about it was that I used Google Docs to do the whole presentation, including creating it, presenting it and publishing the slides the next day. Here are my thoughts, weighed out in a pro / con table.

The BadThe Good
Lack of fancy special effects or animations, only a single text fade in effect.No eye-gouging awful effects, the text fade looks nice.
Somewhat slow editing, just due to the fact that it's online instead of local, and it's HTML and Javascript instead of a native desktop application.Not so slow that it matters, will improve with the faster javascript engines coming in 2009.
Also, the features keep coming as the tools improve, no need to wait for the next $900 release of MS Office, incremental changes are just weeks away.
Have to be online to use it.Collaborative editing, collaborative viewing (I didn't use either of these, but may, in the future). Can access the presentation from anywhere on the internet.
Presentation mode has awful white lines on the top and right side, and a black utility bar at the bottom (I was using Firefox).The fact that it even has an online presentation mode is great.
The utility bar is very handy, not terribly in the way.
Can't control the presentation next/previous from the presenter's screen (when presenting with dual-screens). Controlling the presentation on the primary screen requires clicking on the slide, where the cursor gets in the way, or by clicking on the arrows in the lower left corner. These arrows can get in the way of the content. Either way, I would rather not have the cursor on the presentation screen at all.Speaker notes pop up in a separate window for dual-screen presentations.
Unlike Flash's full screen mode, it doesn't go back to the embedded size when it loses focus.
Unlike QuickTime or other embedded media players, it is very predictable.
Published slides required an iframe tag on my HTML Strict doctyped web site. Would have liked to foce visibility of my speaker notes on the published embedded slideshow.Published presentation was 1 line of HTML and was all HTML based (as opposed to Flash). Can publish on a web page, but viewers can get closer and use the full-screen view, see the speaker notes and even download it.
Exporting to a PPT file lost my gradual loading effects (eg. show 1 bullet at a time).It can export to PDF and PPT with fair enough quality. I had done this for a just-in-case-the-internet-fails backup. Plan B would have been degraded, had I needed it.
Less features than PowerPoint.Less annoyance than PowerPoint.
Had all the features I needed, not much more to get in my way.
It was evident, in stark opposition to PowerPoint, that this was about content and presentations, not about useless frustration, lining up pixels or worrying about fonts.
Limited design templates.Current template selection was adequate, I found one I liked.
Minor UI annoyances:
  sometimes wonky box selection
  smallest font size too large
  limited link type selection, no linking to slides, documents
  no shift-drag for straight line object moving
Great UI examples:
  drag & drop slides
  context menus always had the right actions
  so solid and easy, I didn't even consider using the help system
Interface was not customizable like MS Office, move toolbars, etc.Not bothersome, as it felt so good that I wouldn't want to change it around.

Overall, I had a great experience. Google Docs is constantly moving forward and this latest version of their presentation system was fantastic. I will definitely be using it in the future.

(0 comments)

Run Eclipse from your portable USB drive

posted under category: CFEclipse on February 28, 2009 at 10:04 am by MrNate

I've got to admit that running basically everything from my USB drive is really nice sounding. Portable everything. I love PortableApps.com. Let's talk about running Eclipse portable.

Step 1: Download Eclipse, extract to portable drive
Step 2: Download Java, extract or install to portable drive
Step 3: Make a new workspace folder on the drive
Step 4: Rig up a batch file or shell script to run it all together. Here is what it needs to have for windows:

start-eclipse.bat
-----------------
@echo off
cd eclipse
start eclipse -vm ../java/bin/javaw -data ../workspace

You'll see it may take only a few seconds longer to start than running it off your HDD.

Once started, you can import your projects into the workspace, add plugins and do your work from right there, all completely self-contained.

I did this initially for my Ant/Groovy presentation. I had my presentation online with Google Docs, and my demos from the flash drive. The idea was to use somebody else's PC, come with nothing to install and leave with nothing to clean up. It worked almost perfectly -- Alan had warned me about his PC, but when I ran the live demo anyway, Ant froze, Eclipse crashed, and I was out of time. Bummer! Anyways, not to detract from the subject, it did work on 3 other PCs. I'm just giving out creative ideas here.

Of course, if you're like me, to use this as your main IDE, you'll want a web server and something that runs CFML. I'm not there yet, but I know some other folks are doing just that.

(0 comments)

Build Automation with Ant & Groovy, presentation slides

posted under category: AZCFUG on February 26, 2009 at 7:54 am by MrNate


If you follow the fullscreen link, you should be able to see my speaker notes as well, which my help tie the concepts together. If you want to see the demos, you MUST turn on the speaker notes.

(0 comments)

The SQLSurfer build process

posted under category: Software Quality on February 20, 2009 at 7:53 pm by MrNate

I have this open-source toy project I've been playing on, SQL Surfer. It's a little web-based SQL IDE with an amazing build process. How could I not share it with you?

The idea was pretty simple. When I work on my program, I want to see it like a normal program, multiple files, separate CSS and JS, included cfms, conditionals based on the server version, but when I release it, I want it in one, single file: easy to distribute, easy to throw on a server, no install, no folder structure to preserve, no dependencies to remember. It seems that basically no one has ever done this, but it's not too difficult.

The way it works, is, when I get to a point of wanting to make a release, I just run the Ant build file. One click. Ant does what it does best, preps the build, cleans out the output folder, in the end, it zips the results and whatnot, but I couldn't pull off the dynamic file embedding with plain Ant XML, so that's where Groovy comes in. I've got Groovy searching for included files (cfinclude, script, style, etc) and embedding the files in place of including them. Plus, while I was mashing files together, it seemed logical to compress them, even if just a little.

The result is a mashup of my entire application, nearly obfuscated into a single, gigantic, single-file, working application.

Actually, it goes a little further still. I wanted to have a version to take advantage of ColdFusion 8's new <cfdbinfo> tag, which, by the way, is awesome, but I also wanted to stay compatible with CF 6 and 7, even with a lesser experience. When you type a new CF tag into an older version, you get a compile error. That makes it hard to develop and hard to release. My solution was to drop in <cfif left(server.ColdFusion.productVersion,1) GTE 8>, followed by a cfinclude, css or js reference, then, Ant makes 2 files for 2 releases and my Groovy build file has 2 functions, removeCF8 for removing the if blocks, and removeIfCF8 for just the if statements and embedding the files.

The actual result is 2 files, all mashed up and working perfectly for different server versions.

Going overboard, I also embed EditArea, for the code editor. Of course EditArea doesn't care about an all-in-one-file project. I use Groovy to insert EditArea into the main file as well as change EditArea itself, at build time, to point to the embedded parts in the CF application instead of its own directory structure.


Taking it beyond reality, I realize now that I could probably include a framework like Barney Boisvert's excellent FB3 Lite, and then potentially images in b64. The only challenge that this approach leaves me with is CFCs. I love my objects, but I haven't figured out how exactly to embed them.

Ouch. Even just typing that last sentence makes my head explode with ideas. Taking it way too far, I could probably embed the components I use onto the main file, stripping out the cfcomponent tags, then to recreate them, create instances of the generic coldfusion component, WEB-INF.cftags.component, and re-constitute them with duck typing and method injection... Yeah, maybe some day, if I get really into it.

You can check out the source code right now and compile it yourself, but to hear about it first hand, visit the AZCFUG Feb meeting, 2/25/09, where I'll be showing it off. If you miss it, don't sweat it, I'll have the slides out by the next day. I'm undecided on having a connect meeting for it. If we choose to, I'll post it up here.

(0 comments)

AZCFUG - February 2009 meeting - Skills Month

posted under category: AZCFUG on February 17, 2009 at 6:03 pm by MrNate

Yes, it's a week from tomorrow. Alan & I have had some trouble getting speakers, but we need to have some get-togethers still, so let's do it.

Wednesday, February 25, 2009 6:30 PM, UAT main theatre room.

We're calling this "skills month."

Presentation #1:
Alan Rother, AZCFUG Manager: Intro to XPATH
Alan is a Senior Applications Developer at Interactive Sites in Scottsdale, juggling the application development of dozens of high profile sites for the hospitality industry. Also, he is insanely smart, so this will be good (no pressure here, Alan). Alan's presentation will run around 30 minutes and will take you from little-to-no knowledge of XPath to some actual applicable knowledge that you will want to use.

Presentation #2:
Nathan Strutz, AZCFUG Manager: Build Automation with Ant & Groovy
Nathan is a serious coder at The Boeing Company in Mesa who hacks on internal web 2.0 style applications, usually with his headphones on and nose buried in CFCs. Nathan's 25 minute presentation will discuss build automation with Ant, and some creative ways to use it. You'll like it.


We have a potential speaker for next month, but would love to fit in another short presentation if anyone wants to give it. As I said before, it doesn't have to be anything cerebral, and it doesn't even have to top 5 minutes. We'll be bugging you all about this, pretty much forever, so you might as well give in now :) Also, remember, presenting for the user group is a great resume item, and a great way to get your name out there.


As usual we've got the typical schwag giveaways (Somebody, please take our CF8 posters!), and we will most likely meet up at Aunt Chilada's after the event. Check the UAT map here.

More information is online at the Phoenix ColdFusion User's Group site and the AZCFUG Adobe Groups site.


Immediately following the AZCFUG presentations, the AZFPUG (Flash) group has a presentation lined up with Jason Crist, who will talk about the Facebook AS3 API, starting at 7:30 PM. You're invited to stay, but I will probably hit Aunt Chilada's before that.

(0 comments)

Having other projects

posted under category: AZCFUG on December 24, 2008 at 12:51 pm by MrNate

I know a lot of us out in the general work force really do a lot of work, and some of us put in way more hours than is healthy, but with the holidays being upon us, I'd like to suggest one thing: have other projects.

By other projects, I mean a personal project or an open source project where you can do what you do best, whether that's bean counting, programming or technical document writing, do what you do best and what you love to do (or at least loved to at one point), and do it on your own time outside of work. In having this other project, you give yourself a number of great opportunities.

First, you get freedom - be creative, do it on your own schedule, do it your way. Freedom ignites the passion you have for what you do. At work, you conform to rules, legacy problems, people problems, and things that make what you do not fun. Freedom from that structure makes things fun, and you can bring that fun back with you to your job, something everyone will appreciate.

You also get learning opportunities that you would never have when you're slaving away for a dollar. They want things done their way, and you have 2 hours to do it, while on your own time, you can try something new and it doesn't really matter how long it takes you. Be creative and come up with the best solution. Once you get there, you've probably learned something new. Keep at it until this becomes a point on your resume.

For me, I typically learn new programming frameworks and languages, and try creative methodologies that initially sound like they could never work. This eventually trickles down to work for me in ways that I thought never would. One of them was quite tangible in getting me hired at better places - the more I know, the more people want to hire me, and the more money they want to give me. I honestly didn't expect that. Strange, I know, I'm a little dense.

One of my pet projects is doing little things in C#. I find it fun and can't explain why. Playing with C# has made me a better programmer in general, as well as it has been able to solve some relevant issues in my day-to-day work where I use it for utility chores and small projects. I'm not saying that C# should be your project; I'm just throwing that out there.

At one previous company I worked at, one of the interview questions was about extra, non-work programming projects. This was literally one of the measures of how serious a candidate was at programming - if it was more than just a chore and if it bled over into a way of life. Lucky for me (... ?) you can almost never find me far from a keyboard, hacking away at something.

Finally, with completed projects, there's always the chance to monetize them one way or another. You never know if the project you've been kicking around has million dollar potential until you've put some real work into it.

Let me suggest some projects to get you started. If you like starting new things, make a personal web site, or one for your family. Be creative with where things come from (like Photoshop & Illustrator for design, your Flickr account for content, etc.). If you have one, be improving it. If you make something cool along the way, consider open sourcing it. If there's a tool you always wanted to use, make it. If there's some boilerplate code you keep re-typing on each project, make a real tool or framework out of it.

If you don't like starting new things, download code from an open source project, make a few improvements and send them in. Open source developers LOVE this. If they don't want to take the app in the same direction you're going, fork it and start your own project. This is a great addition to your resume as well.

In conclusion, I'm urging you to get a personal pet project of your own, or a few. It's good for everyone, most of all, yourself.

(2 comments)

The problem with Microsoft's software platform

posted under category: General on December 19, 2008 at 11:22 am by MrNate

I've got a fever, and the only prescription is a bunch of ranting run-on sentences...

See, here's the problem with Microsoft's software platform, especially relating to ASP.NET, but they keep doing things like this: they went from having no MVC, where web sites feel like desktop app programming, except with HTML, which really just makes no sense whatsoever and is a retarded paradigm to program for even though they pulled it off fairly well even from the first version, to finally having some basic MVC support; things that the rest of the programming universe have been doing and loving, where they finally addressed the issues where they just suck at, acknowledging that maybe all the programmers out there in the world are smart and are basically right and that the feeling of needing to make maintainable applications that aren't ridiculous to update and work with and acknowledging that letting the developers do the HTML, CSS and Javascript to do their web-based apps might be a good thing because after all, they probably work on a team with designers and deselopers and the like and the developers have to eventually be sick of the stupid paradigm of being forced to use ASP.NET's web controls and having those things write all their tables and login forms because the code those output just really sucks and they can't get in and fix it and make it look like the designers really wanted without sacrificing a lamb, by introducing ASP.NET MVC late last year, which would finally let Java programmers in, and maybe even ColdFusion and Ruby guys as well because they can all do MVC even though ASP.NET couldn't, and would also just make the platform much more approachable by traditional web developers who understand the request/response model and who like to get their markup right enough to validate and who are always annoyed by Microsoft's web stack getting in their way because there's only 3rd party support for making a normal web site instead of postback and having the whole page be a form, which again, makes no sense, ok, from that, straight into the ASP.NET MVC Design Gallery, where the traditional ASP.NET desktop software developers - and yes, I said they make desktop applications in ASP.NET because there's no other real excuse or explanation for what you're doing when you work with ASP.NET except that you're posting back and responding to events exactly like a desktop app in visual studio where you double-click on a button and write a codebehind action for the click event where it makes sense for desktop applications but falls utterly flat on the web unless you actually are doing something special with the button's onClick event like popping up a 'loading' image so the user doesn't hit the link again - now they can download and apply a pre-made design so that suddenly your MVC app is friendly, and you don't really have to do HTML and CSS because that's for web people, and programmers aren't web people, they're programmers and shouldn't have to learn html because it's somehow too difficult to understand for a programmer because after all, the programmers doing ASP.NET and dragging their little web controls onto the stage and shying away form the HTML probably actually are too slow to learn something as 'challenging' as the div and span tags, or at least Microsoft has somehow formed the permanent opinion that they are and they coddle their developers and pet them on the head and say "it's alright, you don't have to do HTML." If you commit your life to programming on the Microsoft platform, I would pretty much promise you that you will never have to learn HTML, Javascript or CSS, just C# or better yet, VB because then you can do vbscript too and program in classic ASP or make windows scripts and macros for Excel which is really all your business wants anyway. Imagine a programmer who never learns anything about what they're doing or what platform they're working on, then imagine armies of them crying and whining until Microsoft gives in and releases something that takes them from zero to hero, but you have to do it this one certain way and whenever you deviate off the path you're out of range, even for some clever googling because no one else has ever gone that path and that error number is so obscure that Microsoft would really rather that you never saw it so the MSDN page for it says something about how to get back on the right course because you tried to change the font tag to a span with a class and they didn't expect you to know what you were doing so you should leave it because, after all, IE v.16 still supports the font tag even though firefox had disbanded it 22 years after the standards committees threw the tag out and they figured no one would actually have software that generated a font tag because that would be ludicrous.

Dear Microsoft, make the developers on your platform grow some brains and learn a little about HTTP and a little about forms and links, where the Javascript goes and where CSS fits in, and how to write a multi-page form without postback (even though postback is a clever solution). See, it's too hard to know why we would implement a pattern (like postback or MVC) until we've suffered without it. There's no reason for an ASP.NET desktop programmer - yeah, i said it again - to switch to MVC (other than it's new and now has a design gallery) because MVC doesn't solve any of their problems, and MVC is better for making web applications that work together and have reusable parts and are well managed but it's not so good for just web pages, and who knows, I'm sure there will always be a market for those end-developers who really just want a web page with a login form and a table from the database and they want to call it an application even though the only cohesion it has with the rest of the pages is a link to another page and it has no reusability or management from the standpoint of the application as a whole and all the code is on the page or in a partial class which might as well be on the page except that now you have to have 2 files open in visual studio as if to prove the point that Microsoft is always trying to solve the wrong problem. Maybe if you allow ASP.NET to really be a part of the web instead of this alien spaceship that visits the web when it feels like it, then we'll drop some of the dead weight out of the programming chairs, as if the programming industry could downsize itself based on IQ, or better yet, it would let people learn some of what's really going on and how technology works and would excite them and make programming on your platform as fun and rewarding as we all know it can be like when you solve your first big problem and even though your manager wouldn't ever understand the programming difficulty you just overcame, you know you did it and you did it well, and it's 4:50 Friday afternoon so you can free your mind to have a relaxing the weekend and everything just feels right.

I like ASP.NET MVC. I really do, but I do not think it should be the first point of entry for a new developer getting into web development. I even somewhat like ASP.NET and web forms, although, I suppose in another way, I also despise them with the fire of a thousand suns, so it's maybe 50/50 what I'll feel depending on my caffeine intake for the day, but I don't think ASP.NET and web forms should be a new web developer's entry point into web development. It just isn't right. What is right? JSP is close, as it's still fairly modern and can be upgraded into an MVC pattern (many frameworks are available) as the developer matures, except for the complexity, specifically with getting your server up and running, and learning about beans and stuff, it's just overkill and that is a rant for a different day. PHP would work, except that when you look at the language you see C versus Perl with an out of control language library that could choke three camels. Ruby on Rails is a magical UFO that does MVC - too much code generation that hides what the world wide web does, not a good starter. Classic ASP, not really a language as much as a lightweight platform, and it's coupled usually with vbscript, I would say avoid it because, while not technically end-of-life, it hasn't seen any activity since ASP.NET came out in 2002 and is no longer considered modern. That leaves us with ColdFusion, which is perfect with its syntax that's similar to HTML and javascript without performing any type of web magic that can't be deduced by just looking at it, easy debugging, easy database connections, the ability to move into object oriented concepts and some well supported frameworks that give you as much MVC as you can wish for. As much as ColdFusion is touted for its ease of programming, it also doesn't hide the real web from you - it just makes it easy to get to.

(2 comments)

ColdFusion and the Session Facade

posted under category: ColdFusion on December 14, 2008 at 9:07 pm by MrNate

We've heard it, we may have seen it in action. If you have ever asked yourself "why," this is for you.

(BTW, I'm just going to call it a "facade" because "façade" is too difficult for my keyboard to produce)

The Pattern
A facade is a fake front, like a mask. A session facade hides away the "complexity" of using a session.

The session facade is the point-of-contact for your session variables. Using one, we no longer have a session scope that you can talk to, now we talk to the facade. The facade offers basic bean methods with generic names - get(), set() and delete(), or a variation on the theme.

Dave Ross has pretty much the definitive ColdFusion Session Facade article (2 pages worth and sample code) - how to use it and all. I'm just considering the usefulness of it.

That sucks
Instead of #session.username#, now we can just type #application.objectFactory.getBean('sessionFacade').getData('username')# and the session facade will handle the dirty work of typing the scope name "session" for us. Finally, more typing!

So now that we're typing more, we also have to learn a new API for managing the session scope. What if we use get, put and delete methods and our friend Bob Bobbery uses get, set, remove, clear, search, etc, etc? More to learn equals more complexity.

And what problem exactly did this fix? We had a session scope before, and we technically still have it. Nothing forces the bad coders on our eam to use it. Nothing really changes, assuming the facade just gets and sets variables from the session scope. It just added another CFC to manage and a bunch of extra code.

The final problem is that the session facade doesn't do anything to manage the session, to organize it, report on it, fix problems that could occur or reduce complexity. It's typically just a dumb bean with variables.* replaced with session.*. It's useless.

Oh, that might be cool
We programmers are managing change. That's one of the things that we do, and hopefully, we will do it well. What if the session scope goes away... no not likely, but with a session facade, we have the mechanism to manage every variable in and out of the session scope. We could reroute it to a database.

The session scope could disappear due to an administrative switch. On a hosted server, we may have no choice. The session facade could then be changed to get essential data from the database at every request.

What if, to reduce server memory, we want to put certain variables, or certain types of variables in our database. The session facade could be made to leave some things on disk, some in memory. A little brains can be added without touching the rest of the application.

What if we want to write a log event every time something goes in and out of the session scope? The session facade is basically our only option for this. The only other way would be to search our code for the word 'session' and add a cflog on each event. With a session facade object, we can do logging or any other type of thing all in one place. Not bad.

Perhaps we may want to cflock each session access because of some potentially unsafe code reading and writing to one variable - we can do that easily here by exclusively locking the set method and readonly locking the get method, using a unique session key to name the lock.

In summary
In summary, the choice to use a session facade should be based on the risk of drastic session scope change. The benefits seem to be a lot of 'what if' scenarios, but they could happen, maybe, while the drawbacks seem to pay off right away. Laziness now or laziness later?

(8 comments)

AZCFUG December 2008 - Casual Wednesday

posted under category: AZCFUG on December 10, 2008 at 10:45 am by MrNate

Hey everyone in the Phoenix valley - This month's AZCFUG meeting is going to be super-casual. We're going to Aunt Chilada's in Tempe next Wednesday, the 17th at 6:30. As usual, we will probably be out back somewhere, so look around until you find us.

There's an official post at our Adobe Groups site with a little more info.

The agenda? Nachos, the user group and giving away our schwag. Buy your own drinks, but bring something to say about the CFUG.

I'll get you started.
"I think one cool idea for a meeting next year would be __________."
"I think Alan would look better if his hair __________."
"I think, in regards to virtual presenters, we should __________."
"I would like to do a presentation on __________."

Oh snap, did I just involve the community?

(0 comments)

Why precisely is it important to var-scope your variables?

posted under category: ColdFusion on December 9, 2008 at 8:51 pm by MrNate

We've all heard it a thousand times. "VAR YOUR VARIABLES !" But why? You say, "I've never had that problem" and I'll tell you what, you probably wouldn't know it if you saw it. Pay attention here.

Let's take a simple ColdFusion function, easy stuff here. Dead simple.

<cffunction name="runMyCode">
<cfset result = 1 />
<cfloop from="1" to="5" index="i">
<cfset result = result * i />
</cfloop>
<cfreturn result />
</cffunction>
What's the harm?
Ok, so you hit your page, which calls this code tucked away safely in a CFC. You put that CFC in the application scope because that's the Singleton pattern, or something like it and it runs faster. You get a good result (120). Great. Hit it again, no problem. Write a unit test if you want, it passes every time.

Now, put that out on production. I dare you.

Minutes later, your phone rings. Bill Billings, your most loyal customer calls up. He must be your most loyal customer, because it's only loyal customers or especially angry customers that ever call. He sounds angry and you rethink Bill's loyalty. Bill says "What's the idea? I got '7200' when I know I was supposed to get 120!" And you're pretty sure he was supposed to get 120. I mean, that's what the function does. It just returns 120. You tested it! You tell Bill that you'll look at it and brush him off because you're busy coding. Check your glasses, Bill. Check your glasses.

As soon as you get off the phone, it's Sally Sallington, another loyal customer calling, asking how she got 518400000 from something that should really be giving something closer to 120. Oh man. Now you have a problem.

Interestingly, your customers are getting round numbers, and they are both divisible by 120.

The Java thread model
If you get the sense that java is screwing with you, you're on to something. What you failed to test for was multithreaded access to your method. When Bob and Sally hit that method at the same time, anything can happen.

You've got 2 users, so 2 threads running some code. Java has to make sure that both requests are satisfied as quickly as possible. How does it do that? Well Java will flip-flop between which thread is running, basically, on a whim. Maybe Bill will run through the loop 3 times and stop before the multiplication line, then Sally will just start the loop. Bill will run another 1 time around the loop, then Sally's thread takes a turn going 2 loops, stopping after the multiplication line.

Both variables in the function, result and i are being shared between everyone who runs the function. Bill sets result to 1, then 5, then 10, at which point, Sally may come in and set result back to 1, or pick up Bill's 10 at the start of the loop and go from there. It's impossible to say what exactly will happen. It's part of the magic of Java.

Why did they do it that way?
Why does Java's threading flip-flop between the active threads? Why can't it just finish one and then start the next? Well then you wouldn't be running a multi-threaded application server, would you?

Then there's HotSpot - Java optimizes code as it runs and chooses the best path while it's running. As far as I know, it's literal, actual, magic. There's no way to know what it will do.

Also, usually your code isn't quite that simple. You put <cfquery> tags in there which could even be on a different server, maybe component instantiation calls that have to go to disk to pull in the CFC in, compile it and call it. While Java waits for the network or the disk or whatever else, it handles the other requests that are waiting.

But I have a 4-CPU, 4-core server
Oh, that's not going to help. Now Java can literally do the same operation across 16 threads at the exact same time. You're really in trouble.


read on for the stunning conclusion...

(more on this subject) (16 comments)

SQL Surfer 2.0: First commit

posted under category: Free Code For You on November 10, 2008 at 8:36 pm by MrNate

Hey all - quick note to let you all know that I issued my first commit of many into the SQL Surfer project. No real single-file download yet, but you can download the source and build your own with Eclipse, Ant and Groovy (if you dare!).

I'll share some more ideas with you all as I progress.

(0 comments)

Integrating 3rd party applications into yours, safely

posted under category: General on October 29, 2008 at 8:26 pm by MrNate

Reuse-in-the-small is a solved problem. Reuse-in-the-large remains a mostly unsolved problem.
Jeff Atwood from Robert Glass, Facts and Fallacies of Software Engineering

I'm actively hacking at my latest toy project, which integrates a few 3rd party projects, and I had the thought, integrating a library, like jQuery, is drastically simpler than integrating a whole application, like a discussion board or WYSIWYG text editor. How do you solve these problems?


A few years ago I attempted to drop Ray Camden's Galleon Forums into another project. My app was Fusebox, so I had to rewire some of the front end, then move the component calls back out to the circuit. Sounds fairly easy, but with 3 gaping problems.
1st, the client calls and we have to modify it heavily. It turned out the only thing Ray's app was good for, was a starter kit on the database and DAO templates.
2nd, Ray puts out a new version with features we like, avatars, BBcode and signatures. We were so far out of sync that there's no way we could implement his new version.
3rd, I was never sure how stable the rewritten code was (turns out it was ok, but I was crossing my fingers).

Result: Thanks for the starter kit, now I'm on my own.


Fast-forward a few years to my new project, and I've started integrating Edit Area, a javascript code editor, into my application. Edit Area presents a few challenges, including the build program written in PHP and the authors not being native English speakers. Also, I have some application requirements, such as no externally linked files, and oh yeah, it has to work right (grrr).

So, how do I make changes to the application while keeping myself open to future versions?

The method I chose was to make changes to Edit Area in my build file. Ant calls Groovy. Groovy reads in their file and turns it into my file, which my program includes. It is repeatable but not destructive. When the next version comes out that fixes some of my problems (and I do hope it does), it will be mostly zero effort to update my code. Their changes could break my build temporarily, but I can tweak and adapt.

The biggest issue here is the challenge of meta-programming, or programming programs to reprogram programs. It's a lot of trial and error to get it right, and a lot of regular expressions. Also, Ant isn't exactly a real programming language, so I have Ant run a Groovy script. It's initial complexity to solve a repeating problem, which is a fair trade to me.

Result: Brainiacs only, but it works well.

(2 comments)

SQL Surfer 2.0: alt.lang

posted under category: Free Code For You on October 19, 2008 at 5:51 pm by MrNate

I kind of went overboard on the languages & platforms with SQL Surfer 2.0, which I first mentioned early yesterday morning. Luckily, the finished product is just running CF/HTML/CSS/JS (That's 4).
The build process uses C# (+1) to customize fixes to Edit Area.
I used a batch file (+1) to copy the C# exe to my dev folder.
The build file is Ant (+1), and Ant is in XML (+1).
The build file uses groovy (+1) to replace some includes with actual content.

Total count: 9 different platforms, languages or technologies. Not bad for a little SQL tool.

UPDATE 10/23: I move the c# asynchronous process into Groovy during the build process, so that removes 2. That puts me down to 7 now.

(0 comments)
Nathan is a co-manager for the Phoenix CFUG (AZCFUG) and a ColdFusion application developer for an aerospace company in the Phoenix East valley (Mesa). Aside from doing ColdFusion applications, Nathan enjoys playing with servers, hacking with a variety of other programming languages and managing his home theater PC. Nathan got his programming start writing batch files in DOS.
This blog is also available as an RSS 2.0 feed. Click your heels together and click here to email Nathan.