-
Enhancement
-
Resolution: Fixed
-
P4
-
8
Richard Bair writes:
I'm looking at WebHistory. One thing I would recommend is, when there is not a good reason for using lazy initialization of properties, then go ahead and create the properties eagerly. For example, the WebHistory currentIndex property probably should just be created eagerly since I would venture to guess that currentIndex is pretty well always used. Also, I suspect it is also true that there will only be a few WebHistory objects in existence at any given point in time, and as such, any memory savings due to lazily initialization is probably very small.
In such cases, I prefer to just create properties eagerly because it doesn't hurt (on balance it has no real impact either way in a case like this one, but technically it will be slightly faster at runtime eager because the setter doesn't require checking whether the property is null all the time or invoking a method -- but in this case it is invoked so rarely it won't make any real difference), and because it makes the code a little simpler.
I'm looking at WebHistory. One thing I would recommend is, when there is not a good reason for using lazy initialization of properties, then go ahead and create the properties eagerly. For example, the WebHistory currentIndex property probably should just be created eagerly since I would venture to guess that currentIndex is pretty well always used. Also, I suspect it is also true that there will only be a few WebHistory objects in existence at any given point in time, and as such, any memory savings due to lazily initialization is probably very small.
In such cases, I prefer to just create properties eagerly because it doesn't hurt (on balance it has no real impact either way in a case like this one, but technically it will be slightly faster at runtime eager because the setter doesn't require checking whether the property is null all the time or invoking a method -- but in this case it is invoked so rarely it won't make any real difference), and because it makes the code a little simpler.