this would be a nightmare to develop while maintaining backwards
compatibility. Making the whole language typed, period, would be somewhat
easier - but only in a sense, as you would really just be ripping out the
massive amounts of code that handle typelessness - a huge job by anybody's
measure.
However I did have one idea that might be able to address this somewhat - at
least partially. Of course it could also be the stupidest thing ever thunk.
What if you could apply type validation on a per-variable basis? Basically
assign a type to a variable and have every write to that variable tested for
that type.
The language implementation would be tricky. I would propose, off the top
of my head, that CFPARAM could have an attribute added:
<cfparam name="Foo" type="boolean" enforceType=true>
The "enforceType" parameter would be optional and default to "false" to
ensure backwards compatibility (I would add the same attribute to
"cfargument" as well). The setVariable() function could also have a third,
optional parameter added to enforce type (again defaulting to "false"):
#SetVariable(Foo, Value, true)#
The hardest one would be CFSET since it doesn't follow a more traditional
format (both the left and right side of the equals are dynamic). You could
do something like this:
<cfset foo = value enforceType = true>
That's really just two attributes to the tag. However personally would
probably rather see a new tag. Perhaps something like this:
<cfset foo = value >
<cfsetType foo = "Boolean">
And perhaps a corresponding function:
#SetVariableType(Foo, "Boolean")#
I would personally only want to see simple typing using this: Boolean,
Numeric, String, Date, query, struct, CFC Names, etc - not
int,long,float,etc.
In practice this would mean that the whenever the variable was written to
AND it had a defined type then that type would be checked. However no
checks would be done on reads.
Just the write checking would most likely incur a (small) performance hit
but since you would presumably only be using it for "important" variables
then it's something you'd be able to manage.
As an aside I'm not convinced CF needs typing at all - but I do love
automatic type validation so you could say I'm on the fence.
Jim Davis
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

