April 20, 2018
final == immutable? (or not?)
Comments
(4)
April 20, 2018
final == immutable? (or not?)
Newbie 12 posts
Followers: 2 people
(4)

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”}; myVar.foo = “baz”`

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

Thanks!,

-Aaron

4 Comments
2018-06-15 05:32:13
2018-06-15 05:32:13

Hi all,

The ticket is https://tracker.adobe.com/#/view/CF-4202132

Thanks!,
-Aaron

Like
2018-06-15 00:19:26
2018-06-15 00:19:26

When I have something locked down, I want it to stay locked down.

Like
2018-05-16 07:26:24
2018-05-16 07:26:24

I agree with Brad on all counts.

Immutable objects would be useful. Final ones: not so much.

Like
2018-04-17 13:59:03
2018-04-17 13:59:03

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.

Like
(1)
Add Comment