To comment or not to comment

Damn, Chad Myer‘s post about mistakes of comment usage in code made me think !

I tend to agree with him about the fact that your own code should be self explanatory, so that code comment is redundant.
But on the other hand, sometimes a little comment about the flow of the code always tends to help me understand the code itself better.
That aside, my code doesn’t have that much of code comment ( except for the //TODO: lines ) !
So I had to search a bit, but found a good example IMO, to show of the need of code comment… This to answer Chad’s question !

So here it is, what do you think ? Is the comment valid, should it stay in the code ? I think it should ! It still seems very obvious, but I would like to keep it in.


/// The general list has 2 internal lists:
/// * one pointing to the actual objects in the database
/// * one pointing to the actual objects in memory
/// To get the total count we have to take following flow into account
/// * the memory reference can be different from the database reference, so we combine the 2 counts and subtract the objects that are already available in the database list
public int Count
{
int totalCount = 0;

totalCount = ReferenceEquals(this.internalListMemory, null) ? 0 : this.internalListMemory.Count;
totalCount += ReferenceEquals(this.internalListDatabase, null) ? 0 : this.internalListDatabase.listCount;
foreach (DictionaryEntry internalListDataObjectsElement in this.internalListMemory)
{
if (!ReferenceEquals(this.internalListDatabase, null) && this.internalListDatabase.ListFind(internalListDataObjectsElement.Key))
totalCount -= 1;
}

return totalCount;
}

[Update]
Like I stated above, maybe the code comment is a bit to abvious ( so it could be omitted, but I’m in favour to let it in ).
So here maybe another example… but also here a small suggestion, this could maybe be changed to a //TODO: version. Depending on the work flow of programmer and his Task list.


/// There is a bug with the Excel interop for Office XP ! We first need to set the current culture to en-US to get correct date time values
public void StartTimeProcessing()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

- Rest of code with use of the interop code
}

Default user Locale through .Net

kick it on DotNetKicks.com

For who doesn’t know this yet, I’m a software programmer !
Currently I’m working with Visual Studio 2005 and develop software with C#.

And every now and then you get stuck in a situation that seems hopeless :). Even with a large team of capable people and the vast code example base available on the internet, some problems seem unsolvable !
So let me tell you a small story about one of this problems I recently had.

First the current layout of the project, we create software, but we actually sell a complete system to our customers. This means that we will ship a Dell desktop model together the software ! Then our service people will run the install scripts on site and configure it to the needs of the customer. But during the configuration, the service guy has to create several users through the configuration program. These users are stored in Windows XP as actual users, so when the service guys creates a new user, the default settings for this user are coming from Windows XP itself.
More technical detail : there is a .Default user defined in the Windows Registry that acts as a template for each new user !

Now the problem with this setting… Each time the service guy adds a user he has to set this user to the correct Locale, depending on the country where the software is going to get used ! This because the user account for the service people is put to English – US and it could be that each user has to be set to Dutch – Belgium.

To facilitate the install, we had the idea of manipulating Windows XP in such a manner that during configuration of our software the service guy can pick one Locale that will have the effect that each time he adds a new user it will already have those Locale settings.

For this problem I was asked to come up with a good solution in C# !!
And well to cut a long story short, I haven’t found one !!!!! So I was stuck.
The only real solution I found had to many pitfalls, we regarded it as a ‘no go’. It consist of creating a CultureInfo object from a given LCID and dumping all data into the Registry node of HKEY_USERS\.Default\Control Panel\International ! Even though I think this should/could work, I think that string manipulating each value to the correct format would lead to many possible errors.

What happens when I’m stuck… I go around the internet and search for topics that are closely linked. Well let me say that since the dawn of Blogs, we are blessed with information and knowledge that has impact on real life development !!
As a blogger myself, I know that writing a good article with some tutorial knowledge so since developers started using this medium my life got a lot easier :).
Because of my current working position I follow a lot of MSDN blogs that have a close or near relationship with .Net, Visual Studio or C#. One of those blogs is the one of Shawn Steele, and let me tell you his blog is superb ! Easy to follow and the example code/solutions he posts are all eye openers for me.

Well because he had already written many posts about cultural settings, I tried to contact him to see if he could shed some light on my problem. And guess what, I got a solution within 24 hours !!!!! That isn’t even damn fast, that is just amazingly brilliant !! His original answer is situated here.
Thanks again Shawn !!

After looking at the solution, there are 2 lesson to be made :

1. Not everything can be done with .Net ( so hence the reason why I got stuck 🙂 )
2. Not all solutions need to be difficult ( just one Windows script command line does exactly what we wanted )

Now for all other people out there who would stumble upon this same problem, here is the code I used in .Net to launch the script, enjoy.


public void StoreCultureInfo(int lcid)
{
try
{
//First create a CultureInfo object from the given LCID code
CultureInfo cultureInfo = CultureInfo.GetCultureInfo(lcid);

//Setting the .Default user in the Registry can't be done through .Net code in a straightforward manner !
//But there is a way to do this through use of command line syntax, the details can be found here : http://support.microsoft.com/default.aspx?scid=kb;en-us;289125
//Reminder : This option will only work for Windows XP, in Windows Vista detailed solution can be found here : http://www.microsoft.com/globaldev/vista/vista_tools/vista_command_line_international_configuration.mspx

//First we need to create a text file with the correct Locale for the Default user
//The locale should be specified in Hexadecimal format !
string hexadecimalLCID = cultureInfo.LCID.ToString("X");
string localeConfigurationFile = Path.Combine(PathHelper.TempDirectory, "regopts.txt");
//Be sure this configuration file doesn't exist yet
if (File.Exists(localeConfigurationFile))
FileHelper.DeleteFileEvenIfReadonly(localeConfigurationFile);

using (StreamWriter streamWriter = File.CreateText(localeConfigurationFile))
{
streamWriter.WriteLine("[RegionalSettings]");
streamWriter.WriteLine("UserLocale_DefaultUser = {0}", hexadecimalLCID);
streamWriter.Close();
}

//Now execute the command line option to swith the default user locale !
Process process = new Process();
process.StartInfo.FileName = "rundll32.exe";
process.StartInfo.Arguments = string.Concat("shell32,Control_RunDLL intl.cpl,,/f:", "\"", localeConfigurationFile, "\"");
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
process.WaitForExit();

int processExitCode = process.ExitCode;

if (processExitCode != 0)
throw new ApplicationException("Problem occured while setting the Default user locale !");
break;
}
}
catch (ApplicationException ex)
{
}
}

Technorati tags: , , , ,

bk Cycling route management overview

Well better late then never 😉 I’ll give a small overview of my current progress in my cycling website.

So the real purpose is to have all available cycling network points charted onto a Google maps interface. This with the extra ability to create your own routes offline and share them with other people.

What’s currently available

  • I charted a small portion of available network points at the north of Mechelen
  • I added a bunch of network points from around Brugge
  • You can select network points that are connected through a route to build up your own cycling route
  • When you composed a route, you can save it and share it through a special designated url
  • You can also, during composition of your route, always clear the last selected network point

What’s currently on track for improvement ( some are up in a land of far far far far away 😉 )

  • Possibility to enter a location and jump to that location on the map
  • Get detailed route GPS information to show ‘nice’ tracks on the Google map
  • Give a clean printable overview page of the Google map and the network points selected
  • Let people add points of interest
  • Suggest a route between two distant network points
  • Update the design
  • Able to upload / download routes through GPX or KML

As you see this project has still some features that need to be added ! But since I switched from an asp.net to a PHP/JavaScript version, things got very easy 🙂 .

But still anybody who wants to help in any way ( programming, design or providing route data ), can always contact me through the contact form here on the blog ( upper right corner ).

Technorati tags: , , ,

Cry for help to all cycling people !

This post is a cry for help…
I’m shouting out to all the people who love cycling ! Actually I have to be more specific, a cry to all the cycling lovers in Belgium !


Logo thx to Mirthe

And why am I needing help, well I’m creating a new website that will allow people to plan and share cycling trips online !! This doesn’t sound very fancy, but the catch is, that you can use specific designated points ( called Fietsknooppunten in Belgium ) ! If you want to get more details about this concept, just have a look here ( in Dutch ).

So what do I need from you guys ? Well I need GPS coordinates ! Because now I only have a small set of bike points and I would like to add more… and I need a GPS log of the route between 2 points, so that the route is nicely displayed on the Google Map.

If you want to help, just use the email contact option here on my site ( right top of the screen ) to get in touch with me, so we can work out the details.

To get a feel of how the program works, just browse to my test site at FreeHostia.com ! BUT be aware this is a test site, so there could be down time. Normally you can already select several points ( that are connected to each other ) and save your selection as a cycling route !! You then get a shareable link ! AGAIN these links can disappear in time, because when the program is more stable I’m going to reset the database.

Enjoy and please support me in my quest !

UPDATE :Ok I have to be honest about this, it seems I’m not the only one with this idea ! Check out some other online route managers !! Here and here and an offline tool here

Technorati tags: , , ,

Clean .Net program install package = ILMerge

I just had to post about this little tool ! I think all people who are busy in software development using .Net, should at least have a look at it ;).

What am I talking about, well, a small tool called ILMerge. It’s available from the research part of Microsoft. So what is it about ?

Best way to explain a tool is by giving an example : Imagine you have several .Net projects that, all of them, create separate dll’s ! This is not uncommon and you probably designed your projects this way, because they reflect some sort of internal business architecture… so no worries here. But on the other hand you probably also have some solutions that incorporate several projects, who have some kind of common link between them. So wouldn’t it be nice if you could get all those projects, that are linked one way or another, inside one dll instead of separated ones ?

Well with ILMerge you can accomplish this ! It will combine several input dll’s into one target dll or even better, combine an exe and several dll’s into just one exe ! Another example is to combine code dll’s together with their resource assemblies !

This procedure is of course only relevant for deployment of your software, so developers don’t have to perform this step and still can program with the complete original dll base ! But before packaging the software, it would be ideal to merge several dll’s to get a cleaner, smaller install package.

On a side note, I received a small update by Scott Guthrie, that there will be an ASPNet_Merge.exe MS Build task with the Visual Studio 2008 release !! But no ILMerge task yet…

Technorati tags: , , , , , ,

DateTime formatting the .Net way

Back in the ‘old’ days when we where using Visual Studio 6 and made our first Visual Basic programs, we had to rely on ‘good luck’ and ‘plumbing’ to get some tasks done !

What I mean to say is, that sometimes the software would have a mind of his own ! Some code just didn’t perform in the correct expected manner. And this wasn’t something you actually could have avoided, no the software had some flaws !

But with the arrival of Visual Studio .Net and the new programming languages like C#, this seemed a thing of the past ! Until now that is ! Because I have a small code example I would like to show you, that would seems very straightforward, but has me ‘bugged’ whole week.

The thing I’m trying to do, is cast a normal DateTime.Now to a Time format, but depending on the current user settings ( in the regional settings ). What would seem like an obvious thing to do… So here we go with our little experiment !

  • First set your regional settings correct : English ( US )

  • Then go to Customize and in the Time pane change the time to display using the 24 hours notation ( and loose the AM & PM )

  • Create a small console application and paste following code ( we are talking Visual Studio 2005 here )

// Expected : True, Actual : True
Console.WriteLine(Thread.CurrentThread.CurrentCulture.UseUserOverride.ToString());
// Expected : H:mm:ss, Actual : h:mm:ss
Console.WriteLine(Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern);
// Expected : H:mm:ss, Actual : h:mm:ss
Console.WriteLine(System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortTimePattern);
// Expected : 10/13/2006 13:31, Actual : 10/13/2006 01:31
Console.WriteLine(DateTime.Now.ToString("g"));
// Expected : 10/13/2006 13:31:28, Actual : 10/13/2006 13:31:28 !!!!!!
Console.WriteLine(DateTime.Now.ToString());
// Expected : 13:31, Actual : 01:31
Console.WriteLine(DateTime.Now.ToString("t"));
Console.ReadLine();

So as you can see, the DateTime.Now.ToString(“t”) option will NOT take into account the current user settings, found on the regional settings pane ! This is not something I would expect… I would just like my code to be as little dependent as possible. So I WANT to use the default DateTime formatting options and not having to wander about what the user chooses. It must be up to the user to get the right format he wants, I just want to be able to tell the program to give me the Time and not the complete DateTime.

After this little experiment, I searched further for any information, but got back empty handed.

The only document on MSDN that says something significant about DateTime and the regional settings can be found here. But it just states the things I would expect in my test and they just aren’t true.

After this set back I contacted Chris Sells Program Manager in the Distributed Systems Group at Microsoft, hoping maybe he could shed a little light on my issue ! To be honest this guy is amazing ;), knowing he’s probably swamped with work, he still managed to reply me in a very fast time frame ( thanks Chris ) !

The first thing Chris noticed was that I could get the good user settings information through the following code :

System.Globalization.DateTimeFormatInfo.CurrentInfo.FullDateTimePattern

But this wasn’t helping me much… the real problem is not getting the info about the DateTime format, but displaying it correctly using the default formatters in .Net ! So this info is a bonus, yes, but still I’m stuck !!

So for now I use a small work around, that I would love to delete as soon as possible, by reading out the users settings of the regional settings through the HKEY_CURRENT_USER in the registry ( \Control Panel\International ).

Chris will still check his huge background information repository 😉 and hopefully come back with some good news. But if ANYBODY knows how I can solve this ‘little’ problem, please help me out !

UPDATE : well Chris got back to me on this problem… he submitted my question on some community and he got an answer from Michael Kaplan !
It seems he has answered this question before !! Take a look here for more info on the solution.

In short : “A lot of the confusion is due to the fact that the .NET Framework has two time formats (long and short) while Windows only has one time format (long) which can optionally be truncated in GetTimeFormat.” And : “So the answer to the original customer inquiry, to wit: “The main issue is that I don’t understand why/when .Net uses the user overrides of the Regional Settings” is that only one of the settings in .NET directly relates to the one in Windows, even though they both look like they ought to….”

Currently listening to : Autoharp – Hooverphonic ( The Magnificent Tree )
Del.icio.us tags: , , ,

Football – stop saying soccer

Ok this post is going to be a bit odd… it involves soccer !!

Not that I’m that big of a fan of the game, although I played it myself for most of my current life, but this little thing just has me hooked.

There is a social network game online, called Hattrick and it is created around the most popular sport in the world soccer. The objective is quit straightforward : manage your own team !

The setup is simple, first you create a free account on Hattrick and after a day you get a team assigned ! You’ll be placed in a small competition and will be able to play against the other teams inside your competition.

Sounds easy and it is, but what strikes my is the level of detail you have at your disposal to manage all kinds of settings ! A small list of things to do :

  • Assign a coach
  • Choose training schemas
  • Hire other staff ( like a doctor )
  • Buy and sell players at a special eBay like trading place
  • Manage the players on the field, choose the right positions and follow their progress
  • Choose different setup formats for each league game
  • Expand your home stadium

And the list just goes on and on ! After reading this you’ll think it to be overwhelming and impossible to manage, but it really is just easy…

What I find even more extraordinary is the fact that everything just runs very smooth and seems to be programmed with the old ASP technology ! You can even follow the games in real time, through text messaging !

Damn I wish I could create something like that !!

Currently listening to: Stereo MC’sWe Belong in This World Together
Del.icio.us tags: , , ,

Project maintenance

Let me post something that involves a bit of the Web 2.0 hype 🙂 !

Today several websites offer some kind of free ‘social’ service, that can be used by the general public. Very nice things are available for the web-generation !! Some examples :

* Grou.ps
* Del.icio.us
* Google calendar

The list is long…

But there is one GREAT drawback with all this Web 2.0 stuff : it are actually all programming projects, that need to be maintained, tested and if needed updated or enhanced !!
This means that people need to be involved and keep track of possible bugs ! This takes time and effort… so for some ‘free’ ‘opensource’ websites, this can be a pain in the a**, if not impossible !

On the other hand, some guys are doing a fine job and let me put some of these guys in front and give them the credit they deserve ! It seems a coincidence, but last week I had several problems with serveral online services/websites.
First thing to do in such an event is search the site for some way to contact the webadmin, programmer or support. If you can’t find a contact, maybe there are other options, like online support forums…

But the best thing is presenting the problem to the original owner.

Let us begin with : Grou.ps, they offer a great tool to ‘group’ people together in a ( pun intended ) group ! One of the main features is the option to add locations using Google maps and here I had an issue ! I live in Belgium and only recently Google maps was updated with a street level detail of our country ( since version 2.x ), but Grou.ps isn’t yet upgraded ! So I posted the problem on the website and voila even after one day I got feedback, stating they are looking into this and are aware they need to upgrade the Google maps software plugin ! The even created an internal bug ticket, how sweet !!

Secondly, I use PMetrics on my blog to keep statistics of the users that come and read the feeds ! They had an upgrade of their software so that it is usable as a Sidebar Widget in WordPress, a cool feature ! But when I switch on this feature, the statistics fail and aren’t visible anymore for the public… also here I posted an error report on the public forum. Again one day after the post I received a personal message with detailed questions to help the developer to search and solve the problem. Even a response was posted back on the forum !!

Last but not least, I follow several Wing Chun ( Wing Tsun, Wing Tsjun ) sites to read about this fine martial arts sport… and there is one that comes out a bit special : the Wing Chun Archive. It states that the site is a ‘collection’ of all information, schools, peoples and media about the art ! Of course this can’t be achieved without the help of a supporting audiance ! So I gave it a test and used the ‘suggestion’ form to add a new Cantonese translation… for the third time in a row, I got a response the next day !! The new phrase was added and the webadmin gave me a feedback on the update… The Wing Chun stance Yee Gee Kim Yeung Ma was added.

Well to be honest, I was very suprised by the hard work and commitment I got from these websites… this makes those services all the more enjoyable and I hope they keep up the good work !

Update: Seems Michel doesn’t like the Web deux point zero hype ;), well all I can tell is that he is right in stating that the ‘real’ web 2.0 isn’t new… But today people are more focused on the subject and try to integrate more, that gives us great new services !