initialization

Necessary and sufficient validations upon application init

Hello again. I have a new puzzle for you :-). I was thinking on how should an application handle his own start up. Like : checking for required libraries, correct versions, database connectivity, database compatibility, etc. To be specific, here is the test case. I use SWT and Log4J, for obvious reasons. Now, the questions : Should ...

Initializing temporary aggregate object using curly braces.

Let's say I have a class: class Aggregate { public: int x; int y; }; I know how to initialize an object using curly braces: Aggregate a1 = { 1500, 2900 }; But I can't find a proper syntax to create temporary object and pass it as an argument to some method, for example: void frobnicate(const Aggregate& arg) { // do...

Set a String to "" or leave it null?

I have some String variables which are getting the values from invoking the function getParameter() and some of this variables will probably be null. Later, I will evaluate this variables using equals() method. Should I set all the String variables to the empty String ("") if they are null to avoid any problems? ...

C++ static global non-POD: theory and practice

I was reading the Qt coding conventions docs and came upon the following paragraph: Anything that has a constructor or needs to run code to be initialized cannot be used as global object in library code, since it is undefined when that constructor/code will be run (on first usage, on library load, before main() or not at all). Even i...

Initialize custom class according to user selection

Hi, I have a navigation based application with two levels, in the second level the user select an option which should cause initialization and loading of the proper Nib file (there is a Nib file for every available selection). Now I'm doing the initialization in a switch, based on the user selection. The problem is that I'm adding Nibs...

How to generate a list of 150 cases initialised with a dict in Python ?

I would like to create a list like this list = [] for i in range(150): list.append({'open': False, 'serve': False}) But is there a better way in Python to do it ? ...

Initialize window code Mac OS X

I'm currently reading "the red book" for learning OpenGL properly, and in one of the first examples, the author writes a line that says "InitializeAWindowPlease();" as a place holder for the code that will make a window to draw the OpenGL content in. Since I'm using Xcode for my programing, I know that I "get" a window to work with aut...

Is there a way to initialize an object through a hash?

If I have this class: class A attr_accessor :b,:c,:d end and this code: a = A.new h = {"b"=>10,"c"=>20,"d"=>30} is it possible to initialize the object directly from the hash, without me needing to go over each pair and call instance_variable_set? Something like: a = A.new(h) which should cause each instance variable to be ini...

BASH script passing stdin input to a program and giving control back to user input

(I looked everywhere for this, perhaps my googling skill is off today) I have a program that requires a handful of initialization cmds from stdin (and not through arguments). It'd be nice to move those commands into a script so when the script completes I can start keying the real work. So something like: cat initcmds.txt | myprogram.e...

Object initialization in CSharp

When i have declaration like: class Professor { string profid; public string ProfessorID { get { return profid;} set { profid=value;} } student st; } class student { string name; string id; public string Name { get { return name;} set { name=value; } } public string StudentID { get { ...

How does "this" escape the constructor in Java?

I've heard about this happening in non thread-safe code due to improperly constructed objects but I really don't have the concept down, even after reading about in in Goetz's book. I'd like to solidify my understanding of this code smell as I maybe doing it and not even realize it. Please provide code in your explanation to make it stick...

Initializer list *argument* evaluation order

So, the C++ standard requires that class members be initialized in the order in which they are declared in the class, rather than the order that they're mentioned in any constructor's initializer list. However, this doesn't imply anything about the order in which the arguments to those initializations are evaluated. I'm working with a sy...

Initializing Generic Variables in Scala

How do I declare a generic variable in Scala without initializing it (or initializing to any value)? def foo[T] { var t: T = ???? // tried _, null t } ...

What happens to a declared, uninitialized variable in C? Does it have a value?

Quick question-- if in C I write: int num; Before I assign anything to num, is the value of num indeterminate? ...

C struct initialization using labels. It works, but how? Documentation?

I found some struct initialization code yesterday that threw me for a loop. Here's an example: typedef struct { int first; int second; } TEST_STRUCT; void testFunc() { TEST_STRUCT test = { second: 2, first: 1 }; printf("test.first=%d test.second=%d\n", test.first, test.second); } Surprisingly (to me), here's the...

Value assignment in C#

Without initialization how is it possible to assign values to arrays? string[] s={"all","in","all"}; I mean why did not the compile show error?.Normally we need to initialize ,before assign values. ...

How to initialize a class?

The problem is really simple, I have a class "Stock", I want to load its property "StockName", "StockCode' from the db. so which patten should I use? pattern 1) Use service class to create it public interface IStockService{ Stock GetStock(string stockCode); void SaveStock(Stock stock); } p...

What do the following phrases mean in C++: zero-, default- and value-initialization?

What do the following phrases mean in C++: zero-initialization, default-initialization, and value-initialization? What should a C++ developer know about them? ...

array initialisation

Hi all, I'm quite certain that arrays of built in types are unitialized, whereas arrays of UDTs are default initialized. int foo[5]; // will contain junk Foo foo[5]; // will contain 5 Foo objects that are default initialized This occurs regardless of whether the array is allocated on the stack or heap. However, I'm finding it hard ...

When do I have to use initializer lists for initializing C++ class members?

let's say I have std::map< std::string, std::string > m_someMap as a private member variable of class A Two questions: (and the only reason I'm asking is because I came across code like that) What's the purpose of this line: A::A() : m_someMap() Now I know that this is intialization, but do you have to do this like that? I'm c...