An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

Quick Tip: Specifying argument types and default values in CFSCRIPT

May 8, 2009 ·

I like writing my CFML functions as script code where possible. That has traditionally meant that you cannot specify argument types or default values:
function someFunc(arg1,arg2) { ... }
That means you cannot have optional arguments and you have no type checking. You might want to say:
function someFunc(
numeric arg1,
string arg2 = "foo"
) { ... }
This ensures someFunc only accepts numeric values for arg1 and it allows arg2 to be omitted in calls, taking the default value of "foo". Wouldn't that be nice? In Railo, you can already do this!

Tags: coldfusion · railo

4 responses

  • 1 Ben Pate // May 8, 2009 at 6:52 PM


    No seriously, this is a great feature. I've seen lots of small features in Railo that I really envy. Overall, I'm glad that there's competition in the CFML area, because it will help push everyone forward.

    Now Sean, will Adobe take up all these little challenges? Will the standards committee be able to sort out stuff like this (admittedly small) enhancement to CFML?

  • 2 Sean Corfield // May 8, 2009 at 7:09 PM

    The CFML Advisory Committee has recently been discussing a number of enhancements to CFSCRIPT, including enhancing function declarations. I'll provide more details in a new blog post.
  • 3 Russ // May 8, 2009 at 7:16 PM

    At least CF has the option to use a tag so you can specify arguments explicitly. PHP and a lot of other languages don't even have that.
  • 4 AJ Mercer // May 28, 2013 at 1:08 AM

    Thanks for the tip Sean - blogger like you (and Google) make me look good ;-)