I'm happy to see that Keith, Fritz, and Aaron have gotten the PluralSight website properly launched. I'm particularly pleased that Keith, Fritz, and Mike Woodring all now have proper blogs. These guys were some of the sharpest dudes at DevelopMentor...seriously.
Wednesday, May 26, 2004
Processing Command Line Wildcards
I can use a keyboard so much faster than a mouse that I just hate it when an app makes me click things instead of letting me type in shortcuts. So it's no surprise that I love working at the command line. One thing that distinguishes a good command line application from a bad one is whether or not it lets you use wildcards. For example, being able to do:
fooutil blah.txt *.cs abc????.xml
is a good thing - it lets me say, “Run fooutil on the file blah.txt, any file with a .cs extension, and files that have a name that start with abc, are seven characters long, and have an xml extension” all in one fell swoop.
As it turns out, getting this behavior in your app is pretty easy. Here's the code:
public static int Main(string[] args) {
foreach (string filespec in args) {
string specdir = Path.GetDirectoryName(filespec);
string specpart = Path.GetFileName(filespec);
// GetFiles will vomit on an empty specdir
if (specdir.Length == 0) {
specdir = Environment.CurrentDirectory;
}
foreach (string file in Directory.GetFiles(specdir, specpart)) {
string path = Path.Combine(specdir, file);
// Your code to process the file identified by path goes here
}
}
}
The key magic here is Directory.GetFiles, which will return you a string array of file names that match a given directory a pattern. Check out the docs for Directory.GetFiles to get the full scoop on what patterns are legal. Also note the use of Path.Combine - never combine path elements with +.
Tuesday, May 25, 2004
XPQ
Since Eric mentioned me, I feel all this pressure to post something cool and C#-related. OK, here's a neat little number:
public class App {
const string USAGE = @"Usage: xpq <xpath> <input>";
public static void Main(string[] args) {
if (args.Length != 2) {
Console.WriteLine(USAGE);
return;
}
XPathDocument doc = new XPathDocument(args[1]);
XPathNavigator nav = doc.CreateNavigator();
object o = nav.Evaluate(args[0]);
if (o is XPathNodeIterator) {
XPathNodeIterator iter = o as XPathNodeIterator;
while (iter.MoveNext()) {
Console.WriteLine(iter.Current.Value);
}
}
else {
Console.WriteLine(o);
}
}
}
What does it do? It lets you run XPath queries against files from the command line. I call it XPQ for XPath Query. So, for example, I can print the number of “foo” nodes in a doc by running:
xpq count(//foo) doc.xml
Or I can print the value of every “bar” attribute in a document by running:
xpq //*/@bar doc.xml
The way it works is by taking advantage of the XPathNavigator.Evaluate method, which runs the supplied XPath expression and returns an object. The type of the object you get back depends on the expression you provide. If the XPath expression evaluates to a number, you get a double. If it evaluates to a string, you get a string. And if it evaluates to a identify more than one node in the document, you get an XPathNodeIterator.
I'm sure there are 999 tools out there that do all this and more, but I love that the framework lets you do so much with just a few lines of code. And this one covers about 90% of the cases where I just need to know something quick about an XML document.
Monday, May 24, 2004
I'd Like to Thank the Academy
It's an honor just to be nominated, of course. I want to thank my parents, my director, and my dog Jimmy.
Wednesday, May 19, 2004
More Direct3D Afrikaans Translations
The third and fourth installments in the Direct3D tutorial series, are now available in Afrikaans. Thanks to Ernst Kuschke.
Tuesday, May 18, 2004
Moore of the Beginning of the End
I've been saying for years that Moore's Law will end in the next two decades. The typical response I get to this assertion is, “Oh, they'll just move on to the next thing...quantuum computing, multi-core processors, optical, whatever.“ This is basically an assertion of faith against an argument of physics - a typically human response. Which is why I'm pretty sure the computing industry is going to get totally blindsided when suddenly things stop getting exponentially smaller/faster/cheaper. What's Microsoft's business model when you have to buy a computer that's five times as expensive as the one you own now in order to support the features they're working on?
The key, of course, is to figure out a way to profit by announcing something that solves the problems while everyone else reels around in the smoke. My current best guess is “compiler technology,“ but that's another post.
It seems that Intel may already be experiencing an early little speed bump on the way to the giant brick wall.
The warning came first from a group of hobbyists that tests the speeds of computer chips. This year, the group discovered that Intel's newest microprocessor was running slower and hotter than its predecessor. What they had stumbled upon was a major threat to Intel's longstanding approach to dominating the semiconductor industry - relentlessly raising the clock speed of its chips. Then two weeks ago, Intel, the world's largest chip maker, publicly acknowledged that it had hit a "thermal wall" on its microprocessor line.
Sunday, May 16, 2004
FlexWikiPad 0.90
Yesterday I sat down and finally polished off supporting non-ASCII characters in FlexWikiPad. I have to say, I'm pretty happy with how the tool is coming along. Although it still has a few missing features, the bugs that are left are all ones I can ignore, and it's never yet lost any data for me. I've been using it pretty much every day for a few months now. It has completely replaced my use of OneNote, which I also really liked. I'm taking that as a sign that I must be on the right track.
Anyway, since I got the code to a good point, I went ahead and released version 0.90. Now I need to figure out what to work on next. One thing I miss is full-featured Find and Replace functionality - I definitely will be doing that soon, since I often find myself wanting it. But I can get the same effect with a command-line search of the underlying files, so I'm wondering if maybe I should add the other thing I really want to get in: configurability. Specifically, I'd like to move all the formatting to an XML config file so people can change fonts and regular expressions without having to wait for me to release a new version.
If you're interested in helping me out, now is the time. Go grab the tool, try it out, and make a feature suggestion here, here, or here in the comments.