Questions tagged [lazy-initialization]
The lazy-initialization tag has no summary.
37 questions
1
vote
3
answers
211
views
Ensuring run-once behavior in a multi-threaded environment via volatile lambdas?
I'm coding an enum strategy pattern where one of the strategies makes use of an ScheduledExecutor:
class ControllerImpl {
//...
boolean applyStrat(StratParam param) {
getStrat().apply(...
2
votes
1
answer
1k
views
Is it a good idea to use a Lazy wrapper type to encapsulate lazy initialization in Java?
In our code base, we have several static or instance members that we would like to initialize lazily.
If the initialization cannot yield null, It's easy to implement.
Otherwise, one could use an ...
2
votes
1
answer
142
views
Modelling seats of a table in a social game
Assume we want to model a table where players can sit down to get together to play a game (card games, dice games, ...). Assume a few properties associated with each seat
class Seat
{
public int ...
1
vote
2
answers
518
views
C++ tactics / data structures / design patterns to avoid or postpone unnecessary object creation?
A couple of months ago I wrote a C++ program for computational mathematics that was supposed to compete with a highly optimized C code.
After a while I did manage to get it fast enough to beat the C ...
6
votes
1
answer
1k
views
Is it better to use lambda functions or boolean variables to record state
I have heard some people claiming that boolean state variables are generally bad and should be avoided when possible. Apparently in many cases it is possible to put state into lambda functions, ...
0
votes
1
answer
212
views
In what other locations besides infinite streams and infinite lists is memoized lazyness useful?
Haskell is one of the few non-strict languages out there.
In his paper Why Functional Programming Matters, John Hughes uses (memoized) lazy evaluation (as well as higher-order functions) to implement ...
4
votes
1
answer
1k
views
Webpack and Lazy Load for large-scale Web Application
Background
I am trying to develop with Webpack and JavaScript. Webpack would bundle all source code into one single file. When application becomes large, the file would be very large and cause ...
8
votes
1
answer
1k
views
Is there a name for the counterpart of the lazy loading pattern?
Definition of the lazy loading pattern from Wikipedia:
Lazy loading is a design pattern commonly used in computer programming to defer initialization of an object until the point at which it is ...
6
votes
4
answers
5k
views
How to avoid pollution of logic with lazy-loaded async properties
To be able to scale I would like to use async programming. It works really well if I have to read something from db and push to frontend, however I do not know how to use it correctly in blobs of ...
1
vote
1
answer
4k
views
Is there an easier way to do this with Lazy<T>?
I was trying to find a concrete example online but I couldn't find one that also used one of the class' other attributes.
So, can this be done more succinctly with a Lazy<T> object?
public ...
7
votes
2
answers
3k
views
How to populate Lazy object from database
I have these classes:
public class Order
{
private Lazy<IEnumerable<Volume>> _volumes;
long ID { get; private set; }
string Description { get; private set; }
IEnumerable&...
4
votes
2
answers
2k
views
Lazy loaded property signatures in business objects
Let's say I am designing business objects around a poorly optimized database that have no ability to change.
I have a Person object with a ShippingAddress property. The ShippingAddress is very ...
2
votes
1
answer
1k
views
Applying initialization-on-demand holder idiom at variable level rather than class
I was looking for the idiomatic way to implement thread-safe lazy initialization for a configuration collection retrieved from the DB inside a Spring bean.
I decided to adapt the initialisation-on-...
6
votes
2
answers
2k
views
Does laziness yield more race conditions?
I recently ran into a race condition while accessing a configuration setting. After examining what I could of the code, I came to the conclusion that the Configuration class' laziness1 was the source ...
0
votes
1
answer
240
views
Lazy-initialization vs preprocessing in image-based iOS app
I am making an iOS app which contains museum gallery: user can look through exhibits and then select info about it, etc.
On the exhibit screen I have two ScrollViews that are different, but are being ...
2
votes
2
answers
856
views
Lazy loading if collection would have any entries
I often see model classes with properties like this:
public IList<Note> Notes { get; set; }
public bool HasNotes { get; set; }
Where the list is initialized lazy, but the boolean property is ...
3
votes
1
answer
894
views
Lazy loading can lead to stale data, violates IoC?
Trying to be a better programmer
I have an application that keeps track of Roles and Permissions, I had classes for Role and Permission which were just value objects.
class Role
{
int RoleID
...
5
votes
4
answers
4k
views
What is a good pattern for combined caching and reinitialization?
I have a situation where I have three requirements:
Lazy initialization - don't create the collection until asked for it
Caching - keep the collection in memory on the object
Reinitialization - be ...
1
vote
1
answer
667
views
WPF: Reloading app parts to handle persistence as well as memory management
I created a app using Microsoft's WPF. It mostly handles data reading and input as well as associating relations between data within specific parameters.
As a total beginner I made some bad design ...