Thursday 24 July 2014

Survey: to scope or not to scope

And, indeed as the old trope goes: "that's the question". I have been looking at some code that follows one coding standard, which says "thou shalt scope all variables". And I look at my code, in which I only scope when needed, and I really feel the former is a pile of... clutter compared to my own code.

However the scope of my own code is much narrower and much less mission critical. And only I work on it. So just because I prefer to do something a given way which specifically suits me doesn't mean that's the best way to do it.

So I want to know how you do it. And with that in mind, here's a survey for you to fill out, if you so choose: "Scoping of variables scope variables".

Personally I think there's merit in scoping everything else: I'll scope form & URL variables despite the fact they're part of the scope-look-up that CFML does automatically. I think it's important to know where these external values came from. And obviously most other scopes need to be specified anyhow.

But what about the variables scope? I can see a point in scoping 'em in a CFC, as one wants to know when a variable is local (unscoped), or specifically object-wide: variables scope.

However in a CFM file I think it's ceremony for the sake of it.

What do you think?

The survey has three questions:

  • How vigorous are you at scoping variables-scope variables in CFM & CFC files?
  • Do you have either a formal or personal coding standard you follow regarding scoping of variables-scope variables?
  • Anything else to add?

So should be quick.

And - to make things abundantly clear - do not answer the questions in a comment on this article. Fill in the blimin' survey. That's what it's there for. All comments on the survey will be published when I follow-up in a few days. But if you comment here it wastes my time when I come to aggregate the result, as I have to grab them from multiple locations.