Skip to main content
January 5, 2009
Question

Using a dot "." in defining/scoping variables

  • January 5, 2009
  • 3 replies
  • 350 views
I've always felt it was a best practice to scope EVERY CF variable and still do. However, a new co-worker to me feels that using a DOT in variable names could cause problems. I completely disagree but would like others opinions. To me scoping variables is absolutely a best practice.

She specifically referred to the article below but to me the point of this article was about using "primitive" variables such as: "var1.var2.var3".

http://www.coldfusionmuse.com/index.cfm/2006/3/14/dot.operator

Looking forward to others opinion especially seasoned CF folks from Adobe.
    This topic has been closed for replies.

    3 replies

    January 5, 2009
    Thank you for the comments!

    I agree that my co-worker missed the point of the article. Almost every language uses scoping so when she brought this up it almost through me for a loop, thought maybe I was going insane. I also leave the "variables" scope off at times but to be consistent I try to even scope those.

    I have seen code with multiple dots which always seemed confusing and useless. I was not aware that this could be a problem with later versions of CF but since I never do that it should not be a problem with anything I have written.

    Thanks again!
    Inspiring
    January 5, 2009
    I tend to scope all my variables except those in the variables scope. Since CF checks that scope first, I see no advantage to the extra typing.

    Regarding using periods in variable names, I never even knew it was possible.
    Inspiring
    January 5, 2009
    NUHuskers65 wrote:
    > I've always felt it was a best practice to scope EVERY CF variable and still
    > do. However, a new co-worker to me feels that using a DOT in variable names
    > could cause problems. I completely disagree but would like others opinions.
    > To me scoping variables is absolutely a best practice.
    >

    I think this co-worker misunderstood the point of that article as
    surmised in its last paragraph, and I quote:

    "The solution is to avoid using dotted notation for primitive variables.
    Only use dotted notation for variable naming when you intend to create a
    structure."

    All variable scopes in modern, aka MX, aka Java Based, ColdFusion are
    structures. You use the dot [.] character to specify the keys of
    structures. So you are doing what you are supposed to do.

    This article refers to older versions of ColdFusion where all the
    variable scopes where *not* structures and you could get away with dots
    in your primitive, i.e. non-structure, variable names. It also tells
    how one can still do this by using array notation.

    This is a bad practice and should be avoided for the very reason that in
    modern ColdFusion, dots are meant to be interpreted as structures. It
    does not say to not even use dots for these structures where they are
    meant to be used.