Running with Code Like with scissors, only more dangerous

10Jan/120

Please, don’t ever use the “Remove Unused Namespaces” feature

Posted by Rob Paveza

Seriously, I don't know why this feature exists or who thought it would be a good idea. The time it takes to compile even the most complicated C# file is trivial.

On the other hand, when I try to access the .Take() method in System.Linq, or the Encoding class in System.Text, or suddenly I need a new List<T> from System.Collections.Generic - if you have used a tool to remove unused namespaces from your C# code file - you have made me wonder why my editor isn't detecting it.

There's a reason that many default namespaces are included with a default C# code file. Leave them there! Maintenance programmers will love you forever.

14Jan/080

Another Reason to Avoid Automatic Properties

Posted by Rob

Another reason to avoid using Automatic Properties:

[Name("Simple Property Example")]
[Browsable(true)]
public string TestProp1
{
    get;
    set;
}

Look at the property in the debugger:

Oh wait, I can't.

I can't even set a breakpoint to let me know when the property is being accessed.  I understand not being able to see the backing store or the value component - they are after all not part of the code.  But you can't even see when they're being hit.

All I have to say is...

STAY AWAY.

2Jan/080

Where Have All My Gigabytes Gone?

Posted by Rob

I don't know if this is a Windows Vista-specific trick, or maybe something related to Volume Shadow Copy (the service that supports System Restore), but there seems to be a major discrepancy on my hard drive.

In Windows Explorer, open the C drive, select all, then Alt+Enter to open the properties dialog.

Size: 128gb (137,787,853,411 bytes)
Size on disk: 129gb (138,600,678,813 bytes) (Note: I don't know how there's an odd number of bytes, except that apparently NTFS uses some type of odd clustering strategy - to my knowledge, the "size on disk" field should be a multiple of 4,096, the default NTFS partition cluster size for this size disk).

Now I navigate up to My Computer, right-click on the C drive and choose properties.
Used space: 267gb (287,193,178,112 bytes)
Free space: 664gb (713,020,395,520 bytes)

(This drive is a RAID-0 stripe of two Maxtor 500gb SATA drives)

Now if I set it to display protected OS files and folders, I can come up with a few new items:
4gb in hiberfil.sys (Hibernation support)
4gb in pagefile.sys (Virtual memory swap file)
132gb in \System Volume Information (System Restore)

Looks like I've discovered the reason for the space usage - System Restore.  Ugh.  Hard to believe I've had this installation of Windows active for about, what, not even a week?  And System Restore has managed to take up more space than the files I've installed.  The good news is, with it set at 15%, I'll probably only get another 7gb taken.  Still....  It's just incredible to me that it's filled so fast.