Wednesday, April 26, 2006

Editing Project Files

Shawn Farkas once again comes up with an awesome tip in the huge and near-undiscoverable feature list for Visual Studio 2005. You can edit project files in Visual Studio (and get Intellisense and syntax-coloring by unloading the project, then an Edit option appears. The complete click-by-click here.

Monday, April 24, 2006

Maintaining client-side state but NOT on the client.

So you are writing distributed browser-based application in JavaScript. So you need or want to store some things client-side. Up to now, the best thing to do was to embed a Flash object and use Local Shared Obects to store that information. There are a couple things that aren't optimal about that:

  • Some version of Flash 6+ must be on the client box
  • You're subverting Flash via APIs that will change
  • You're limited to the 100K store-size of Flash (which still beats a 4K cookie)
  • The state is on the client machine

Along comes Les Orchard with a JavaScript wrapper around Amazon's newish S3 information store. Check out S3Ajax.

Think about these cool things:

  • You can store anything in S3, including your images and JavaScript
  • The client pays for the bandwidth and storage for their data
  • Someone else is responsible for backup and uptime
  • The client's data is available everywhere, not just on their machine

Monday, April 17, 2006

A tale of two implementations

Doing dynamic programming is all the rage these days. Some of the biggest proponents seem to be those that practice TDD. To that style of development, everything is fair game and dependency injection is used to solve many issues. Those injections are usually based on some reference to a provider of some sort. Others, caught in the declarative world of modern databinding are using named properties of objects.

Both worlds have need of the ability to link up the desired behavior, and they usually accomplish it through string constants that point at the desired provider or property. This is where one of my oldest code-smells kicks in; you can't dependency-check a string constant very well. The TDDers will tell you, "No problem, Mon! The tests will catch that." Old hackers like me don't want to wait that long (and that's one of the reasons type-less languages have so little appeal to me). We want something that will catch the errors for us immediately. Using things like Visual Assist's red-squiggle, the compiler's error messages, or even the IDE's cool automatic scoped rename ability keeps me from having to even run the test to catch the stupids.

So back to the string constants. How do we get the compiler/IDE to understand the connection? By making it a code link, of course. We want to replace those string literals with actual references, in some form, to the actual property or provider. This isn't a new problem, so it should come as no surprise that it's been tackled a couple of times recently for .Net development.

Let us study a couple examples and be us I mean you, I've finished my homework.

The wrong way: Get rid of nasty "string"

The right way: Static Reflection

Okay, are you back now? I'll wait, really...

What I don't like about the first idea is that it reads HORRIBLY. The code's intent is completely non-obvious, it creates all kinds of proxies where none are needed. It's ugly. Ayende's solution works without making any significant objects at runtime. The whole thing is just compiled away into a single delegate which will likely get optimized out of existance anyway.

What's the moral? If the code you are replacing is much easier to understand and maintain than the code you are using instead... you are not done refactoring.

Update: Of course this breaks down at pointing to properties because C# is overprotective, read the comments for the best-until-they-lighten-up-at-C#-land.

Excellent service is RARE, but it does exist.

It's kind of sad, but very true; you rarely get excellent customer service these days anywhere. This weekend I was graced with such service and wanted to pass on the recommendation.

On Friday evening, I placed an order for a ten-pack of Shure foamies and a set of Shure triple-flange sleeves for my excellent Shure E4c earphones at Sweetwater. I chose them because the prices were reasonable, and they offered free shipping. On Saturday afternoon I got a call from them, I missed the call, but the voice mail went something like this.

This is Brandon from Sweetwater. I was calling to let you know that we have your order for the Shure earpieces. The foamies are in stock, but the triple-flange are on order. Since you chose the free-shipping, which is UPS ground, I wanted to know if you wanted the foamies right away, or should we wait until the triple-flange is in stock. If we don't hear back from you, we'll ship out the foamies now and the triple-flange when they come in, but if you don't need them right away you can call me at 800-222-4700 extension 1236, and I'll send the order when the triple-flange sleeves come in; they are due in on Tuesday. Either way, the shipping is free.

Let's break this down... they returned my call on the weekend. They were going to default to shipping a partial shipment for free. They called to warn me about a two day delay on an order that was supposed to take around 5 days to ship anyway. They weren't doing this to save money... Brandon's time to make the call is easily equal to the shipping of something as small as the earphone sleeves. I'll be back, and I'll tell anyone that I know about service like this.

So, if you need any musician or sound equipment, even something as simple as new foamies for your earphones, by all means head to Sweetwater 800-222-4700 and ask for Brandon at extension 1236.

Oooo, cool

What was this all about? So arbitrary!
Can't we read about something interesting instead? Here's a list of really good links about dates and time.

Spell Checker for HTML and ASP.NET pages

Mikhail Arkhipov has released a cool spell checker for HTML and ASP.Net source pages. It uses the Office spelling engine, so you need Office installed, but it's really nice to keep stupid typos out of public-facing pages. Details here: Spell Checker for HTML and ASP.NET pages

If you combine this with WholeTomato Software's Visual Assist X, you get coverage of almost everything in your source. Visual Assist X does spell-checking of comments and quoted strings in source. If you haven't used Visual Assist yet, it's really an awesome tool. I've used it since the 1.0 days and completely forgot how hideous the default Visual Studio experience is without it until VS2005 betas started. For a brief time, I didn't have a corresponding beta from Whole Tomato and I was miserable. You get much better Intellisense, partial and embedded matching of symbols, more extensive syntax-coloring, multiple clipboard rings and tons of other really nice features, in C/C++, C#, ASP, VB [VS2003 and VS2005], and C/C++ [VC 6.0].

Wednesday, April 05, 2006

Why I can't just jump ship to Ruby on Rails...

412 Precondition Failed: "Precondition Failed The precondition on the request for the URL / evaluated to false."

I what way is this comforting? Does it just not like my browser? Don't ask me.

Update: Okay, I tried it on another machine, and it works there. So it doesn't like my browser!. I then used Rex Swain's cool HTTP View tool to see what was going on. I tried it from the working machine and saw a very different UA string. So I tried removing elements one-by-one to see what made it work. Eventually, I had removed most of the non-standard stuff (.Net CLR versions, etc.) and got it to work. Once I got it to work, I added the missing bits back one-by-one. It's not which strings are in there, it's how long the UA string is.

This is pathetic!

You don't let people see your site because their UA string is too long?