I'm sure it's been done before and I'm sure it will be done again. Sometimes habits work to your advantage and sometimes they don't.
Here's a case where a habit bit me recently.
static
void Main(string[] args)
{
try
{
object dbConnection = GetDbConnectionWithRetry(0);
}
catch (Exception oneException)
{
Console.WriteLine("oneException=[" + oneException.ToString() + "]");
}
}
private static object GetDbConnectionWithRetry(int recursionCount)
{
Console.WriteLine("GetDbConnectionWithRetry recursionCount=[" + recursionCount + "]");
object dbConnection = null;
if (recursionCount < 10)
{
dbConnection = OpenDbConnection();
if (dbConnection == null)
{
dbConnection = GetDbConnectionWithRetry(recursionCount++);
}
}
return dbConnection;
}
private static object OpenDbConnection()
{
// This is just a dummy method for sample code purposes
return null;
}
It's humorous in retrospect. Can you spot the bug? What habit should I break myself of?