Jeff Key

It works on my machine

Sponsors

My Job

My stuff

Old stuff

Useful Stuff

November 2003 - Posts

NullTextWriter

I'm trying to do some profiling on a command line app that uses a number of assemblies that spit out a bunch of debug information via Console.WriteLine (this isn't the intent and the calls have since been removed; I just don't have the latest bits yet).  This is no problem on the command line, as I can redirect output to null via “> nul”.  Unfortunately, this doesn't work when started from a profiler.

The simple solution was to add an optional “-null” argument to the application.  When that argument is given, I replace the standard out with a NullTextWriter, then re-add the standard out at program end in case any exceptions were thrown, etc.  Here's the magic:

public class NullTextWriter : TextWriter  {
    
public override System.Text.Encoding Encoding  {
         
get { return ASCIIEncoding.Default; }
     }
}

You can set the output stream by calling Console.SetOut(TextWriter).  Works for me.

Posted: Nov 29 2003, 09:43 PM by jeffreykey | with 2 comment(s)
Filed under:
SingleDrive

I've been acquiring new hard drives over the years as I rip more CDs, take more photos, etc.  As you'd imagine, it gets harder to keep track of what is where, what's worth keeping, what's not, etc.  I finally lost it yesterday and took a few hours to write something to create a single virtual drive.  It's nothing fancy like a file system driver, but simply a Windows Explorer-like app that shows all of the drives you want (including networked drives) as a single drive.  I have no idea if anyone else would find this useful.  If so, let me know and I'll clean it up and post the source on my site (and get a better icon).

“Features”

  • User picks which drives to use in the virtual drive, including network drives.  (This is good for me because my “server“ machine has two internal and two external.)
  • Folder tree view is an aggregate view of all of the folders on all the drives.  For example, although I have two or three “\Documents and Settings\Jeff“ folders on different drives, it shows up only once.  Every file is shown.
  • Send files/folders to the recycle bin.
  • View file/folder properties.
  • Open files.
  • That is all. 

Download

Posted: Nov 29 2003, 08:46 PM by jeffreykey | with 16 comment(s)
Filed under:
Please enter a path that does not contain embedded spaces.

What year is this?  1983? 

I'm installing Borland's Optimizeit profiler and things aren't looking good so far.  I get to the second page of the installer, which is all done with bitmapped fonts that I can hardly read, and get the above message.  I'll continue on and hope that the people that wrote the installer had nothing to do with the actual product development, and are shot.

Posted: Nov 29 2003, 07:20 PM by jeffreykey | with 4 comment(s)
Filed under:
Concise preview of C# v.Next and related technologies

Microsoft® has posted a Word® document titled “A Sneak Preview of Visual C#® Whidbey”.  It's a great, short overview of the language improvements as well as VS.NET, WinForms and ASP.NET info.  Check it out, you might learn something.

Microsoft, Word and Visual C# are either registered trademarks or trademarks of Microsoft Corp. in the United States and/or other countries.

Posted: Nov 28 2003, 04:44 PM by jeffreykey | with no comments
Filed under: ,
Where is the line between a property and a method?

Brad Abrams has started some really interesting API discussions over the past couple months.  It's great to see what the .NET teams are thinking about and it's nice to know they're listening to “the people“.  I've always found API issues to be particularly interesting, and Brad's blog doesn't disappoint.

One of the more recent discussions is Properties vs. Methods.  Sure, they're both really methods, but what does the consuming developer expect?  Most treat them like fields and expect that the cost is minimal.  What if that's the case 95% of the time, but the remaining 5% are (very) expensive?  Do you use methods instead?  Do you consider a different design altogether?  Read about this and more at Brad's Pad of API Happiness.

Why default parameters are bad

I've read in the past that default parameters in VB.NET are “bad”, but never saw an explanation.  Being a C# guy, I didn't really care to find out why since we don't have them.  BradA explains why.

Simply, the default value is compiled into the callerYes, that's right, this is your worst versioning nightmare.

Posted: Nov 28 2003, 03:08 PM by jeffreykey | with 1 comment(s)
Filed under:
Determining if a C#/VB.NET assembly was compiled as DEBUG or RELEASE

I had to figure this out a couple days ago and the answer isn't what you'd expect:  It's not FileVersionInfo.IsDebug or IsRelease, as neither compiler flips the required bit.  As far as I can tell, the only way is to look for a DebuggableAttribute on the assembly.

static void Main(string[] args) 
{
    Assembly assm = Assembly.LoadFrom(args[0]);
    bool found = assm.GetCustomAttributes(typeof(DebuggableAttribute), false).Length > 0;
    Console.WriteLine("Assembly is {0}.", found ? "debug" : "release");
}
Posted: Nov 23 2003, 07:52 PM by jeffreykey | with 4 comment(s)
Filed under:
Determining if a table exists

Quiz

How do you determine if a table exists in SQL Server?

a)  sysobjects
b)  information_schema.tables
c)  other

If my crack research team is to be trusted, the answer is “B”.  They claim the reason is that the sysobjects table's schema may change over time but the information_schema.tables view will not.

Six of one, 1/2 dozen of another. Or, sprocs vs. generated SQL

If you've been keeping up with the blog world the past week (I haven't) you've probably read or seen references to the multi-blog debate about sprocs vs. generated SQL.  The best post (and comments) I've seen so far is on Frans' site (85 comments as this went to press).

My thoughts:  Every problem is different.  Pick the most appropriate solution.  Easy!

InkLog: Huh?

So now there's a weblogging site for TabletPC users[1] to upload posts in Ink. 

This is progress?

I can't read my own handwriting, much less a good chunk of others'.  I think the TabletPC presents a great mode of input for a PC.  Very cool and handy.  But please, please, don't subject me to other people's bad handwriting.  I've noticed some other apps are treading in these waters and I hope it doesn't catch on.  The day I start receiving emails in Ink is the day I start my career in home construction and renovation.

[1] Link from fun guy Provost.

Posted: Nov 22 2003, 11:13 PM by jeffreykey | with 3 comment(s)
Filed under:
More Posts Next page »