.comment-link {margin-left:.6em;}
Gert .Net
[GertDotNet]
20040121
 
The laws of Gert
When writing code, I use the following "Laws of Gert" to guide me:


  1. 1st law of Gert: No magic numbers

  2. Conservation of code

  3. Laws are meant to be broken, or changed



1st law of Gert: No Magic Numbers


Never use numbers like 1, 2, 1000 etc. Using magic-numbers will make stuff unclear and hard to change.

Conservation of code


In time, the number of lines of a solution to a problem allways grows. When extra information is found, this allways means you have to extend the code. You can never just delete code.
In everyday life this is also true: When fixing a gap in the laws, the government just adds some, they will never delete laws.

Laws are meant to be broken, or changed


If you dont, you get an inflexible system.
In everyday life this is also true: If not, we should not need a parliament.

20040108
 
Calculate an Age using C#
Looks like there is no default library function to calculate the age in years of a certain person. This is what I use starting today:


public static int CalcAgeInYears(DateTime birthDate, DateTime now) {
int result = now.Year - birthDate.Year;
if (now.DayOfYear > birthDate.DayOfYear) {
return result;
} else {
return result - 1;
}
}


Powered by Blogger