ColdFusion Muse

CFMX and the Dot Operator - Migrating From CF 5 to CFMX

Mark Kruger March 14, 2006 11:23 AM Coldfusion MX 7, Coldfusion Tips and Techniques Comments (4)

If you come from the old "Coldfusion 4-5" days (in fact many or our customers are still running CF 5) then you might remember how those earlier versions handled variables with periods in the name. If you created a variable with a period in the name CF simply treated the period as if it were part of the variable name. For example, if you did the following in CF 5:

<cfset var1.var2.var3 = "My Dotty Variable">

You would not have created anything more than a primitive variable named "var1.var2.var3". If you tried to use <cfdump ...> to dump out var1 it would generate an error - var1 not found. If you intended for var1 to be a structure containing a structure var2 containing a primitive var3 then you would have to rewrite the code like this:

<cfset var1 = structNew()>
   <cfset var1.var2 = structNew()>
   <cfset var1.var2.var3 = "My Dotty Variable">
Fast forward to CFMX.

Read More
  • Share:

4 Comments

  • Adam Cameron's Gravatar
    Posted By
    Adam Cameron | 3/14/06 5:15 PM
    I think it's a bit "misleading" to suggest that the dot is an OPERATOR. It would be an operator if this was possible:

    myStruct = "top" . "middle" . "bottom";

    and that would create a struct like this:

    myStruct.top.middle.bottom

    (or, I dunno, something like that... it's nonsense so I don't know what my expectations would be, other than "an error").

    But that's not how it works. For something to be an operator, it has to be usable in an expression; and usable with other operators and operands. Dots aren't.

    It's simply part of a CF synactical construct which allows the autocreation of structures on the LHS of an expression.

    When going:

    mystruct.top.middle.bottom = "value";

    mystruct, top, middle and bottom are NOT operands, and . is not an operator.

    --
    Adam
  • Steven Erat's Gravatar
    Posted By
    Steven Erat | 3/14/06 7:05 PM
    Nice post! While I knew that this was documented in as a change in the CFMX 6.0 documentation guide in the section on Migrating, I didn't know that it was possible to create struct keys having dots in the key name. Good technote :) Thx!
  • Mkruger's Gravatar
    Posted By
    Mkruger | 3/14/06 7:18 PM
    Steve - thanks for the kind words.

    Adam - while I see your point that the "dot" doesn't seem to have the same syntactical properties as the + or - etc... I would hasten to point out that the term "dot operator" is quite ubiquitous in the java world (as well as other OO languages). In fact the Coldfusion migration guide itself refers to the change in variable naming as follows:

    --------------------------
    You can no longer use a dot (.) in a variable name, because ColdFusion MX supports the dot notation as a DOT OPERATOR to create a struct. For example, last.name creates a struct called last with a key called name, instead of creating a simple variable whose name has a period in it.

    --------------------------

    So, while some folks who are unfamiliar with the idea of the dot being an operator might struggle initially at the idea, I think it is fairly well supported. I would add that your argument is more about syntax (which can vary widely based on the language used) than function. It may be fair to say that the dot operator has syntax rules attached to it - but I think it is definitely an operand.
  • Adam Cameron's Gravatar
    Posted By
    Adam Cameron | 3/15/06 3:37 AM
    Fair cop.
    I think you should probably remove the analogy to the + operator though, as it is misleading. It is not an operator in THAT sense of the notion.

    Personally I think the existing - almost ubiquitous - usage is inaccurate, but that is a fight I think would be futile for me to engage in ;-)