July 2004 Archives

Fun with Cold Fusion Regular Expressions

| No Comments

All sorts of languages have Perl-style regexps these days, including ColdFusion. However, that doesn't mean that they're going to be easy to use. I wanted to write a version of XmlFormat (a function that escapes text for use in XML) that would not eat newlines. Pretty simple, no?

Here's the error message I got on my first attempt.

 Missing argument name.
When using named parameters to a function, every parameter must have a name.

 [...]

coldfusion.compiler.CFMLParserBase$MissingNameException: Missing argument name.
	at coldfusion.compiler.cfml40.FunctionParameters(cfml40.java:3374)
	at coldfusion.compiler.cfml40.ComplexReference(cfml40.java:3296)
	at coldfusion.compiler.cfml40.VariableReference(cfml40.java:3262)
	at coldfusion.compiler.cfml40.PrimaryExpression(cfml40.java:3153)
	at coldfusion.compiler.cfml40.UnaryExpression(cfml40.java:3087)
        [and much more of this wonderful stack trace]

Here's the code I was trying to run.

newText = REReplace(text, "\n", "
", "ALL");

U huh. Well it turns out that the parser (or was it really the lexer?) was getting confused by that unguarded hash (#). Normally those are used in ColdFusion to interpolate variables in strings. Okay, but zero marks for clear compiler error messages.

Solution? Double the hash (##).

How to Make a JAR File Not Execute

| No Comments

Sometimes one can spend way too much time on silly deployment issues. Case in point, after adding another JAR file to my application, I start getting:

Exception in thread "main" java.lang.NoClassDefFoundError: com.example.Foo

Welll, of course Foo is in the JAR file. Whether I try java -jar or java -classpath, I get the same error.

After scratching my head for a bit and double-checking for silly user errors (yup, there is a manifest file in the right place), I figure I'll have to check Sun documentation on manifests.

..where I discover that the Class-Path header takes JAR files separated by spaces. Nothing wrong with that, but I had been using colons. D'oh!

Estimates: a Useful Tip

| No Comments

The CHAD meeting was not all that well attended, but I thought it was worthwhile being there. The speaker, David J. Anderson, did not really follow his slides. Instead, he told stories about his own experiences in software engineering, starting as a game author in the eighties and getting around to how FDD evolved.

He also improvised a model, Coad style, on the topic we chose, which turned out to be horse racing. It was interesting because he was able to almost apply a template that made sense and seemed to take into account a lot of things that people often forget. The whole idea that generic models can be applied to most situations is deeply appealing.

I took down just one note. Estimates should follow a power law.

You know how it's usually done. You list all your tasks, trying not to forget anything. You estimate each one. You add it all up. I've even written spreadsheets that try to automate some of this, with mixed results.

I had not thought too much about the relationship between difficulty levels. However, humans tend to think on linear scales. This extends to estimating: if we think something is a bit more difficult, we assign a bit more time to it. Thing is, software is one of those things where a little more difficult translates to you'll need twice the time.

When to Use protected

| No Comments

The protected keyword in Java and other object-oriented programming language always seemed pretty strange. Unlike the private and public it's not obvious why anyone would need it.

Now I find myself using it quite a bit. Here's the scenario.

I'm extracting methods into a super class so that I can share them among related classes. One of those methods I'm extracting is private. What to do? I don't want to make it public. If I leave it private nothing will work. That's where protected is appropriate.

All of this is made more natural in an IDE that has support for refactoring.