Skip to main content

Questions tagged [initialization]

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; ...
404 Name Not Found's user avatar
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 ...
wcminipgasker2023's user avatar
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 ...
glades's user avatar
  • 493
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 ...
James's user avatar
  • 11
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 ...
Eric Ouellet's user avatar
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. ...
pschill's user avatar
  • 2,010
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 ...
Benj's user avatar
  • 169
-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 = ...
Anon's user avatar
  • 3,633
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: """ ...
lucasgcb's user avatar
  • 365
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 ...
user avatar
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 ...
Luca's user avatar
  • 181
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 ...
samus's user avatar
  • 475
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) { ...
Dennis's user avatar
  • 8,257
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 ...
Mehdi Haghgoo's user avatar
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 ...
Mark's user avatar
  • 682

15 30 50 per page