Wednesday, August 5, 2009

MSDN Lightweight Mode

Long time, no blog. Mostly I update on Twitter now (http://twitter.com/craigandera) – it’s just easier to hurl a 140-character tidbit out than it is to write one of these posts. And I’m nothing if not lazy. But a reader posted a comment over here about MSDN Lightweight Mode. I checked it out, and it’s pretty cool, so I thought I would share it here on the blog, since I know not everyone watches my Twitter feed.

Anyway, have a look at http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates(lightweight).aspx (for example) and see what you think. I like it. I particularly like the fact that I can view just C# code (or just VB, or just whatever), as the noise generated by seeing all the languages is probably my only complaint with the loband view, which I still love and use as my primary interface to the MSDN website. 

I have no idea if this is an official thing, or an alpha that will disappear tomorrow, or what. Although I’m still doing work for MSDN, I only heard about this via the comment that Robert dropped on my blog. So hopefully I won’t get in trouble for sharing it, since I found out about it in public. :)

Check it out and see what you think.

Thursday, April 2, 2009

MSDN Loband Rocks

I mentioned MSDN Loband a few months ago. Well, they’ve updated it, and the update kicks some serious butt. Check it out here (the root of the MSDN library) or here (the docs for System.Xml.XmlReader, which show a more typical page). Note the navigation links on the left side, particularly the absence of the tree, and notice how much more streamlined – and therefore faster – the HTML is. I even had a friend tell me that it works pretty well on an iPhone over 3G…in New Zealand!

Now, once you’ve decided you like this version much better than the old one, click the “Persist low bandwidth view” link in the upper right corner and rejoice in the fact that you will always get this view.

I can pimp this one with a clear conscience because I had nothing to do with implementing it. Kudos to the team.

Wednesday, March 18, 2009

Using Extension Methods to Verify Assumptions

I was working on something with Tim yesterday, and between us we came up with what I think is a pretty cool trick. We were defining some extension methods on XElement and friends that make it easier to work work XHTML. Something like this:

doc.Html().Div(“foo”).Div(“bar”).Value

Which would pull out the text content of a div with a class of “bar” that was a descendant of a div with a class of “foo”. All well and good, but one of the problems we were trying to address is that we didn’t want to proceed if there was no div of class “foo”. A NullReferenceException would be thrown, but we wanted something more specific. So we came up with this:

public static T OrThrow<T>(this T obj, Exception e) {
    if (obj == null) {
        throw e; 
    } 
    return obj;
}

Which in turn allowed us to write this:

doc.Html().Div(“foo”).OrThrow(new MyException(“no foo”)).Div(“bar”).Value

The clever bit is that the OrThrow extension method is generic on the type it’s invoked on, and it returns that type, so you can insert it into a chained expression and you don’t lose any intellisense. And because of type inference, you don’t actually have to specify the type (you don’t have to type OrThrow<IEnumerable<XElement>>), which cleans up the expression a bit.

This approach is more general than just XHTML, of course. Really, it allows you to insert arbitrary assertions/checks into a series of chained calls using a fairly natural syntax (for some value of “natural”). Nothing you can’t do other ways, but we liked the way this came out enough to want to share it.

Friday, February 13, 2009

Hard Links in Windows Do Not Update Immediately

I was pretty excited when I saw mklink appear. Filesystem links can solve a lot of annoying problems, which is why you see them used all over the place in Unixy systems. Although, like salt, the key is to use them sparingly.

Which is why I’m so annoyed that the Windows version is pretty much completely useless. Soft links are only recognized in some contexts, but hard links are the real offender. Try this from an elevated command prompt:

> cd C:\temp
> echo foo > a.txt
> mklink /h C:\temp\hard-a.txt C:\temp\a.txt
> more hard-a.txt
foo

So far, so good. Now try this:

> echo more >> a.txt
> more hard-a.txt
foo
> more a.txt
foo
more
> more hard-a.txt
foo
more

WTF? My hard link doesn’t update immediately? That sucks!

From experimentation, it seems that it only updates after you’ve actually accessed the link once. Since one of the things I’d like to do is hardlink files into my Dropbox synchronization directory, this is pretty much a non-starter – they’ll never appear to be updated, and therefore will never sync. Unless I visit every file, which is pointless, because if I was going to do that, I could just copy them. Which is what I’m trying to avoid.

I’m more than willing to believe I’m missing something here, but if so I don’t know what it is. My best guess is that this is a bug in the filesystem caching code (I’m on Windows 2008).

Days like this make me want to switch full-time to my Ubuntu machine. Also not perfect, but at least the novelty makes me less sensitive to its shortcomings.

Monday, January 5, 2009

What Is All the Fuss About How You Can Write DSLs in Lisp?

I saw Chris’s recent post, and felt compelled to respond, despite the fact that I’m pretty sure I’m going to regret it. :)

Here’s what he says, abridged:

(when (and (< time 20:00)
                   (timing-is-right))
      (trade (make-shares 100 x)))

IMO, that's not a DSL -- that's just a set of function calls in an existing language.

The short version of my response to this is: “Yes! Exactly! That’s a feature, not a bug!” On to the longer version.

This argument, as a question of semantics, is fundamentally doomed to remain unresolved, unless someone can magically provide an exact definition of DSL that a) has no imprecision, and b) everyone agrees with. I’ll just pass on waiting for that to happen, and make my own observation:

A set of function calls in an existing language is generally preferable to a completely separate language. Particularly if it’s the language that you’re using to write the rest of your system. Sure, there are cases where using a specialized language is the thing to do, but over the last few years I’ve come to have a lot more - what’s the word? respect? fear? caution? – anyway hesitance around introducing additional languages into the development process. It’s not rare to see C#, SQL, XSLT, XPath, NAnt XML, regular expressions, and four or five other grammars floating around in the development lifecycle of a single process, and it’s got a real price. If nothing else, it means that not everyone can work on every part of the system. Throw in the fact that some of those are hard to debug, or have conflicting metaphors, or different performance characteristics, and it adds up.

So yes, one of the reasons that I’m excited about Clojure is that it’s a Lisp, and as a Lisp it is flexible enough to adapt to the point where I often don’t need a DSL. Or, if you like, where my DSL is also a Lisp. That doesn’t mean “I never want to use a DSL” or “I always want to use Lisp” – all things in moderation. It certainly doesn’t mean “You shouldn’t use M” – how the hell would I know what you need? But for me, I think it’s nice to have a tool that gives me the choice.

Wednesday, December 31, 2008

2008 – The Year in Review

It’s the end of the year, and although I skipped 2007, it is my habit to take a look back here on matters personal and professional. To whit:

I blogged a lot less this year. There are a number of reasons for that. The main one is that I’m just not as interested in blogging as once I was. I think that comes with the increasing “inward focus” my career has taken. I just find that more and more, what matters to me is what matters to me, not what matters to everyone else. That’s not a judgement or a boast, just an observation. It’s quite liberating: for example, I can go look at weird languages (see below) and not worry about it too much. :)

If you really can’t get enough Craig, you can always try me in appetizer size over on my Twitter stream. I seem better able to post a few dozen characters than a few paragraphs these days.

Career-wise, 2008 continued the shift I started in 2007 away from lots of small projects towards one big one. If I remember right, by the end of 2006 I’d worked on about seven different open source and proprietary projects, at a max of something like five simultaneously. That was too much, and I was feeling burned out. These days, pretty much all my professional time goes to a contract at Microsoft, where I’m working on the next version of Visual Studio. That has been very interesting for a variety of reasons, not the least of which is that it’s related to the work I’ve done on the MSDN REST Web Service.

Of course, the most significant event of 2008 had nothing to do with web services: it was the birth of our second child, daughter Susan. She was a cranky newborn, but has since turned into a charming and active baby. Needless to say, having two kids has really changed my life. I’m still coming to terms with giving up my free time – a painful process for me.

Not that I have no free time, of course. If I had none, I wouldn’t have been able to train for and run a marathon. But maybe I shouldn’t have talked so much smack in that post – Engberg whupped me good, and now I have to run another one. I think maybe this time I’ll make qualifying for Boston my stretch goal. Along the way, I’d also like to run a sub-20:00 5K. That’s much more my type of thing – I’m a fast runner, not an endurance runner.

This year saw my fascination with Lisp continue and even deepen, as is obvious from a variety of posts here. My latest interest on the parentheses front is Clojure. I made one (sort-of) provocative post about it, promised to say more, and never did. Well, given how not into blogging I am lately, I’m not sure whether I ever will live up to that promise. So go check it out for yourself: it really is an awesome language. Stu’s book is a good way to get started.

Here at the cusp of the new year, I don’t really know what 2009 will hold for me. I have a pretty good idea that the Microsoft work will continue for a while, but of course as an independent there’s always an increased level of uncertainty. But I like to think that it’s a rare problem that doesn’t yield an opportunity, so I’m optimistic.

On the family front, obviously we’re looking forward to watching both kids continue to grow and flourish. 2009 will be Ellen’s last full year of preschool, and of course Susan will likely start walking, talking, and doing all sorts of things. We hope to take family trips to Taiwan, Hong Kong, and Alaska, too.

On the professional front, I really want to spend more time working with Clojure. I’ve got some ideas for some real apps I can write, since that is, after all, the only true way to learn a language or platform. Plus it gives me a chance to run Ubuntu regularly, which I’ve been enjoying as a departure from the ordinary. (Clojure runs on Windows just fine, BTW.)

In the personal realm there are the running goals I mentioned earlier. I also hope to continue to fly Falcon, and maybe even DCS: Black Shark, which looks really sweet. If I somehow magically find extra time, and the basement finally gets finished, maybe I’ll even start playing bass and/or drums again.

Wishing you all the best in the new year.

Wednesday, November 19, 2008

A C# REPL (in Clojure)

It’s no secret that I’ve been interested in Lisp for quite a while. Lately, that has meant Clojure. Clojure is a new Lisp dialect that runs on top of the JVM. That means it has the power of Lisp (macros, dynamic typing, etc.) combined with the power of the JVM. The synergy reminds me of an old bumper sticker I saw years ago: “C: combining the speed of assembly with the power of assembly.” We’ve moved on a bit since then, but still. :)

Anyway, you should check out Clojure. It is easily the most exciting technology I’ve seen in years…probably since I first saw .NET in June of 2000. Even beyond just being a Lisp that actually has vast libraries (one of the main complaints against Lisps of the past) is the fact that there are some truly brilliant features of the language above and beyond what other Lisps sport.

One of the cool things I’d heard was that Clojure will run on top of IKVM.NET, which is a .NET implementation of the JVM. I figured that if there were a reasonable story for .NET interop, I’d be able to use Clojure to drive .NET code in a REPL. A REPL is a Read-Eval-Print Loop, which is a fancy way of saying “an interactive programming command line”. It’s like the immediate window in the Visual Studio debugger on steroids, and its absence is one of the increasing number of things that makes C# painful to use as I gain proficiency in more advanced languages.

Yes, I said it: C# is not an advanced language. If you think it is, then in my opinion you don’t know enough programming languages yet. :)

Intentionally provocative statements aside, here’s how you do it:

  1. Download and unzip ikvm.net. No installer required.
  2. Download Clojure. I recommend grabbing the head of the Subversion tree rather than the release that’s on the website.
  3. Build Clojure by running “ant jar” in the clojure directory. You’ll have to install Ant to do this if you haven’t already.
  4. Run “ikvmstub mscorlib.dll” to create mscorlib.jar, which will create the Java wrapper classes for the stuff in mscorlib.
  5. Launch a Clojure REPL via “ikvm –cp \path\to\clojure.jar;\path\to\mscorlib.jar clojure.lang.Repl”.

Now you have a working REPL, in which all the types in mscorlib are available to be driven by Clojure, which is most definitely an advanced language. Here’s a very simple example (the results of running the commands are indicated by =>):

(import '(cli.System DateTime))
=> nil

(new DateTime)
=> #<DateTime 1/1/0001 12:00:00 AM>

(.get_Now DateTime)
=> #<DateTime 11/19/2008 2:31:02 PM>

(.ToString (new DateTime) "R")
=> "Mon, 01 Jan 0001 00:00:00 GMT"

You get the idea.

Of course this is probably only useful as an exploratory tool: if I were writing Clojure for real, I’d write it against the JVM, not against IKVM.NET. But I use the excellent SnippetCompiler all the time now, but it’s still not the quite same thing as a real REPL, so I’m excited to have a real REPL available.

And really, the reason I’m posting this is that I’m hoping it will be a sort of gateway drug for you, and that what this will really do is kick off your interest in Clojure itself. The website is a pretty good source of information, but you can also check out Stu Halloway’s Programming Clojure book. It’s available in Beta form here. I’ve been tech reviewing it, and even the early beta looks pretty good.