Many people have argued about function size. They say that functions in general should be pretty short. Opinions vary from something like 15 lines to "about one screen", which today is probably about 40-80 lines.
Also, functions should always fulfill one task only.
However, there is one kind of function that frequently fails in both cri...
I have an object myObj, which is an instance of a class MyClass. Some of its instance variables always have their initial values passed in by the calling code. Other instance variables will be initialized in one of two ways. For an instanceArray of type NSMutableArray, the possibilities are either
instanceArray = [[NSMutableArray all...
Hey guys,
I was wondering what was the default values of variables before I intialize them ..
For example, if I do :
//myClass.h
BOOL myBOOL; // default value ?
NSArray *myArray; // default value ?
NSUInteger myInteger; // default value ?
Some more examples here :
//myClass.m
// myArray is not initialized, only declared in .h fil...
Hi,
I need just dictionary or asociative array string => int.
There is type map C++ for this case.
But I need make one map in my class make for all instances(-> static) and this map cannot be changed(-> const);
I have found this way with boost library
std::map<int, char> example =
boost::assign::map_list_of(1, 'a') (2, 'b') (3...
Hi,
After I have created a serious bunch of classes (with initialize methods), I am loading these into IRb to test each of them. I do so by creating simple instances and calling their methods to learn their behavior. However sometimes I don't remember exactly what order I was supposed to give the arguments when I call the .new method on...
Good evening,
I am developing a set of Java classes so that a container class Box contains a List of a contained class Widget. A Widget needs to be able to specify relationships with other Widgets. I figured a good way to do this would be to do something like this:
public abstract class Widget {
public static class WidgetID {
...
For global variables in C like
int aglobal = 5;
When does the 5 get transferred into aglobal by the loader and how does it know to put 5 in aglobal.
Same situation with a static declaration in a function. Like
int afunc()
{
static int astatic = 8;
return astatic;
}
...
Edited again because it originally wasn't clear that I'm trying to initialize the arrays at compile time, not at run time...
I've got the following reduced testcase:
typedef struct TestStruct
{
int length;
int values[];
};
TestStruct t = {3, {0, 1, 2}};
TestStruct t2 = {4, {0, 1, 2, 3}};
int main()
{
return(0);
}
This...
I just made an interesting mistake in my code:
Dim endColumn As Integer = startColumn + endColumn - 1
The code was actually supposed to be:
Dim endColumn As Integer = startColumn + numColumns - 1
The interesting thing is, I would think that this code should be recursive and loop indefinitely, as the initialization of endColumn sort...
How does one suppress the automatic initialization and destruction of a type? While it is wonderful that T buffer[100] automatically initializes all the elements of buffer, and destroys them when they fall out of scope, this is not the behavior I want.
#include <iostream>
static int created = 0,
destroyed = 0;
struct S
{...
I have the following in my Puzzle.h
class Puzzle
{
private:
vector<int> puzzle;
public:
Puzzle() : puzzle (16) {}
bool isSolved();
void shuffle(vector<int>& );
};
and then my Puzzle.cpp looks like:
Puzzle::Puzzle()
{
// Initialize the puzzle (0,1,2,3,...,14,15)
for(int i = 0; i <= puzzl...
Hi everyone,
I'm currently kicking off a background thread to do some REST queries in my app delegate's didFinishLaunchingWithOptions. This thread creates some objects and populates the model as the rest of the app continues to load (because I don't block, and didFinishLaunchingWithOptions returns YES). I also put up a loading UIViewC...
This question is related to the post here. Is it possible to initialize an array in a function call or constructor call? For example, class foo's constructor wants an array of size 3, so I want to call foo( { 0, 0, 0 } ). I've tried this, and it does not work. I'd like to be able to initialize objects of type foo in other objects' constr...
I have Angle class that I want initialized to a random value. The Angle constructor can accept an int from a random() function. Is it safe to place this call in the ctor list:
foo::foo() : Angle(random(0xFFFF)) {...}
or do I have to do it in the body of the constructor?
foo::foo() { Angle = Angle(random(0xFFFF)); ...}
If it matte...
I find myself using hash arguments to constructors quite a bit, especially when writing DSLs for configuration or other bits of API that the end user will be exposed to. What I end up doing is something like the following:
class Example
PROPERTIES = [:name, :age]
PROPERTIES.each { |p| attr_reader p }
def initialize(args)
...
Hi,
I installed the sml interpreter from here : http://www.smlnj.org/, I used the self extracting .EXE for windows. (I'm running windows7 64 bit)
Although simple operations on basic datatypes are working, it is not recognising operations on arrays/vectors (update, array constructor etc). Do i need to install something else as well to ma...
Hey all,
I need to make some connections on startup of a server. I'm using the wcf technology for this client-server application. The problem is that the constructor of the server isn't called at any time, so for the moment, i initialize the connections when the first client makes a connection. But this generates problems in a further p...
Here's a very simple example of what I'm trying to get around:
class Test(object):
some_dict = {Test: True}
The problem is that I cannot refer to Test while it's still being defined
Normally, I'd just do this:
class Test(object):
some_dict = {}
def __init__(self):
if self.__class__.some_dict == {}:
se...
ok this is just a shot in the dark but it may be the cause of most of the errors ive gotten.
when your initializing something. lets say a smal swing program. would it go like this
variables here
{
private Jlist contactList;
String [] contactArray;
ArrayList <String> contactArrayList;
ResultSet namesList
// constructor here
...
I just got a bug report from someone running an app I wrote under Windows XP. He says it won't start up.
The application failed to initialize
properly (0xc0150002). Click on OK to
terminate the application.
It works fine at my end, (under Windows 7,) and I don't have any Win7- or Vista-specific stuff in the program, so it shou...