final == immutable? (or not?)

Hi CF Community,

I’d like to get your opinions. Would you prefer final variables to be immutable or not? Currently, a “final” variable just means you cannot make the reference point to something else. However, who would find it more useful if “final” meant the data structure pointed by it will not be mutable?

Example: `final myVar = {foo=”bar”}; = “baz”`

Who would prefer that to not throw an exception (current behavior) or to throw an exception?



4 Responses

  1. I think Final has little to no place in CFML. It feels like we were just copying over patterns from Java that don’t make a great deal of sense in CFML. Immutable data structures are much more common in dynamic languages like Ruby and would have been a better way to spend out efforts. An immutable array or struct would be one that you create and it will not allow itself to be modified by other code which is useful for ensuring no accidental changes happen when you’re passing a data structure around by reference (an exception is thrown if you try to modify an immutable struct or array). The languages I’ve seen have a syntax when declaring the variable where you specify if it should be immutable or provides some sort of .freeze() member function that you call when you’re finished creating the data structure and ready to lock it from further mutation.

Leave a reply