Tuesday, June 9, 2009

A Difference between Visual C++ 2010 and Visual C++ 2008

I have just noticed that there is no more global option for specifying reference (such as include, library, executable, etc.) directories in Visual C++ 2010. Previously you could open the Options window using Tools – Options menu, and there was an item called VC++ Directories. This was extremely useful for specifying external SDK roots. For example, I use wxWidgets for some of my research projects, WTL for the UI coding, and also the ACE library. Since VC6 the right way to link to such SDK-like products was precisely through the VC++ Directories dialog.

However, in Visual Studio 2010 Beta 1 these settings are now made project-specific and are accessible via Project Properties window:

Project Properties window

I am wondering if the same behavior is going to apply for the final release. If so, I guess it would bring a lot of inconvenience, especially for team development. I hope, it is not more than a bug.

Cheers,
Kirill

Wednesday, June 3, 2009

Reusing Source Files in Multiple Visual Studio Projects

Sometimes you have a file F in a project P1, and you want to add it to your project P2 without actually getting a copy of the file. In Visual C++ you simple choose Add Existing Item, the rest is taken care of for you. However, in Visual C# (and maybe Visual Basic which I didn't test) even if you choose Add Existing Item and pick a file from an external folder, the file will be copied to your project folder.

I really find it awkward especially in case you have your files under version control. Luckily, I've just found a simple solution how you can share your source code between two or more projects without copying the files. At least for C# it works just perfectly. Furthermore, no 3rd party software is required!

You still choose Add Existing Item, then in the File Open dialog box you select your file and press the small arrow on the Add button. You should choose the Add As Link menu item:

Adding a file as a reference in Visual Studio

Then the your file reference should be displayed as an icon with a shortcut arrow in the solution tree:

File reference displayed in Visual Studio solution tree

Cheers,
Kirill

Wednesday, May 27, 2009

Google Blogger Is Imbecile

Google Blogger has the ugliest, stupidest, crummiest, dumbest, most diabolical, most idiotic, most moronic, most irrational (please post your comments with negative adjectives so that I could keep my list in better sync with reality) content editing interface!

Just figure out that when I switch to HTML editing and paste my article's markup written in a professional quality editor (plus I pretty much know HTML so I could use plain text editor as well), the formatting is all quirky! For example, new lines are treated literally instead of just producing a single white space.

C'mon, we're talking about Google! It's not MyGrannySoftware, is it?

Cheers,
Kirill

Tuesday, May 26, 2009

CodeProject Article: Exposing Events in ASP.NET Server Controls

I've just submitted an article to CodeProject. The article's main concern is adding events to your ASP.NET Server Controls. Although the topic may seem pretty straightforward, there are still some major optimization pitfalls that developers may not be aware of.
In this article I emphasize on using the Events collection. Code listings are provided in C#.

Cheers,
Kirill

Friday, May 22, 2009

In Front of a Change

Just recently I started to realize -- I don't want to be the way I am. I don't want to be employed the way I am now. I don't want to manage my time the way I do now. There is maybe a dozen more different "I don't want to"s but I'm just unable to figure them out right now.

I want to start my way towards financial freedom the way smart people do. I want to find something that would bring me creative excitement from having made something, fair amount of money for compensating for my work, lots of free time for other new ideas, and an open mind to find one idea from a hundred that is worth giving myself to.

I'm sure it's gonna be a hard path, but at least I made my first step -- declared my goals.

Cheers,
Kirill

Sunday, April 12, 2009

A Usability Issue in Office Communicator 2007

On my day job we use Microsoft Office Communicator 2007 for online conferencing and demos. Below is a screen I face every time my machine starts:

screenshot

As a good boy I always type my password to NOT SIGN IN:-) Maybe it’s “broken on purpose” as Seth Godin would say?..

Wednesday, April 1, 2009

The Way Mr. Torvalds Looks to Me Now

Just recently I've seen a movie on YouTube which is called Tech Talk: Linus Torvalds on git. In this video this man is so smart that any person, other than him, is "ugly and stupid". That's what the guy says almost literally.

I personally don't take it as a joke.

For example, he says, "How stupid a man must be to create Subversion?" Very nice, Mr. Torvalds. However, a lot of people (and me also) are happy with this great product. So I guess, we are all just "ugly and stupid".

What I say to that -- Mr. Torvalds is a Goebbels. Consuming his code is like taking a glass of wine from Goebbels.

Cheers,
Kirill

Wednesday, March 25, 2009

An Elegant Way to Parse C# Enums

If you're like me, you find the standard .NET way to parse Enums pretty awkward:

string aStr = "Truncate";
FileInfo aFN = (FileInfo) Enum.Parse(
typeof(FileInfo), aStr);

First, we have to provide the type of the enumeration twice. Second, I personally hate nested parentheses. I just cannot read the code with too many parentheses.

What I suggest is a thin wrapper:

public static class EnumParser<tEnum>
where tEnum : struct
{
public static tEnum Parse(string theVal)
{
return (tEnum)Enum.Parse(
typeof(tEnum), theVal);
}

public static tEnum Parse(string theVal, tEnum theDef)
{
try { return Parse(theVal); }
catch (ArgumentException) { return theDef; }
}
}

After several years of programming in C# I found I constantly use the exact same approach in most or all of my projects so I added it to my small C# toolkit.

The initial example would look more elegant with this new class in scope:

string aStr = "Truncate";
FileInfo aFN = EnumParser<FileInfo>.Parse(aStr);

The second overload allows us to use a default value:

string aStr = "Unknown";
FileInfo aFN = EnumParser<FileInfo>.Parse(
aStr, FileInfo.Truncate);

The provided solution is good but not perfect. Let's create another version of the EnumParser class:

public static class EnumParser
{
public static tEnum Parse<tEnum>(
string theVal) where tEnum : struct
{
return (tEnum)Enum.Parse(
typeof(tEnum), theVal);
}

public static tEnum Parse<tEnum>(
string theVal, tEnum theDef) where tEnum : struct
{
try { return Parse<tEnum>(theVal); }
catch (ArgumentException) { return theDef; }
}
}

As you see, we moved from a generic type to a non-generic type with two generic methods. Now let's look at the usage:

string aStr = "Truncate";
FileInfo aFN = EnumParser.Parse<FileInfo>(aStr);

The usage example when we don't specify a default value is almost identical to that of the generic type. However, things change significantly when a default value comes into play:

string aStr = "Unknown";
FileInfo aFN = EnumParser.Parse(aStr, FileInfo.Truncate);

As you see, we don't even specify the generic method arguments and the code will still compile successfully. The reason is: the compiler can resolve the arguments of the generic method from the argument that we specified. Our default value argument has now two roles: first, it is the value that will be returned in case the string is not recognized; second, it is an implicit type specifier for a generic method.

This is, of course, my favorite way to parse enums.

Cheers,
Kirill

Tuesday, March 24, 2009

Using AJAX CascadingDropDown Extender with Page.EnableEventValidation Set to True

Using the CascadingDropDown control extender that ships with the AJAX Control Toolkit requires that EnableEventValidation property of the Page containing the target DropDownList control be set to false.
However, this can potentially expose our page to a malicious attack, since nothing can then prevent "generated" post-backs.
A more elegant approach is creating a class that derives from DropDownList as follows:

public class NoValidationDropDownList : DropDownList
{ }

After the class has been created, all we need to do is replace the instances of the DropDownList class with respective instances of the NoValidationDropDownList class.

The reason why this works is simple: ASP.NET only validates controls that are marked with the SupportsEventValidation attribute. Since our class is not marked with this attribute, ASP.NET does not validate items on post-back and, consequently, no exception is thrown.

Cheers,
Kirill