Skip to main content
32 events
when toggle format what by license comment
Nov 20, 2018 at 11:47 comment added Dirk Boer @Flater, construction of the Lazy can't happen in the Get because you need state. I.e. the lock object and the cached value. Maybe copy paste it and try it out on your own. It works, and you have one third less 'moving parts'. If you found a good alternative with less code for the consumer then please provide it as an answer!
Nov 20, 2018 at 7:34 comment added Flater @DirkBoer: I just don't quite understand the point of having a lazy object whose initialization is not yet known. Why not simply instantiate the lazy when you know what you effectively want - which for you is at the time you call your get method? That, combined with the fact that you "waste" the get method parameter for subsequent calls, makes me feel like it's a less clear version of doing the same thing. Reinventing the wheel comes at a cost, and I don't quite see the benefit that allegedly outweighs the cost.
Nov 19, 2018 at 15:32 comment added Dirk Boer @Flater, of course for me everything will go through the exposed public property - I am not going to to duplicate the .Get(). What I save is that I can initialize inline instead of doing it seperately in the constructor. Try writing one for the current implementation and you see that you will need at least 3 moving parts. The member, the property and the initialization logic / construction within the constructor. For me the current implementation feels like 33% more boilerplate, plus that one third actually needs to be in the constructor instead of close to the rest of the code.
Nov 19, 2018 at 14:04 comment added Flater This saves boilerplate code How so? Correct me if I'm wrong, but now you're going to have to implement initialization logic for every get, even after the object is already instantiated. How does adding the necessity to create logic that will in effect be ignored on any call except the first (or, conversely, hoping that the consumer knows when it can/cannot leave the initialization logic empty) make this easier? If you write two get calls to the same object, each with a completely different initialization, how are you easily going to figure out which one is actually initialized?
Nov 18, 2018 at 10:27 vote accept Dirk Boer
Nov 18, 2018 at 9:12 answer added Theraot timeline score: 19
Nov 18, 2018 at 9:05 vote accept Dirk Boer
Nov 18, 2018 at 9:09
Nov 18, 2018 at 0:41 answer added Dirk Boer timeline score: 1
Nov 17, 2018 at 12:37 comment added Dirk Boer Hi @OrkhanAlikhanov, thanks! I tried stripping a lot of that source to try to get to the core. See the results in one of the answers that I posted if you think it's interesting.
Nov 17, 2018 at 12:25 answer added Dirk Boer timeline score: 0
Nov 17, 2018 at 7:29 comment added Orkhan Alikhanov Source code of System.Layz<T>: referencesource.microsoft.com/#mscorlib/system/… (put for curious people)
Nov 16, 2018 at 17:11 answer added user52292 timeline score: 7
Nov 16, 2018 at 11:10 answer added Dirk Boer timeline score: 3
Nov 16, 2018 at 11:05 comment added Vogel612 Mod Note: Please do not use comments to lead extended discussions about a question and about how to write correct threadsafe code. Comments have been purged. You're all very welcome to continue the discussion in Code Review Chat if you want :)
Nov 16, 2018 at 10:56 history rollback Heslacher
Rollback to Revision 5
Nov 16, 2018 at 10:40 history edited Dirk Boer CC BY-SA 4.0
added 59 characters in body
Nov 16, 2018 at 10:35 vote accept Dirk Boer
Nov 18, 2018 at 1:21
Nov 16, 2018 at 10:25 history edited Dirk Boer CC BY-SA 4.0
added 1945 characters in body
Nov 15, 2018 at 22:12 answer added jpmc26 timeline score: 10
Nov 15, 2018 at 21:25 answer added phoog timeline score: 6
Nov 15, 2018 at 19:26 history edited Dirk Boer CC BY-SA 4.0
deleted 2 characters in body
Nov 15, 2018 at 19:09 answer added Eric Lippert timeline score: 39
Nov 15, 2018 at 18:57 comment added Dirk Boer @AdrianoRepetti, I actually agree, so I provided the second example (how I usually use it). Problem is that I indeed 95% of the time need to access instance variables, and putting in the constructor I really dislike. Because if you have 5+ properties like that you're moving actually a lot of logic into your constructor meaning you really have to jump around in your code because the rest of the boilerplate actually needs to be outside the constructor.
Nov 15, 2018 at 18:52 history edited Dirk Boer CC BY-SA 4.0
added 213 characters in body
Nov 15, 2018 at 18:00 history tweeted twitter.com/StackCodeReview/status/1063129632126447616
Nov 15, 2018 at 17:14 answer added user73941 timeline score: 9
Nov 15, 2018 at 12:50 answer added Nkosi timeline score: 5
Nov 15, 2018 at 10:44 comment added t3chb0t @AdrianoRepetti this would make a great answer ;-)
Nov 15, 2018 at 10:32 history edited t3chb0t CC BY-SA 4.0
removed language tag from title
Nov 15, 2018 at 10:31 answer added t3chb0t timeline score: 14
Nov 15, 2018 at 10:20 history edited Dirk Boer CC BY-SA 4.0
deleted 210 characters in body
Nov 15, 2018 at 10:15 history asked Dirk Boer CC BY-SA 4.0