A Few More Quotes…

Several people left comments when I posted a few of my favourite quotes, so here’s a few more.
The first quote in this list is from possibly one of the most brilliant men to have every lived, and one of my heros. I would have dearly loved to have met him.

I’m smart enough to know that I’m dumb.
Richard Feynman

A little knowledge is a dangerous thing.
Alexander Pope
[From an Essay on Criticism, 1709:
“A little learning is a dangerous thing; drink deep, or taste not the Pierian spring:
there shallow draughts intoxicate the brain, and drinking largely sobers us again.”]

Success is the ability to go from one failure to another with no loss of enthusiasm.
Sir Winston Churchill
He has all the virtues I dislike and none of the vices I admire.
Sir Winston Churchill

Any fool can write code that a computer can understand.
Good programmers write code that humans can understand.
Martin Fowler

All you need is ignorance and confidence; then success is sure.
Mark Twain

If you tell the truth you don’t have to remember anything.
Mark Twain

It was on fire when I found it!
– Anon

The Joy of (Deleting) Code: Less is More

I love coding! I can still remember when I first discovered programming at the age of eleven. At that age it filled me with a sense of wonder and it had the feel of a black art! But there’s one thing I like more than writing code…and that’s deleting it! That’s right, I just love deleting code.

Less code can mean less errors and less ‘cognitive friction’ when reading it, and therefore easier to maintain. I’m not talking about code that’s a candidate for the next obfuscated C competition! I’m talking about lean, simple, concise and precise code with no duplication.

The work days I like the most, are those when I leave work having refactored a large chunk of code (be it mine or someone else’s).

Liberate yourself, delete some code today!

Favourite Quotes…

OK, this is not a technical post, but I do like succinct, pithy quotes. They seem to sum up what we often do as developers, that is, reduce things to simple, but information rich forms, meme’s if you will. Here are just a few of my favourite quotes:

In the land of the blind, the one-eyed man is king.
Erasmus

Any society that would give up a little liberty to gain a little security will deserve neither and lose both.
Benjamin Franklin

Those who cannot remember the past are condemned to repeat it.
– George Santayana
(often paraphased as: Those that ignore history, are doomed to repeat it.)

Those who can make you believe absurdities can make you commit atrocities.
– Voltaire

Never hold discussions with the monkey when the organ grinder is in the room.
– Sir Winston Churchill
History will be kind to me for I intend to write it.
– Sir Winston Churchill

Everything should be made as simple as possible, but no simpler.
– Albert Einstein

Any fool can defend his or her mistakes … and most fools do.
– Dale Carnegie

Windows XP Service Pack 2 Support Tools

Every so often (actually quite often!), I come across something and I think “I really should have known that!” (bit like the F7 key in a command window…). Some time ago, pre-.NET in fact, I was playing around with some VB/Win32 API code written by L.J. Johnson, and put together a simple app. to display (among other things) domain group membership. I’m sure I’m the last person to know this but Microsoft have a freely downloadable set of Windows XP Service Pack 2 Support Tools that includes whoami.exe that can display your SID and group membership:

C:\> whoami /USER /SID

[User] = “HOMEDOMAIN\mitch” S-1-5-21-1935655697-117609710-839522115-1003

C:\> whoami /GROUPS
[Group 1] = “HOMEDOMAIN \None”
[Group 2] = “Everyone”
[Group 3] = “HOMEDOMAIN \Debugger Users”
[Group 4] = “BUILTIN\Administrators”
[Group 5] = “BUILTIN\Users”
[Group 6] = “NT AUTHORITY\INTERACTIVE”
[Group 7] = “NT AUTHORITY\Authenticated Users”
[Group 8] = “LOCAL”

Saw this via Bart De Smet’s blog.

Command Line Snippet (from Scott Hanselman of course!)

So I’m watching yet another great Hanselman webcast, and he casually mentions that if you hit ‘F7‘ in a command prompt window (cmd.exe), you get a history list of all your commands…wait a minute rewind that! I knew about the history list and the up/down cursor keys (as I’m assuming everyone does right?), but ‘F7’? And what do you know, the folks responsible for PowerShell have also included it!

CSS Control Adaptor Toolkit: Update Available

A recent on-going trend in web page design is for page layout to use pure CSS based layout instead of TABLE elements. [See References Zen Garden, Free CSS layouts for just a few examples.]

What are Control Adaptors? ASP.NET 2.0 has a new extensibility model built into it called Control Adapters. Control adapters allow you to plug into any ASP.NET server control through this model and override, alter or tweak how that control is rendered.

The great thing about control adaptors is they do not require developers to change the way they program against existing controls or to use new controls on a page. In fact, the developer can be completely unaware that a control adaptor is being used, because the control adaptor encapsulates all the functionality required. The ASP.NET 2.0 CSS control adaptor white paper can be found here.

A new Beta2 of the control adaptor toolkit is available and you can download it from here.

Scott Guthrie’s original article is here: CSS Control Adapter Toolkit for ASP.NET 2.0. His update article CSS Control Adapter Toolkit Update contains a Quick Start walkthrough. Excellent stuff!

.NET Exception Handling Guidelines: Catching Exceptions (part 4)

  • Unless you are writing framework code, do not consume non-specific errors by catching System.Exception or System.SystemException.
  • There are occasional circumstances when swallowing errors in applications are justified, but these are few and far between.
  • Do NOT over catch. Over-catching can hide bugs. Let exceptions propagate up the call stack.
  • Catch specific exceptions only when you know you can recover from them. Do NOT catch exceptions you can do nothing about.
  • If you can avoid throwing an exception, by using a TryParse, Exists or some other method, do so.
  • Use try-finally rather than try-catch for cleanup code.
  • For objects that implement IDisposable consider the using statement:
using (SqlConnection connection = new SqlConnection(connectionString))

{

}

  • Try to avoid catching and rethrowing: it can decrease the effectiveness of debugging.
  • If you do catch and rethrow an exception, use an empty throw rather than throw ex, otherwise you will lose the original exception’s call stack:

try

{

    //…code that might throw here…

}

catch (CustomException ex)

{

    // perform some specific handling here…

    throw; //rethrow the original exception

}

The links to the previous posts on this topic are here: part 1, part 2, part 3.

.NET Exception Handling Guidelines: Custom Exceptions (part 3)

  • Derive custom exceptions from System.Exception or one of the other base exception types (but not System.ApplicationException).
  • Suffix custom exception type names with “Exception”
  • Make exceptions serialisable, so they can cross remoting and application domain boundaries.
  • Provide the following constructors on all custom exceptions, and use the same parameter names and types:

[Serializable]

public class CustomException : Exception, ISerializable

{

public CustomException(){}

public CustomException(string message) { }

public CustomException(string message, Exception inner) { }

// This is required for serialisation

protected CustomException(SerializationInfo info, StreamingContext context) { }

}

part 1, part 2, and part 4 are here.