Array.indexOf and Bad Evil IE

For Christ’s sake, Microsoft, it’s only been about 9 years since the rest of the world started supporting Javascript 1.5, don’t you think it’s about time your browsers started supporting Array.indexOf?

WTF, Microsoft?

The origins of vandalism

I’ve always been fascinated by discovering the origins of the language we use today. I’m reading the excellent Lost to the West: The Forgotten Byzantine Empire and a story early on in the book regarding the long fall of the Roman Empire caught my attention for its connection to the modern term “vandalism.”

The story goes like this. In 455BC (or BCE if that’s what you prefer) Rome had just narrowly avoided being ransacked by the Mongol horde when Atilla the Hun died in his sleep while camped with his army not far from the gates. The city celebrated in typical Roman fashion — with a coup: The Emperor Valentinian III was deposed and killed by a usurper named Petronius Maximus. Petronius then immediately married the widowed empress and cancelled the betrothal of Valentinian’s daughter to the heir of an allied North African king named Genseric.

Thus antagonized, a letter from the empress requesting aid was all the excuse Genseric needed to set sail with an army from (an apparently rebuilt and unsalted) Carthage, cross the Mediterranean Sea and lay siege to Rome. When word reached the city that Genseric’s army was on the move, Petronius and the Senate fled, leaving the city without a leader to mount a defense. This left the Pope as the only real authority remaining in the city.

Pope Leo I was a singularly brave and persuasive figure – less than 10 years before, Leo had walked into the camp of the fearsome Atilla the Hun and persuaded him to withdraw from the city and leave it unmolested. Once again, the aging Pope had to leave the city and walk into the camp of a hostile invading army in order to beg for the mercy of a conquering general on behalf of the citizens of Rome. What must have been going through his mind…

Pope Leo was, once again, successful, extracting a promise from Genseric to keep murder and mayhem to a minimum in exchange for the surrender of the city. Genseric’s army spent 14 days systematically looting the city, but violence was indeed kept to minimum. News of the event was, nevertheless, greeted with horror as it spread throughout the known world. The horror was so deep that the name of Genseric’s people — the Vandals — survives today as a synonym for senseless property destruction: vandalism.

That the Vandals got pinned with this bad rep is surprising to me. After all, Rome had been sacked twice before by this point in its history, once by the Gauls in 387BC and again by the Visigoths in 410AD. The Visigoth sack of 410 was, by all accounts, much more violent (the looters reportedly broke into and defiled the tomb of Augustus), so why aren’t we talking today about visigothism? Perhaps it was precisely because so few people were killed during the Vandal sacking — more people were left alive afterward to survey the damage and repeat the story — that it became infused with such a mystique.

As an epilogue – the word vandalism is the only real Vandal claim to fame that endures today. As a people they were almost completely extinguished from history in 534AD when their North African kingdom was invaded and conquered by the Byzantines during Justinian’s reconquest of the Western Roman Empire. As they say, revenge is sweetest when cold.

NYT’s $40 million paywall… Javascript + CSS??

I kept hearing off and on all day today about the “paywall” thing hitting the New York Times today. Apparently the idea is to monetize the small end of the news media’s money bucket: traditionally, 25% of revenues comes from subscriptions, the remainder comes from advertisers.

Folks blathered on all day about how it was either going to save the industry or was the biggest waste of time ever. While listening to said blathering, I honestly didn’t stop to consider two things:

1. How, exactly, did they manage to spend $40 million on a paywall?
2. What sort of paywall does $40 million buy you?

I’ll answer #2 first. Apparently $40 million buys you a paywall that’s not worth a damn. This one can be defeated by a really simple stylesheet hack.

To me, this just smacks of total and complete incompetence… rule #1 in client-server development is, You don’t send things you don’t want seen out to the client. I mean, we’ve known that for decades.

For #1, I honestly don’t have an answer. I don’t know how a business that makes the majority of it’s revenue from subscription and advertisement spends $40 million dollars creating a system to track who is reading what when.

What I do know is that an advertising and subscription business that’s not already tracking this stuff is probably not going to be in business for long (perhaps that’s the root of the print media’s problem right there)… and that I would have built the thing for the low price of $1 million.

NYT, when you start looking for folks to fix this fiasco for you, let me know!

Baked Penne/Ziti and Sausage Experiment – Part… something

I have been trying for some years to refine a favorite italian dish – baked ziti pasta and sausage. I decided, since I’m not posting anything else here, I’d chronicle the results from my most-recent recipe permutation…

Note to anyone reading this and following along – this recipe is a work in progress, and what I’m reporting as Part 1 here is actually attempt number 5 or so. The ingredients and exact timing varies, but the general idea remains the same.

5 spicy italian sausage links (about 1 pound)
1 box ziti pasta (penne will do… I can’t ever find real ziti either — about 13 oz)
1 jar tomato/spaghetti sauce (as per taste – basil & parmesan here)
1/2 medium red bell pepper
1/2 medium green bell pepper
1 medium banana pepper
1 small habanero pepper
1 can Rotell Tomatoes
1/4 cup diced white onion
1/2 tsp oregano
1/4 tsp rosemary
1/2 tsp sage
1/2 tsp basil
1/4 tsp black pepper
approx 4 tbsp minced garlic (to taste, I use a lot)
pinch cayenne pepper
pinch tarragon
pinch thyme
olive oil (again, taste here)
8 oz mozzarella cheese
1 small tub (8 oz?) ricotta cheese

Cook pasta as per instructions for “al-dente”, adding ~1 tsp garlic and olive oil before water boils.
Preheat oven to 425
Dice up the fresh peppers and onion
Remove casings from italian sausage (if applicable)
In a saucepan/skillet, heat about 1/2 cup oil over medium-high heat, adding 3tbsp garlic and spices.
Add peppers and onion when oil is hot.
Add sausage when onions begin to caramelize.
Cook until sausage is brown, stirring frequently, then remove from heat.
Open the tomato sauce, setting aside approximately 1/4 of it in a small saucepan.
Once pasta is cooked, place about 1/2 of it down in a medium casserole dish.
Place about 1/2 of the sausage mixture down on the pasta
Stir ricotta thoroughly and set aside approximately 1tbsp
Add remaining ricotta to casserole on top of sausage mixture
Add about 1/2 of the remaining tomato sauce
Cover with mozzarella chese
Add the remaining sausage mixture
Add the remaining pasta
Pour the remaining tomato sauce and 3/4 of the Rotell on top of the casserole
Cover again with mozzarella cheese
Bake for 20-25 minutes — until cheese is brown
Add remaining ricotta cheese, olive oil, and garlic to saucepan containing tomato sauce
Bring to a slow boil over medium low heat, stirring frequently, then remove from heat.
Pour sauce mixture over pasta immediately after removing from oven
Let stand for 10 minutes and serve

Serves 4-6 or more.

Good and spicy this time, feels like the right amount of pasta and sausage. We both liked it.

Thoughts for next time:
At least partially drain the sausage before adding it. Since we’re browning it now, there’s a lot of grease.
The ricotta is hard to work with, perhaps taking it out of the fridge a couple hours before cooking will help.
Less ricotta, more mozzarella and sauce in the casserole.
The pour-over is perfect!
Bake a little longer, maybe 30-35 minutes.

XAML FlowDocuments — Stop the insanity

Ask anyone who’s done any work with it for any length of time, and they’ll confirm the .NET Windows Forms stuff sucks. The controls all feel like they were designed by first year college students, and doing anything remotely beyond normal with the toolkit is an exercise in insanity.

This is why, when I decided I needed to build a Windows desktop app for personal use, I’d look into WPF. This app needs to have a pretty rich and non-standard UI, and it needs to display some arbitrary text and image content. WPF seemed well suited to the former, and HTML jumped out at me as an obvious choice for the latter.

After some expected struggles with the new layout model, I started googling for ways to display HTML in a WPF application. I skipped past hacks like hosting an IE instance inside my application (dear God, no) onto something Microsoft is calling “FlowDocuments.”

FlowDocuments seem to be some attempt to leverage XAML into the layout and publishing world… because, yeah, what the world really needs is another document layout language. Regardless, based on my admittedly limited research, FlowDocuments look to be the only sure bet to displaying arbitrary content in a WPF application.

This is disappointing, because it looks as though Microsoft has attempted to re-invent HTML as an insanely clumsy XML dialect. Consider the following simple HTML:

This is a paragraph with some <b>bold>/b> text!

This translates to some really tortured FDML (I made that up. I have no idea what they are calling the language):

<Paragraph>This is a paragraph with some <Bold>bold</Bold> text!

As if that’s not bad enough, try to load some FDML into one of the poorly documented viewer widgets and your head may just asplode. Near as I can tell, this is the most direct way to coerce a string into a FlowDocument…

new XmlTextReader(
new StringReader("Some proprietary XML garbage dialect goes here"))) 
as FlowDocument;

I really hope I’m wrong, because if I’m not, this is a verydisappointing API design on multiple levels:

  1. It builds upon the really idiotic XmlReader API, which, despite the existence of a dedicated Uri class at the time it was created, insists on treating string constructor parameters as Uri’s, making the act of reading XML stored in a string unnecessarily complicated.
  2. I have to wrap my document string inside a StringReader because XmlTextReader is stupid (see above).
  3. XamlReader’s static Load method returns an object for some reason, despite availability of generics when it was created, necessitating the blind as cast at the end.
  4. Aside from being simply non-intuitive, the apparent API removes any chances the compiler may have had to help you realize you’ve got a logical error. I suppose I can forgive the reliance on XmlTextReader — it’s hard to give up an API even when you realize it’s bad — but there’s just no excuse in my mind of the XamlReader’s Load method being untyped. All I can figure is that Microsoft has hired interns to do this stuff.

codepaLOUsa day 2

Day two was definitely the more rewarding of the two CodepaLOUsa days. Continuing yesterday’s theme of sharing teh knowing:

0. The Sports and Social Club apparently adds a mandatory gratuity to checks for parties of two (sorry, Dave!). Considering how poor the service was that we got at lunch, I think I can understand why they do this.

1. Actor-based programming is ActiveX EXE’s comeback plan.

2. I can’t say I’m surprised to discover that it’s much easier than I thought to do RESTful Web Services with WCF.

2a. I think I am now a fan of James Bender (stupid needless javascript redirect and all), and I will be buying his book.

3. When you are a primary sponsor for a conference, I guess it’s OK to give an hour-long sales presentation under the guise of a technical presentation. Still pisses me off when it happens though.

4. LINQ for JSON exists!! Rejoice!

5. Here’s a tip for conference presenters — no one wants to watch you write the sample code for your presentation as part of your presentation. Set your examples up beforehand, please.

6. The award for most surprisingly good presentation goes to Marc Cull from CafePress, a company that is doing some very cool stuff with Greasemonkey.

7. Phillip Japikse should not be allowed to throw t-shirts in rooms with chandeliers. He is, however, allowed to give design pattern talks whenever the hell he wants, and I’ll listen.

8. I wasn’t really counting, but I’m pretty sure I saw 6 presentations given from Macbooks over the course of the conference. The remaining 5 were run from Windows 7 laptops. Where’s the Linux love, Louisville?

I left with some blog-worthy thoughts knocked loose in my head, hopefully I’ll get around to writing about them soon. I seem to have problems finishing anything longer than a couple paragraphs… SIGH.

Today codepaLOUsa, tomorrow… codepaLOUsa

Spent all day at codepaLOUsa and picked up the following bits of teh knowing:

0. When antifreeze gets in your oil, it looks a lot like a chocolate milkshake.

1. Never freelance without a contract, and never waste your clients’ time.

2. Functional programming is mostly about getting rid of all those pesky while loops. Not that there’s anything wrong with that.

3. JBuilder and Delphi are, shockingly, both still alive and well.

4. Clojure may be the most difficult to understand yet genuinely useful language I’ve ever been exposed to. The usefulness criteria excludes the likes of brainfuck and whitespace.

5. If you aren’t doing dependency injection, you are by definition not really unit testing.

A worthwhile day, and I will be returning tomorrow for more knowings.

Dear Microsoft: Your experience sucks

I’m going to spend the afternoon at a client site today, and I need the client tools for SQL Server 2008. Just the client tools, and just for today. To do this, I apparently have these options: purchase a full license for SQL Server 2008, or download a SQL Server 2008 180-day trial.

To purchase a full license would require an “estimated” $7000 for a single CPU license. That would amortize out to an “estimated” $1400 per hour for my needs this afternoon. A little pricey. There are apparently cheaper editions available, but I’m not able to sift through the torturously organized “Microsoft Store” web site to determine whether or not these cheaper editions actually come with client tools — not all versions do — the express version apparently does not.

Finding an evaluation seems easy enough, google for “Sql server 2008,” click “Download Trial,” click to download from MSDN, select a language (don’t you know that from my browser caps?) and click the button… nothing happens. Great, a broken button. Backtrack… there’s a “Technet trial software” link that works, but takes me to a page with no visible download link. There’s a big green “Continue” button, but that appears to download instructions instead, and there’s no inter-page navigation option for “download the file” on the page either. Only after scrolling around, and reading carefully do I finally find download links, well below the page break. And then I have to solve a captcha. Lovely.

It’s been 45 minutes, and I’m now, finally, able to start downloading a 1.3 gigabyte file. Excellent work, Microsoft, you almost completely discouraged me… and what the hell is with the file size, anyway?

Now compare this experience with, oh, downloading a MySQL installer for Windows: a quick “I’m Feeling Lucky” google and I’m right there, downloading 121 megabytes.

Now, I’m by no means holding up MySQL and Oracle as bastions of clarity or usability. I actually think the MySQL site is pretty obnoxiously designed on it’s own, but compared to finding anything on a Microsoft branded site, MySQL is golden. Consider also that an illegitimate copy is also only a single “lucky” away and it’s even worse.

To sum up: Microsoft, your experience sucks. How a company that can create such incredibly awesome developer tools, and craft a user experience like XBOX Live can so thoroughly screw up something so simple as downloading software from it’s website is impossible for me to understand. Fix it.

Blogging is hard — have some more code

So, this blogging stuff is hard. Well, to be more precise, finding the time having the discipline during my free time to sit down and write something every day is hard. I like to think of it less as laziness and more as me not responding when there’s no immediate challenge, but I’m admittedly biased.

Anyway, while my commentary on buying e-books from Barnes and Noble’s Nook store languishes away as a half-written draft, I’ll throw another helpful code snippet up here (even though it’s an old one that I’m sure many of you have already figured out) just so I can check “write something for teh blog” off my to-do list. What? That’s how it’s spelled on the to-do list. I’m just being faithful here.

.NET Nullables rock

The .NET Nullable struct is pretty cool, finally solving the long-standing “impedence mismatch” between three-value logic and how things work where most of us sane people live. Nullable let us distinguish between “no value” and “the default value” when we needed to without resorting to insane workarounds, unenforceable conventions or blatant hacks to do so.

The trouble is, there are times when the cure is worse than the disease. Use nullable types for any length of time at all and you’ll find yourself writing code like this everywhere:

Nullable b = GetSomeDatabaseValue();
bool theValue = false;
   theValue = b.Value;

Because, if you blindly go calling Value, Nullable will throw a nice exception into your lap. The clever developer will quickly decide to “tern that mother out” and wind up with something at least a little more copy-paste friendly:

Nullable b = GetSomeDatabaseValue();
DoSomethingWith((b.HasValue ? b.Value : false));

This is better, but it still counts as repeating yourself since you’re going to have to repeat that ternary logic everywhere. This approach also has further disadvantages that ternary expressions are hard for some people to grasp, and it’s just a difficult coding standard to enforce.

You do want a standard though, that your whole team follows. I’ve personally seen code bases where the team apparently left the standard up to the individual developer, and this was one developer’s chosen method:

Nullable b = GetSomeDatabaseValue();

The simple truth is, sometimes we just don’t care to distinguish between default value and null, and want to be able to safely compress that triple-value logic down into the simple boolean logic we’re all used to dealing with. Extension methods to the rescue:

/// <summary>
/// Retrieves the value of any nullable type, returning the default if it is null
/// (for numeric types this is zero).
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="nullable"></param>
/// <returns></returns>
/// <example>
/// int? foo = null;
/// Console.WriteLine(foo.SafeValue()); // writes 0
/// foo = 42
/// Console.WriteLine(foo.SafeValue()); // writes 42
/// </example>
public static T SafeValue<T>(this Nullable<T> nullable )
where T : struct
   if (nullable.HasValue)
      return nullable.Value;
      return default(T);

The SafeValue implementation above is probably a little naive, but it should be good for 90% of the cases where you’ll want to use it. It lets you turn the “use its value if it has one, otherwise use the default” logic into a one-liner:

Nullable b = GetSomeDatabaseValue();

Bear Grylls goes to McDonalds

Years back, before motel gate, I began to lose interest in Bear Grylls’ Discovery channel show Man Versus Wild because I felt the show was degenerating into shock-mongering by prominently featuring Bear eating some new disgusting thing each week.

In that light, I wholeheartedly approve of this bit of image macro:

Bear Grylls goes to McDonalds

The irony here is that, while I can recall all manner of disgusting culinary choices he made on the show, I don’t believe Bear ever actually drank his own urine on camera… I believe that was actually Les Stroud whose slightly more real “one man lost in the wilderness show” Survivorman I actually quite enjoyed, until (as happens with all the TV shows I enjoy) it was cancelled.