Click here to Skip to main content
15,890,506 members
Home / Discussions / C#
   

C#

 
AnswerRe: Subjective question: which one of these Lazy Init is best Pin
Super Lloyd20-Oct-17 20:31
Super Lloyd20-Oct-17 20:31 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
Super Lloyd20-Oct-17 20:32
Super Lloyd20-Oct-17 20:32 
AnswerRe: Subjective question: which one of these Lazy Init is best Pin
jschell20-Oct-17 9:22
jschell20-Oct-17 9:22 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
Eddy Vluggen20-Oct-17 14:18
professionalEddy Vluggen20-Oct-17 14:18 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
jschell23-Oct-17 6:02
jschell23-Oct-17 6:02 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
Eddy Vluggen23-Oct-17 6:25
professionalEddy Vluggen23-Oct-17 6:25 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
jschell25-Oct-17 9:07
jschell25-Oct-17 9:07 
AnswerRe: Subjective question: which one of these Lazy Init is best Pin
Super Lloyd20-Oct-17 20:40
Super Lloyd20-Oct-17 20:40 
As I specify in my question I dislike that, and it was not the question. I think it's a matter of preference which is so for 2 reasons.
Just for your sake I will elaborate on my reasons.

Reason #1: Maybe creating the object is expensive and I want to delay its creation as much as possible? To improve startup time, for example, as it is usually the main strength of lazy initialisation.

Reason #2 I found the code below distasteful (a subjective matter, to be sure, but I think you will understand on seeing it), prone to refactor error, possibly needlessly expensive.
C#
public class MyClass
{
  public MyClass()
  {
    // I find this statement below confusing and prone to refactoring error
    E = new object(); 
  }
  /*
  * more than 10 lines of code
  * ....
  * ....
  * to make thing a little bit less clear
  */
  public object A { get; set; }
  public object B { get; set; }
  public object C { get; set; }
  public object D { get; set; }
  public object E { get; private set; }
  public object F { get; set; }
  public object G { get; set; }
  public object H { get; set; }
}
Remark if you have trouble seeing the point of my example above, silently refactor in your head E to NonNullPropertyThatIsExpensiveToInitialiseAndBasedOnPrivateState
A new .NET Serializer
All in one Menu-Ribbon Bar
Taking over the world since 1371!


modified 21-Oct-17 3:29am.

GeneralRe: Subjective question: which one of these Lazy Init is best Pin
Bernhard Hiller23-Oct-17 22:28
Bernhard Hiller23-Oct-17 22:28 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
Super Lloyd24-Oct-17 1:04
Super Lloyd24-Oct-17 1:04 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
Richard Deeming24-Oct-17 1:53
mveRichard Deeming24-Oct-17 1:53 
AnswerRe: Subjective question: which one of these Lazy Init is best Pin
BillWoodruff20-Oct-17 18:10
professionalBillWoodruff20-Oct-17 18:10 
QuestionRe: Subjective question: which one of these Lazy Init is best Pin
Super Lloyd20-Oct-17 20:52
Super Lloyd20-Oct-17 20:52 
AnswerRe: Subjective question: which one of these Lazy Init is best Pin
BillWoodruff20-Oct-17 22:42
professionalBillWoodruff20-Oct-17 22:42 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
Super Lloyd20-Oct-17 23:01
Super Lloyd20-Oct-17 23:01 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
BillWoodruff21-Oct-17 0:44
professionalBillWoodruff21-Oct-17 0:44 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
Super Lloyd21-Oct-17 1:21
Super Lloyd21-Oct-17 1:21 
QuestionRe: Subjective question: which one of these Lazy Init is best Pin
Super Lloyd20-Oct-17 21:10
Super Lloyd20-Oct-17 21:10 
AnswerRe: Subjective question: which one of these Lazy Init is best Pin
Sascha Lefèvre21-Oct-17 2:54
professionalSascha Lefèvre21-Oct-17 2:54 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
BillWoodruff22-Oct-17 6:08
professionalBillWoodruff22-Oct-17 6:08 
QuestionAttributes on fields in a DataTable/DataRow Pin
hpjchobbes18-Oct-17 10:27
hpjchobbes18-Oct-17 10:27 
AnswerRe: Attributes on fields in a DataTable/DataRow Pin
Gerry Schmitz18-Oct-17 18:08
mveGerry Schmitz18-Oct-17 18:08 
QuestionHow to reverse an array without using Array.Reverse()? Pin
Mubi Ace17-Oct-17 4:58
Mubi Ace17-Oct-17 4:58 
AnswerRe: How to reverse an array without using Array.Reverse()? Pin
Eddy Vluggen17-Oct-17 5:22
professionalEddy Vluggen17-Oct-17 5:22 
GeneralRe: How to reverse an array without using Array.Reverse()? Pin
Richard Deeming17-Oct-17 9:08
mveRichard Deeming17-Oct-17 9:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.