ColdFusion 9 Component Script

Word Count: 446

I know there are many users out there who love cfscript and many who really don't care for the syntax. I am really on the fence, I like the syntax but do not use it much because of the lack of support for certain tags and on the presentation layer it just does not mix well for me. One of the main reasons that Adobe is yet to support full scripting is the cfqueryparam tag. I am hoping that in the next version of ColdFusion they find a way to resolve this.

I have been doing some ActionScript 3 development lately and I really love the language. So with that I have a small proposal for CF9 that I am sure some people will be with and some are going to hate it. Day to day I write many Components so I think it would be really cool to write components using scripting. With that said here is an example of what I would like to be able to do.

<cfcomponent output="false" format="script">

   variables.dsn = "";

   public function init(String:dsn):User{
      variables.dsn = arguments.dsn;
      return this;
   }

   public function getUsers():query {
      var q = new cfquery();
      q.name = "q";
      q.datasource = variables.dsn;
      q.sql = "SELECT * FROM Users"
      q.execute();
      
      return q;
   }
   
   public function getUser(Numeric:id):Struct {
      var q = new cfquery();
      q.name = "q";
      q.datasource = variables.dsn;
      q.sql = "SELECT * FROM Users WHERE id = " + arguments.id;
      q.execute();
      
      return queryRowToStruct(q);
   }
   
</cfcomponent>
So go ahead rip it apart! Again this is just an idea and I would love to hear pros and cons of this approach from others.

Comments

#1 Posted By: Kris Brixon Posted On: 3/21/08 11:56 AM
More of a question: Is this the same thing (or is this possible)?

<cfcomponent output="false">
<cfscript>
...
</cfscript>
</cfcomponent>
#2 Posted By: Dan Wilson Posted On: 3/21/08 12:31 PM
I am also awaiting a proper first class scripting syntax for ColdFusion. AS3 is a nicely designed language and I would not mind it at all. It certainly would keep my mind clearer switching in between AS and CF all day long....


It would seem that Adobe have begun the process, with allowing attributecollection for every tag... this seems to pave the way for alternate usage of the tags...

Here's to proper scripting support..

DW
#3 Posted By: Raymond Camden Posted On: 3/21/08 12:36 PM
"One of the main reasons that Adobe is yet to support full scripting is the cfqueryparam tag."

I find this odd. :) If you play with AIR and the sqllite stuff, you can see they support bound query parameters. You use something like (I say siomething like cuz my code isn't in front of me)

sql = "select * from foo where id = :id"
sql.setParam(":id", id)

That syntax is definitely wrong, but close to the idea, and would certainly work for cfscript.
#4 Posted By: Dan Vega Posted On: 3/21/08 12:39 PM |
Author Comment
Now that you mention that I remember seeing that somewhere. I just remember speaking with Ben Forta about this very topic and pointed towards cfqueryparam as the main reason for full scripting support. Do not quote me on that though, I could be mistaken.
#5 Posted By: orangepips Posted On: 3/21/08 12:51 PM
What I would really like to see is cfscript incorporate all the functionality of CFML and full ECMA-compliance syntactically. So along those lines I think it would be great to be able to write an entire file in cfscript syntax without cfscript tags. Say a *.cfs extension (probably already taken I know). This is something that I keep coming back to as a change I would like to see in the language such that I wrote something up about it here:

http://orangepips.instantspot.com/blog/2008/03/21/...
#6 Posted By: Dan Vega Posted On: 3/21/08 1:05 PM |
Author Comment
Great article! I agree that a move to ECMA syntax would make sense on so many levels.
#7 Posted By: Gary F Posted On: 3/21/08 8:38 PM
Does the CF community want to move away completely from the tag based syntax that way always sold as a strength of CF? (e.g. easier for beginners and less typing required)

The cfquery way looks a lot easier/shorter than using a js/c# style scripting language to do the same thing.
#8 Posted By: Dan Vega Posted On: 3/21/08 8:43 PM |
Author Comment
I would not say that it would be moving away from its strength. The strength of ColdFusion is how easy it can be for new developers and powerful enough for experienced developers. I think it would just give those of us anther option.
#9 Posted By: Peter Bell Posted On: 3/22/08 2:45 PM
ColdFusion needs to continue to provide a tag based syntax for front end templating and the developers who like it, but I definitely think that Adobe should finish what they started with cfscript to allow for writing of classes and methods without having to use tags.

Only comment I'd make on the example is there's no reason why there should be a cfcomponent tag around the clas.
#10 Posted By: Dan Vega Posted On: 3/22/08 5:37 PM |
Author Comment
I completely agree with you Peter!
#11 Posted By: Kurt Wiersma Posted On: 3/22/08 7:08 PM
Personally I really AS 3 and think that developing some of all of my objects with that syntax would be great. I know it would be large task and might be harder for first time users but it would be really nice to be able to write fully components in a script like syntax and use the tags mainly for output layer type stuff or for manipulating xml.
#12 Posted By: Tony Garcia Posted On: 3/22/08 10:09 PM
I'm with Gary. I like tags, pure and simple. That's one of the main reasons I chose CF over PHP. I have nothing against Adobe putting more features into cfscript. But if that ever becomes the primary syntax that everyone uses, it will be a sad day for me.
#13 Posted By: Dan Vega Posted On: 3/22/08 10:33 PM |
Author Comment
I would agree with you there. I am not asking to replace the tag based syntax I would just like to see another option.
#14 Posted By: Raul Riera Posted On: 4/9/08 9:33 AM
I dont know about the SQL thing, what I love about CF is its cfquery tag, having to code SQL on a single line like on the other languages is a DRAG! (I think we all were there once) Thats something I dont like of AS3 (on AIR though) Sure you can brake the line and add more code, but thats just asking for trouble.
#15 Posted By: Dan Vega Posted On: 4/9/08 9:41 AM |
Author Comment
@Raul - I completely get that. I think anyone who uses CF can agree its strong point is making common tasks simple. What if you prefer a scripting environment to a tag based environment? Should we just tell those people ohh well or wouldn't it be nice to satisfy both parties. I am not saying to replace the current method, it will still be there. I am just thinking of alternative options.
#16 Posted By: Bilgehan Mara? Posted On: 8/3/08 11:14 AM
Having alternatives is good but loosing focus is not and i think CF is loosing focus rapidly. If someone prefers scripting environment to ta tag based environment, i think he/she made a wrong choice by choosing ColdFusion at first. Here are my suggestions for ColdFusion.


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.