Showing posts with label coldfusion. Show all posts
Showing posts with label coldfusion. Show all posts

Thursday, February 7, 2008

Another thing that drives me berserk about ColdFusion and CFEclipse

It is damned near impossible without using the "find" feature and extraordinarily tedious tag-counting (and tag-collapsing) to figure out whether or not a given variable is in scope at a particular part of the page. I can't control-click to go to the spot where the variable is declared; I get no indication as to whether the variable exists at a given spot; I don't even get a warning telling me that the variable may not have been declared conditionally at a given spot.

And then I get exceptions thrown when my predecessor's code references a variable that was conditionally declared earlier and the declaration got skipped this time. Madness.

Saturday, January 26, 2008

Exciting News

As you might have guessed, my productivity isn't quite as high with ColdFusion as it is in a Java web app environment. It took me a couple of days this last week to develop an embarrassingly small number of components and unit tests in CF.

I haven't been whining out loud about ColdFusion quite as much as I've been complaining on this blog, but several related activities, combined with some whining, and my lack of productivity, have led us to general agreement that we're going to be remediating this application's problems using Struts 2, Spring, and probably Hibernate. I'm very happy about this, as you might imagine.

I haven't used Struts 2 on a real app yet, although I have used Struts 1. I'll probably be using this blog in part as a Struts 2 linkdump, and partly as a description / walkthrough as I learn. I'm really looking forward to it.

My first link to dump, courtesy of client coworker: how to set up a Struts 2 project in MyEclipse 6.

Thursday, January 24, 2008

ColdFusion needs unit tests freakin' everywhere

By trade I am a Java developer -- I've done plenty of Java EE work as well as pure Java SE stuff. I'm a consultant in Pittsburgh. I won't mention my employer by name, or name any clients that aren't dead, but I've worked at a fair number of clients in the greater Pittsburgh area.

Back in 2000, at a long-dead website, I did about six months of really painful ColdFusion development. In the fall of this year I was offered the opportunity to do more CF consulting, at a local company, and I took the posting.

So, I've been doing CF again for a few months now. I miss so much stuff from Java development that I won't even list it all, although my previous CF post hits some of them.

Here's a new one: Today I lost half a day to the difference between <cfloop query="foo"> and <cfloop query="#foo#">. The error message I received informed me that I was trying to use a complex object where I needed a simple value. I didn't get a stack trace. I didn't get a line number.

And of course I didn't have a debugger. The only way to find out what's going on in ColdFusion is to layer your code with <cfdump> tags and other output-to-the-page wickedness.

So, anyway, what I'm finding is that the more CF development I do, the more I have to write unit tests for even ordinary model objects -- I need to make sure that freakin' getters and setters are behaving intelligently when faced with even slightly unusual circumstances.

Case in point: I have a method, setShippingCharge(), on a Customer CFC. When I designed Customer I knew that shippingCharge was numeric, and so I wrote it like this:

<cffunction name="setShipping" output="false" returntype="void">
 <cfargument name="shippingCharge" type="Numeric">
 <cfset shippingcharge = "arguments.shippingCharge"/>
 <cfreturn/>
</cffunction>

I didn't write any unit tests for this, because, y'know, it's a setter, and I'm a Java guy.

I ran some code using this method today, populating a Customer object from a database query. Well the
shipping_charge field in the database was nullable, and in this case, it was actually null. ColdFusion complained about this, because of a type mismatch. Null -- or, thanks to the retardation of ColdFusion, the empty string "" -- wasn't numeric!

So instead I had to rewrite the function like this:

<cffunction name="setShipping" output="false" returntype="void">
 <cfargument name="shippingCharge">
 <cfif>
  <cfset shippingcharge = "0"/>
  <cfelseif>
   <cfset shippingcharge = arguments.shippingCharge/>
  <cfelse>
   <cfthrow type="foo.IllegalArgumentException" message="this is supposed to be numeric">
 </cfif>
 <cfreturn/>
</cffunction>



I'm not sure I understand, at this point, why ColdFusion functions even allow you to declare their expected data type. If you've got to go through gyrations like the above for every method, what good is the 'type' attribute on <cfargument>?

I was going to turn this into a rant on dynamic languages but I guess I'll save that, except to say that gosh, a compiler could sure prevent a lot of this pain.

Tuesday, January 22, 2008

ColdFusion Pain

A brief note regarding ColdFusion, which I'm currently doing development on (augh). CF is pretty loosely typed. Unit test (using CFUnit, god help me) certainly need to explicitly do testing on the types that methods return, as well as methods' abilities to handle arguments of varying types.

As a side note, I use CFEclipse, which is the ColdFusion plugin for Eclipse. It really isn't very good. Its ability to do tag completion is woeful; ctrl-space code completion isn't very complete -- and often the "timed" code-completion popup occurs at precisely the wrong moment (namely, when I'm pressing 'return' for some other reason).

Worst, in my opinion, is CFEclipse's inability to find things. When doing Java development in Eclipse, if I highlight a variable name, I expect to see every instance of that variable highlighted in the current file. CFEclipse doesn't do that with ColdFusion files.

I'm also addicted, in Java, to using the right-click menu to find declarations of variables or to find references to methods and/or files. Not available in CFEclipse at all.

I accept that some of this stuff is hard to do for a loosely typed "language" like ColdFusion. But this is playing hell with my productivity. I also accept that CFEclipse is an open-source project and that I could contribute to it if I really wanted to. I'm considering it.