Separating content and presentation, my ass

Here’s a test:

Find a couple of good-looking websites. Then take a look at their source code. Can you find one that didn’t mix content and presentation in their (X)HTML?

Fuck. I thought CSS was supposed to fix that, but CSS is so lame that people had to tweak their HTML in order to render properly with CSS. How is the current state of affairs an improvement over old-school HTML that mixed content and presentation?

Last time I’ve seen a fuck-up this bad was with the C++ standard. It seems that the C++ and W3 committees have taken the same path: don’t create a reference implementation, don’t create lots of tests with expected result sets, just write an long document and hope that vendors will get it right.

Impromptu testing from Visual Studio

Oana has a good guide for calling any function from your code from the Visual Studio Immediate Window. As I’m not a fan of unit testing frameworks, I find this approach very appealing.

An added bonus is that I don’t have to install anything that mentions the word "integration" on my laptop. I like integration when done right, but have been burned too many times by software that does it wrong.

Solving the BitTorrent Bandwidth Problem

So the ISPs are bitching about BitTorrent and similar P2P applications hogging their pipes. Here’s what they can do to easily fix their problem:

1. Start supporting IPv6.

2. Allow and route source-specific multicast.

Problem solved.

Now when somebody wants to distribute a large file, and they want to devote, say, 10 Mbps to it, all they need to do is start multicasting their content continuously on a number of ports. One port should multicast at 5 Mbps, one at 2.5, one at 1.25, etc., for all possible receiver speeds.

Whenever the content is fully sent on one of these ports, simply start over and send it again and again. Add some redundancy and error checking to each channel, and you’re done.

It’s easy to to mathematically prove that this is the most efficient manner of sending the same content to multiple users. Way more efficient than BitTorrent and other P2P protocols.

Does this make sense for ISPs? They would lose a hefty chunk of money from companies like Microsoft (think of all the bandwidth they use when they post a service pack for Windows), but last mile ISPs would benefit tremendously. And as long as pirated content outweighs legitimate content and flat subscriptions are the norm for home users this would be a net win for them.

Notes:

1. This makes sense only for distribution of large files wanted for many users. YouTube probably couldn’t use it.

2. IPv4 supports source-specific multicast with IGMPv3, but that has its problems. IPv6 solution, now that it’s supported by all major operating systems, is a superior solution.

Remote Procedure Calls suck

Here’s a good post by Steve Vinoski on why RPCs are a bad idea. I couldn’t agree more.

Ten years ago I worked on a project that used DCOM for communication between the client and the server. The amount of pain that caused was tremendous. That led me to make the same conclusion that Steve made: RPCs are fundamentally flawed because they don’t expose failure modes to the programmer directly.

However the industry marched on continued delivering these failed technologies. CORBA is still alive and kicking, and both Java and .NET provide remoting libraries.

The problem has been patched somewhat by adding asynchronous calls to these RPC libraries, but the whole idiotic idea of sending object graphs instead of plain messages over the wire is still alive and kicking.

You can also try to use various RPC technologies as a simple message passing technology by using asynchronous calls as messages with parameters being passed by value, but various little details (versioning, object lifetimes, performance, etc.) will still bite you in the ass so why bother?

Currying

The first time people try to use functional languages like ML or Haskell, they’re like, “dude, where’s my parenthesis”. The syntax irks them because they are used to calling a function f like this:

f (1, 2)

while in those languages it’s simply:

f 1 2

Now thankfully C# programmers are exposed to lambdas more than before, so the jump in understanding doesn’t have to be so big as there are a few stepping stones in between.

Take this simple lambda and assign it to a Func<int, int, int> f1:

(x, y) => x + y

You’d call this function simply by saying:

f1 (1, 2)

But it’s effectively equivalent to the following lambda which we’ll assign to Func<int, Func<int, int>> f2:

x => y => x + y

which you would call by writing:

f2 (1) (2)

Now in functional language all functions you write effectively take the second form. And in this form the parenthesis are superfluous, as nobody wants to write:

f (1) (2) (3) (4)

when they can write:

f 1 2 3 4

.NET Framework Sockets Performance

I was doing tests yesterday in order to measure performance of the sockets in the .NET framework. It kind of looked like Jonah Jameson talking to Peter Parker: Crap, crap, megacrap. I’ll give you three hundred bucks for this one.

In the first test I did synchronous IO. The performance was crap.

In the second test I used overlapped IO using Begin/End socket calls. The performance was crap.

Then I found a new addition to the 2.0 framework: SocketAsyncEventArgs and the SomethingAsyncSomething functions. They were the first ones that provided any half-way decent performance. When did this get added? Any why do all the MSDN samples use the Begin/End functions?

[Update: Looks like this was added in a service pack. Scott Hanselman has a diff of changes between two releases.]

The Zen of SSH

Unix has traditionally better than Windows when it comes to doing stuff on the remote machine. On the GUI side, Unix lets you run just a single app on a remote machine and have its window show up completely integrated with your desktop. On the command-line side, you can SSH to any box and it’s as natural as having a terminal window open on your computer.

The Windows story is much sadder. Remote Desktop is severely crippled unless you are running Windows Server in apps mode, plus you only get the full desktop instead of window integration unless you’re using Windows Server 2008.

Command-line side is equally fucked. Windows console apps don’t use a terminal emulation and there are no hooks using which an application could find out what another app is doing with the console. Thus secure terminal access of a Windows box is only good if you don’t try to use the Backspace key or god forbid Tab for command-line completion. And don’t even think about running an editor on a remote box.

Now the good news: There are two Windows SSH servers that make the whole experience work out OK. They are not perfect but they get the job done.

The free one is FreeSSHd. It has a few rough edges but it’s a usable. The commercial one is VShell, which is better but more expensive.

On the SSH client side the story is the same. The free one is Putty, but SecureCRT is better.

Set PowerShell as your remote shell and accessing a Windows box over the network becomes pleasant again.

Bonus: Once you install a SSH server you get SCP and SFTP. That means that you can use a program like WinSCP to access another computer’s file system remotely without bothering to set up Shared Folders in Windows. You are logging in with an username and a password so whatever directories your user can access you can access too.

Bonus #2: If you ever have to edit a file on a Unix box you can use WinSCP to edit the file locally in your editor of choice instead of suffering through vi.

TV Series Recommendation: The Fixer

I rarely recommend TV series as I assume you watched the popular ones: Battlestar Galactica, Lost, the original CSI, and Desperate Housewives and Grey’s Anatomy for Y chromosome-challenged.

But last week somebody on Releaselog recommended The Fixer and I gave it a try. Definitely a pleasant surprise.

(Side note: The Fixer website uses Silverlight to serve the episodes. This is the first time I’ve seen Silverlight used on a non-MS and non-MS-fanboy property. I may yet get surprised by Microsoft’s ability to battle Flash. Click-Once, for example, was DOA even though it’s an useful piece of technology.)

Emacs for C#

Hot on the heels of Amanjit’s comment to my post about vi and Emacs comes comes this post by Dino Chiesa about making Emacs play nice with C#.

Government-Sponsored Wholesale Torture

How in the world did the Republicans manage to shift the discussion on what they are doing in Guantanamo to a moral discussion on whether torture is right or wrong depending on the circumstances?

There is no right or wrong when you are fighting for survival. If, in some contrived scenario like the one election debate hosts create, some psycho had my daughter locked up somewhere and I had him taped to a chair in my basement, you can bet your ass I’d do whatever it takes to get the information out of him.

But this is not the real issue. The issue is government-sponsored wholesale torture which is a markedly bad idea. There are no moral tangents when torture is done by the government. The guy doing the torture doesn’t have his ass on the line, he’s doing it for fun & profit. “Oops, we screwed up, looks like you’re innocent. Here are your fingers back.”