Thursday 1 January 2015

CFML: More on (moron?) assignments being expressions. Or not

This is just a follow-up to my earlier article "CFML: Assignments in conditional statements. Yes or no?".

I can firm up my position on this now. To "no".

Firstly Sean pointed out some woolly thinking on my part:

I said this:
This is actually documented: Expressions - Developing guide. So assignments definitely are supposed to be expressions.
And Sean set me straight:
[...] nope, that just shows that there is special syntax allowed so you can assign a single expression to multiple variables in one go.
Fair enough.

Also, I happened to do a crazy crazy thing... I RTFMed. And the docs for CFScript say this:

Assignments are statements, not expressions, and therefore cannot be used in situations that require evaluating the assignment operation.
So in my opinion, that's case-closed. All this stems from the fact Railo allows assignments in conditional statements. Seen in this light: Railo is wrong to do that, and it's a bug (at least a compatibility one).

I think perhaps the best approach here is that there's no harm in assignments being expressions in general, I think there's enough of a precedent in other languages to make a point of specifically disallowing them in conditional statements.

Or perhaps Railo just needs to make sure this difference is documented. They have a page for this sort of thing: "Language_And_Syntax_Differences" (underscores, guys? Really?).

However I don't think this is a good difference to have. It's not really beneficial.