This is way cleaner.. It is a sort of lazy initialization.. and usually it is split exactly that way: a backing field, a property that lazily initializes the field, and a method that performs the initialization. This also highlight a possible race condition after the very first null check, that can be avoided by a double-checked locking inside the property get accessor; and the InitialiseSelectionHandler method would remain untouched. I'd just keep the backing field close to the property (I usually keep the field immediately before the property).
Daniele Rota Nodari
Posts
-
code sexiness question -
code sexiness questionStoring the value of the property (
SelectedObject
) into a local variable (objects
) is like a snapshot. It ensures that any subsequent instruction refers to the same object. This is important when you need consistency throughout the method, the method can be relatively time consuming and some other thread can concurrently change the property value. You can always rely on compiler optimizations and hope that the compiled machine code will take care of such thing, or you can do it by yourself with the local variable. Another reason could be that you know in advance that someone will add code inside the method to purposely change the object value; such change will require to put the object into a variable, like the collegue told you to do. Doing it later will require to replace any reference to the property with references to the variable: those changes would be spread along the method polluting versioning differences. It can even be of help if copy-paste is performed to some other method where the logic must be kept but the property to process has a different name. These are indeed pre-optimizations, and we can argue about their usefullness and their development cost. Additionally, the name of the property is not totally meaningful, due to the fact it is singular but it can store multiple objects (like the name of the variable unfolds): this could be an important hint for the future-you maintaining the code. -
And I loathe Microsoft today...Are the "pretty pictures" the Windows Spotlight ones? I always encountered links on top of those pictures, and sometimes they point to commercial links, related to the current picture itself (like "Forza" game). Do you encounter totally unrelated links? BTW, All the files related to Windows spotlight should be located into %LocalAppData%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy sub-directories and you should be able to check and disable their usage from the "lock screen" settings.
-
Funny Pigeonsplay at cops and robbers
-
Deleted answer still give pointsIndeed... the same seem to apply to comments (1 point also for deleted ones).
-
Deleted answer still give pointsHi. I just replied to a question, then deleted the answer and replied again (with a more complete answer). All of this within a couple of minutes, before anyone commenting or voting the first answer. Currently that question: - Tells 2 solutions are available. - To anyone but me, shows only one solution, the last one. - I can still see points being rewarded for the deleted answer. By the way, I deleted and re-posted the answer because feeling an "improvement" (instead of editing that was not available) would have marked it as a second answer. Regards, Daniele.