Hi,
I have just found an annoying “silent trap” in haxe, that maybe extends to other languages, but never noticed it: null setters simply do nothing! I had n null setters like the following one
private var __cultureCode: String;
public var cultureCode(get, null): String;
I was trying to set __cultureCode (locally) by setting
cultureCode = "it-it";
instead of
__cultureCode = "it-it";
and the value was “obviously” not being saved, but I found out this only months later: luckily the affected variables were not used yet.
Now it is fixed, but what left me thoughtful is this question: “why the compiler doesn’t tell me anything if I am trying to set a null setter?”. Imho it would be more obvious to receive an error, the operation is wrong and easily causes hidden errors/bugs, you think you’re setting a value but you are just doing nothing.
Now I see it was completely wrong, and it is still now, as it doesn’t set the default value even if I replaced the "cultureCode"s with “__cultureCode”.
I think I will remove the __xxx private var declarations and beat who adopted this approach.
It’s common in AS3, where there’s no other way to do read-only, but I avoid the extra variable where I can, since (default, null) is really just all-around nicer
Yes, the error was in the getter: I replaced all getters with the one Joshua suggested.
I have always set variables with null setters, but this class (partially not mine) confused my mind: I have just came back from holidays, maybe my brain is still somewhere else
Do you suggest a different title to avoid confusing someone?