Thursday, January 22, 2009

[C#, C++] Cascading Constructors

In C# you can call a constructor of your class from another constructor of the same class to do something like this:

class Cake
{
private string name;
private int price;

public Cake(int price, string cakeName)
{
this.name = cakeName;
this.price = price;
//init stuff
}

public Cake(int price):this(price, "Cheesecake")
{
//init other stuff
}
}

Unfortunately there's no way to do this in good old C++, but there are two common ways for simulating a similar behavior:

1) Combine two (or more) constructors via default/optional parameters:

class Cake
{
private:
string name;
int price;

public:
//combines Cake() and Cake("whatever")
Cake(int price, string name = "Cheesecake Giovacchia")
{
this->name = name;
this->price = price;
}
}

2) Use an Init method to share common code:

class Cake
{
private:
int price;
string name;

init(int price, string name)
{
//do crazy common stuff with price and name
}

public:
Cake(int price)
{
this->init(price, "Cheesecake Giovacchia");
}

Cake(int price, string cakeName)
{
this->init(price, cakeName);
}

}

That's about it, I prefer the first solution (the second kinda sucks) but if anyone knows better I am all ears.

I am done sucking for today.

Tuesday, January 13, 2009

Ask a Google Engineer - He Won't Answer

Recently I noticed a very promising initiative on Google Moderator: Ask a Google Engineer.

Geeks are encouraged asking questions to Guido Van Rossum & Co. with no limitation - from "Do you use Google toilet paper" to the infamous interview question "How would you sort 1 million 32-bit integers in 2MB of RAM?".

Turns out most of the question (roughly 1500 in total so far) asked by people (roughly 5000 so far) are silly complaints about how limited is this or why it's not possible to do that in gmail.
 
The rest are pretty much questions studied to impress Mr.Van Rossum with very elaborated Python blabbering or people trying to understand how to find the answers for the questions they are voting. 

But really - where are the answers? There are none (almost). Seen the amount of crap they're getting they're sitting it out to enable questions to be filtered by people votes.

Not exactly a success so far I'd say (maybe also because Google moderator kind of sucks imho)!

Thursday, January 8, 2009

Speed-up Visual Studio Startup!

Who thought getting rid of the splash screen could speed up Visual Studio this much?
Add a /nosplash to the visual studio shortcut target and see for yourself. 

Now, the question would be WHY is it so fast without splash-screen (something dodgy going on there), but this really made my day!