sharp bites

standing on the shoulders of giants

Fix Time and Budget, Flex Scope

Here’s an easy way to launch on time and on budget: keep them fixed. Never throw more time or money at a problem, just scale back the scope.
[…]
If you can’t fit everything in within the time and budget allotted then don’t expand the time and budget. Instead, pull back the scope. There’s always time to add stuff later — later is eternal, now is fleeting. 37signals, Getting Real.

Experience

Experience is what you get when you don’t get what you want.
Dan Stanford

The key to success

I don’t know the key to success, but the key to failure is trying to please everybody.
Bill Cosby

Exce(r)ptions

Just a few notes on exceptions to remind, from Karl Seguin.
Handling exceptions
1 - Only handle exceptions that you can actually do something about, and
2 - You can’t do anything about the vast majority of exceptions

Logging
You should log every exception. Ideally you’ll centralize your logging - an HttpModule’s OnError event is your best choice for an ASP.NET application or web service.

Handling database access (and its possible exceptions):
using (SqlConnection connection = new SqlConnection(FROM_CONFIGURATION))
using (SqlCommand command = new SqlCommand("SomeSQL", connection))
{
connection.Open();
command.ExecuteNonQuery();
}


throw vs. throw ex
On occasion you’ll need to rethrow an exception because, while you can’t handle the exception, you still need to execute some code when an exception occurs. In this case you should use throw to preserve the full exception stack. Contrary, if you find yourself in a situation where you think you want to rethrow an exception with your handler as the source, a better approach is to use a nested exception:
catch (HibernateException ex)
{
if (transaction != null) { transaction.Rollback(); }
throw new Exception("Email already in use", ex);
}


When to throw
A method should throw when it wasn’t able to do what it was suppossed to do.

If you want a more in-depth explanation on the subject, I recommend you go and read the article

Ayende’s Challenge #2: The directory tree

Here comes a new challenge.
Given a set of versioned file, you need to cache them locally. Note that IPersistentCache semantics means that if you put a value in it, is is always going to remain there.


I’m glad this one wasn’t on a real interview, it took me quite some time to get this right, I guess I wouldn’t have get the job this time. xD

You can download the source from here or see it below. :)