Questions tagged [initialization]
The initialization tag has no summary.
55 questions
2
votes
3
answers
247
views
What options are there to handle dependencies that may error?
I have an application, which contains a logger. The logger already exists and is ready to be used, so it can be passed directly to the constructor.
class App {
private readonly logger: Logger;
...
6
votes
4
answers
1k
views
How to avoid init methods when 2 objects need the reference of each other?
According to https://softwareengineering.stackexchange.com/a/334994/432039, I know init is a code smell and should be avoided, and one of the solutions is to use a builder to hold the state first ...
12
votes
4
answers
3k
views
How to initialize the same global resources from multiple modules independently?
I encountered the following situation: I have two modules, TokenService and Wifi which are initialized from main(). The modules themselves don't know of the existence of each other and function ...
0
votes
1
answer
254
views
Best way to accept a lot of user input from command line
I have a program that accepts computer names and then will perform CIM session tasks. The computer names are passed in from the user input and separated by "," (ex: program.exe -computers ...
3
votes
3
answers
1k
views
Is there any performance hit associated by the definition of a static constructor or due to availability of it?
This question is mostly related to the way language implementer do implements static class initalization (pretty specialized question). It is for curiosity and also to potentially improve my code to ...
0
votes
0
answers
454
views
Ensure that library has been initialized
I am using a 3rd party library that must be initialized with Lib::init() before any of its other functions may be called and that must be uninitialized with Lib::destroy() before the application ends. ...
2
votes
1
answer
118
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 ...
-5
votes
2
answers
221
views
What is the proper way to unspecify an integer's value in C++? [closed]
// Default initialization
int i; // i has an unspecified value
return i; // Probably 0, but Unreliable
i = 5; // i has a specified value
i = int();// This will give it a specified value, 0
i = ...
0
votes
1
answer
861
views
Python - Type Hinting specific sized Vectors
Considering a class method that takes a "vector" (Tuple or List of either int or float) of defined values such as the following:
import sys
from numpy import isnan, array, float64
class Shape:
"""
...
4
votes
2
answers
1k
views
Verifying Parameters in Constructor or Service
I was reading on this SO page about when to check parameters when constructing an object. The accepted answer suggests throwing the exception from the constructor so that an invalid object cannot be ...
1
vote
2
answers
5k
views
Calling a static method from constructor's member initializer list
I'm implementing a simple rendering system for a game engine. In my engine I have renderable entities that have a Model component (I'm using inheritance as opposed to a ECS for my engine for now, but ...
1
vote
1
answer
197
views
Passing 0's (literals) to a constructor
I have a function that creates a new object by passing to it's constructor integer ids primarily with values of 0. This function is called when saving a newly created record (not an edit).
public ...
1
vote
1
answer
585
views
Can you explain the behavior of PHP in cases when a parent class variable is masked by the child variable of the same name? [closed]
See the comment inside ChildEntity ::__construct():
class ChildEntity extends ParentEntity
{
/** @var int */
protected $classParameter;
function __construct(int $classParameter)
{
...
2
votes
2
answers
218
views
What is the meaning of injecting a component in programming?
Components common to all ExoPlayer implementations are:
A MediaSource that defines the media to be played, loads the media,
and from which the loaded media can be read. A MediaSource is
injected via ...
3
votes
4
answers
279
views
Advice for bugfixing object oriented code: why is data not set?
When debugging object oriented (Java) code, sometimes some field of some object is null while it should not be. I often spend what I feel is way too much time trying to figure out where it should have ...