portal entry

select a category, or use search below
(searches all categories and all time range)

final == immutable? (or not?)

| View in Portal
April 20, 2018 03:10:04 AM GMT
<p>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</p>
<p>The post <a rel="nofollow" href="https://coldfusion.adobe.com/2018/04/final-immutable-or-not/">final == immutable? (or not?)</a> appeared first on <a rel="nofollow" href="https://coldfusion.adobe.com">ColdFusion</a>.</p>
Labels: Discussion, Final, Language, ColdFusion, final, language, publicbetaaether


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.
Comment by Bradley Wood
63 | April 17, 2018 01:59:03 PM GMT
I agree with Brad on all counts. Immutable objects would be useful. Final ones: not so much.
Comment by Adam Cameron
13 | May 16, 2018 07:26:24 AM GMT
When I have something locked down, I want it to stay locked down.
Comment by James Mohler
1128 | June 15, 2018 12:19:26 AM GMT
Hi all, The ticket is https://tracker.adobe.com/#/view/CF-4202132 Thanks!, -Aaron
Comment by Aaron Neff
1129 | June 15, 2018 05:32:13 AM GMT