ColdFusion 9 setting attributes in cfscript using javadoc syntax

Word Count: 175

I recently came across a problem that I thought was a bug and it was dealing with the new scripting features. I was trying to set some attributes in cfscript using the new javadoc syntax. What I thought was that ColdFusion was reading the information from the comments and I was always a little confused on how it would know that this was an attribute deceleration versus a plain old comment. The problem I was having with the code below is that it was not actually extending my abstract service like I intended. You don't actually need the script tags but for code coloring purposes I am using them. Can you spot the problem below?

If you said that I was using comment syntax instead of the javadoc syntax you are correct. I was not even aware there was a difference until someone pointed it out to me on one of the forums. The javadoc syntax starts with /** not /*. So if we update our code it should look like this.

This brings up another good question though. I actually prefer this method. I have gone back and forth but I thinks when I am working in script this just feels right to me. Mixing attribute into script like the code below just does not. What does everyone else think? Do you have a preference and if so why?

Comments

#1 Posted By: Nathan Mische Posted On: 8/24/09 9:42 AM
I think having comments affect code execution is a horrible idea.

There should be some other syntax for this. Java or ActionScript annotation syntax would seem to make sense to me.
#2 Posted By: Nathan Mische Posted On: 8/24/09 9:57 AM
I'll also note that there is an enhancement request to add some sort of annotation syntax to cfscript: http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbu...
#3 Posted By: Terrence Ryan Posted On: 8/24/09 10:48 AM
Nathan, you don't have to use javadoc notation. You can add them after the component, property, and function entry as attribute="value".
#4 Posted By: Jason Fisher Posted On: 8/24/09 1:13 PM
I strongly dislike the use of comments containing meaningful, actionable code. I also really dislike the inline syntax:

component extends="AbstractService" output="false" {}

The option Terrence points out is cleaner:

component {
extends="AbstractService";
output="false" ;
}

That still feels a bit odd, though, putting the 'extends' info after the declaration of the component itself, but I like it better than the inline.
#5 Posted By: Dan Vega Posted On: 8/24/09 1:15 PM |
Author Comment
I didn't realize there were performance issues with the javadoc syntax. Do you know why that happens? Just curious.
#6 Posted By: Dan Vega Posted On: 8/24/09 1:19 PM |
Author Comment
As you said Jason that feels a little weird. With the attributes setup that way they also now probably fall into the variables scope which I don't like either.
#7 Posted By: Jason Fisher Posted On: 8/24/09 2:22 PM
I guess one of the options in the CFBUG that Nathan referenced above isn't too bad ... at least it would allow the compiler to keep properties out of the variables scope:

@output false;
component {
@output false;
@returntype "WEB-INF.cftags.Component";
}

It's a bit like SQL Server variable declarations ...
#8 Posted By: Adam Cameron Posted On: 8/24/09 3:22 PM
I agree with the others who think that having "executable" code in a comment is absolutely wrong.

Comments are comments plain and simple, and have not relevance outside of source code and documentation engines (in the case of Javadocs), and are ignored by the compiler. This is a precedent set by every other language I know.

CF's approach is just wrong, and should be removed before CF9's release.

--
Adam
#9 Posted By: Raymond Camden Posted On: 8/24/09 5:03 PM
I'll ditto everyone above - the idea of comments having a real impact gives me the heeby-jeebies.
#10 Posted By: Sami Hoda Posted On: 8/24/09 6:52 PM
Agree with Ray. Comments affecting performance is a big no-no.
#11 Posted By: Raymond Camden Posted On: 8/25/09 8:51 AM
To be anal, Sami, comments affecting _anything_ worry me (performance,behavior,etc)
#12 Posted By: Nathan Mische Posted On: 8/25/09 9:38 AM
@Terrence - I know you don't have to use the JavaDoc syntax, but the fact that you can scares me. I consider Dan a pretty advanced CF developer and if this threw him for a loop imagine the confusion it will cause for new CF developers or people coming to CF from other languages. Comments should be comments. And while we do have another syntax, I don't think anyone really likes it. Annotations just seem to make sense here. If we had a clean annotation syntax we could dump the "in-line" and JavaDoc syntaxes and just have one way to define these attributes.
#13 Posted By: Jason Fisher Posted On: 8/25/09 9:42 AM
plus, what about when you need to comment out a comment-style property declaration ... yes, yes, I know that /** is different from /*, but ... really? way too confusing and the IDEs (properly) treat /** */ the same as they do /* */ from a visual perspective.
#14 Posted By: Dan Vega Posted On: 8/25/09 9:46 AM |
Author Comment
Some very good points here, thanks guys!


Post Your Comment

Leave this field empty







Show Captcha

If you subscribe, any new posts to this thread will be sent to your email address.

Copyright © 2007 Dan Vega | BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.