Archive for category C++/C#/SQL/Web Programming

Service Broker Update

I’m finally finishing up the Service Broker RPC implementation at work.  I’m not 100% done, but I can see the light at the end of the tunnel finally.  As usual, setting up the initial implementation isn’t that bad — it’s linking it into every other aspect of the system where you start to see problems.

The devil is truly in the details.  Now I’m exhausted from two straight weeks of fighting this fire, and I’m sure I’ll be right back at it Monday, trying to finish the last hanging details.

Wish me luck!

Tags: ,

More Service Broker

After a two-day period of intense hacking, I’ve got the basic architecture of a replacement for our messaging engine working in Service Broker.  It’s fast, lock contention isn’t an issue, and I’m very hopeful that we can not only use Service Broker to replace our messaging engine, but also to reduce our dependence on external apps that poll the database for changes.

Service Broker is not particularly difficult to understand, but getting the syntax right can be tricky.  I ran into several minor stumbling blocks, which I was luckily able to get over quickly:

  1. I did not specify the “no encryption” option on the conversations I opened, so initially messages weren’t being sent due to the fact that I didn’t have a master key set up for the database in question.
  2. My first cut at implementation used the “fire and forget” pattern, where the initiator terminates the conversation immediately after sending.  This is a problem because if the far side needs to return error information to the initiator, it can’t, since the initiator has already jumped ship.  The fix for this is to let the target terminate the conversation and to put a little activated stored procedure on the initiator side to handle any error responses.

After getting past these issues, it was smooth sailing.  I expect to be able to implement the routing logic today, after which it will just be a matter of cleaning it up for inclusion in our software.  We could potentially be running with it in about a week, at least in its 1.0 version, particularly if I go with straight text for the RPC messages rather than have to mess around with XML serialization.  If I were using C# it would be a no-brainer to use XML, but the options available under C++/MFC are less than stellar.

Tags: ,

SQL Server Service Broker

Sorry for the late update; I’ve been feverishly working on a new project at work, using SQL Server Service Broker to replace our older interprocess messaging and database notification system.

Service Broker is a very cool piece of technology, and since it leverages the ubiquity of the database (everyone that needs notifications has connections to our server) we can end up eliminating a huge amount of code by implementing it.  We’re also likely to gain speed, as it will eliminate the single-point-of-contention queue table and the manual polling logic that we were using before.

I’m almost ready to roll with my second proof-of-concept exercise — this one demonstrating a stripped down version of my proposed architecture.  If I can get it to work the way I suspect I can, we’ll be ready to forge full speed ahead to implementation, and eliminate a code structure that ’s been a thorn in my side for almost 10 years!

Tags: , ,

Upgrayedd

He spells it with two D's, for a double dose of his pimping...

Over the last couple of days I’ve been upgrading my computer system at home.  The impetus is twofold:

  1. I got a version of Windows 7 as a prize in the 2009 Interactive Fiction Competition, and finally decided to use it to do a full reinstall on our primary email machine.  It’s an old Dell XPS, and we’ve had it for 5 or 6 years.  It’ll run Windows 7, and it’s gotten so encrusted with remnants of old software over the years that it isn’t particularly reliable any more, so I backed up all our photos, videos, music, and email, made a list of the apps we absolutely need to reinstall, and took the plunge.
  2. Thomas has been relentlessly hounding me for his own website.  It’s a huge hassle to administer my webserver, though, because I have to reconnect mouse and keyboard and monitor cables.  When I finally got around to it, I discovered the webserver was over 6 months behind on recommended updates, so I spent a good amount of time bringing it up to date.  I also added Mozy remote backup to it, since it handles all my web content and my Perforce source code control depot.  I recommend Mozy very highly; I’ve used it for years and it’s cheap, fast, and reliable.

For good measure, I’m putting Windows Live Mesh on all three of my machines.  This is a very nice, featureful, fire-and-forget RAS package for Windows and Mac computers, published by Microsoft.  It allows easy file sharing and remote access for XP, Vista, and Windows 7 machines.  I found it extremely easy to set up and get started with.

After I got the mesh set up, I was able to quickly install two new websites — one for Thomas, and one for Robin.  Right now they’re just skeletons, but we’ll be fleshing them out soon.  Thomas wants to host Flash video games on his site, which should be an interesting experience, and Robin has long wanted her own blog.  Now she has one!

The Windows 7 upgrade on our main machine is in progress as I type this; I’ll follow up soon and let you know how it worked.

Tags: , ,

Video Hosting Rethought

After seeing the performance of my self-hosted video solution, I rethought the wisdom of trying to host myself.  First of all, performance from anywhere but home was pretty poor; the stream preload could keep up with the video playback, but only if everything went exactly right.  Once a hiccup occurred, it hung up and took an inordinate amount of time to recover.

Also, my upload bandwidth at home is limited.  If several people tried to view a video at the same time (I know I flatter myself, but it could happen), performance would really go down the tubes.

So I decided to host through Vimeo.  They’re free, support the features I’d like, have a nice player interface, and aren’t obnoxious like YouTube.

With luck, offsite-hosted video should be much more performant for viewers.  To test, the Vimeo-hosted Bionicle video is displayed below.  I personally think the quality is better, not to mention the performance.

Enjoy!

Bionicle from Matt Wigdahl on Vimeo.

Tags: , ,

Video-Enabled!

I’ve now figured out how to embed home video in the blog in a nice, streaming player.  The Wordpress “Stream Video Player” plugin is the core technology; once this is in place it’s a simple matter to extract the video from the digital video camera, format it up with Windows Movie Maker (or equivalent software), convert it to a .flv file (Flash-format video), and inject streaming metadata into it.  Then you just upload and embed it into the post!

The result is a very nice embedded video player that supports random access to the video and doesn’t give you the issues that come with using YouTube.  The video is hosted locally and I can freely remove it or change it if I need to.

So here’s the first video I made — Thomas demonstrating his expertly-constructed Bionicle vehicle, complete with functioning weapon.  The age range on the box is from 9 to 16 years old; he built the whole thing himself (with just a bit of guidance from me) at age 8.  Note the complexity and the sheer number of parts, including a functioning gear train!  Also included is bonus footage of Jonathan fussing.

Edit:  I’ve removed the self-hosted movie.  See the next entry for the Vimeo-hosted version.

Huge Spam Wave

spam[1]After the weekend’s festivities, we returned home on Sunday.  On Monday, after having settled in a bit and gotten the kids off to school, I sat down to post the pictures in yesterday’s entry.

We’ve gotten a lot of spam in the past, but it was ridiculous yesterday.  85 new messages had come in since I posted Friday.  Most were the usual “Anubis Gates” pharmaceutical shill, but there was another type of gibberish spew that had apparently walked through my blog, targeting a pretty decent subset of all the posts I have.

With Akismet, of course, it’s the work of a moment to delete them all, but this was by far the biggest wave I’ve been hit by.  Akismet has registered something less than 600 spams total, making the weekend’s attack 15% of all the spam I’ve ever gotten on this blog.

Tags: ,

The Saga of the New Keyboard

keyboards-709573[1]I program.  A lot.  I type in a lot of code at work and at home as well, and I’ve had numerous flirtations with carpal tunnel syndrome in the past.  What finally cured the problem for me — and it was a dramatic cure — was moving to the Microsoft Natural Keyboard around 13 years ago.

Programmers get attached to their keyboards, and it’s no wonder; we type tens, possibly hundreds of millions of keystrokes on the things.  Switching keyboards is a big, big deal — nothing to approach lightly.  As an example of how particular we can get, note that the keyboards pictured to the right are recognizable instantly as examples of the Microsoft Natural Keyboard Elite model, which are inferior to the original models in key feel, function key size, and the layout of the insert/delete and cursor arrow key blocks.

Don’t mess with our keyboards.

The original Microsoft Natural Keyboard is, in my opinion, the pinnacle of keyboard design.  Nothing before or since matches its ergonomics, key feel, or spare layout and design.  I bought one for work and one for home way back in the day, and have used them for well over a decade now — they’ve outlasted at least 3 computers with never a problem.  I’m typing this post on one right now.  I have an Elite as a spare, but I try not to have to use it.

There’s only one problem; the original Microsoft Natural Keyboard is a PS/2-only device.  That’s not been a fatal problem even in the age of USB, as there are PS/2-to-USB converters.  However, either the converter or the new Dell I got recently (or both) are not fully compatible with the keyboard, as I get dropped keys when typing at speed, and it can’t handle interleaving multiple simultaneous keypresses very well, which affects ALT- or CTRL-key combinations and games.

So it was time to look for a new keyboard.

Of course, the first place I went was to Microsoft’s offerings.  After over a decade of complete satisfaction, I knew they understood what a programmer needs in a keyboard.  I also knew they had a suite of new keyboards, all of which natively supported USB.  After reading some reviews I went with the Microsoft Natural Keyboard 4000, which seemed to be the intended successor to the original Microsoft Natural Keyboards.  I ordered it from Newegg, got it, and plugged it in.

With one exception, it’s really quite a good keyboard overall.  The key feel is OK, the layout is good (read:  familiar) — everything about it was acceptable, except for the spacebar.

The spacebar.  How could they screw up the spacebar?  When you type on an ergonomic keyboard, especially  a split one like the Natural series, the spacebar has to be wide to bridge the gap between the two sides of the keyboard.  For comfortable hand positioning, you have to have your thumbs on the very ends of the spacebar — it’s required by the very concept of a split keyboard.  So why would Microsoft make a keyboard with a single contact for the spacebar, and a cheap swaybar to try to balance the forces?  It presses OK in the exact center, but when you press on the ends, it sticks.  Badly.  On either side.

It’s a dealbreaker.  It may be news to Microsoft, but the spacebar is a commonly used key.  I’ve used it several hundred times in this blog post already, which is more than I can say for the ‘x’ or ‘q’.  So back the Natural 4000 went to Newegg, and I looked for another answer.

What I came up with in the end was a used Microsoft Natural Keyboard Pro.  This model supports USB natively, has the same key layout as the original Natural, a good spacebar, and a bunch of extraneous buttons at the top that I just ignore.  Key action is OK; not as good as the Natural, but acceptable.  The function keys are the small Elite size, but I can live with that; I don’t use the function keys nearly as much as the spacebar.  And since older Natural keyboards are almost indestructible, it still works great.

I wish I’d found this one originally, as it was cheaper than the 4000 and I wouldn’t have lost the $18 on return postage and restocking fee when returning the 4000 to Newegg.  But even so I consider it a cheap lesson to learn.  The important thing is that I have an acceptable keyboard to use now; one that works well enough that it seems to blend into the background, and becomes something I can just ignore while I work.

Tags: , , ,

Best SQL Server 2005/2008 Index Maintenance Script Ever

ccrp_0908_04_z+electric_q_jet_carburetor+rebuild[1]It covers reorganization when it makes sense, rebuilding when it has to, has a debug mode, intelligently determines whether online rebuilds are possible or not, is well documented, and generally seems like a very professional SQL script, other than a single typo bug due to the conversion from HTML.

Use it.

Tags: ,

C# vs. C++ — Swimming With the Current

1696193472_34d83c57f3[1]I know I just posted on the glories of smart pointers in C++.  I love C++ like a brother, and I have many C++ friends, but this article does a great job of illustrating, with wit and great examples, one of the most important truths about programming that I think I can pass on, and it’s not flattering to C++:

If you can manage it, try to swim with the current.

The link above is really a series of articles comparing the development of a simple application to read a Chinese dictionary in both unmanaged C++ and C#.  You should read it — it’s very interesting and educational — but the upshot is that although the C++ author eventually got his fully optimized performance to exceed that of the fully-optimized C# program, it took a large amount of very touchy, bug-prone work to do so, while the naïve version of the C# program already had great performance out of the box, and was easily optimizable to speed up further.

Why is this?  You can blame Microsoft’s substandard support for C++, and that’s probably partially right.  You can blame the glacial pace of improvement in C++ Standard Library design and performance, and that’s probably partially right as well.

But why are both of these situations the case?

The fundamental reason is that, for most non-systems programming tasks, the state-of-the art — the current — for development on Microsoft platforms is strongly flowing toward C# and .NET.  .NET is getting the benefits of new technologies and new advances in the craft of software development, and C++ really isn’t.  You can still paddle around in the C++ backwater, but very little in the way of support and improvements is going to be coming your way.  TR1 is very nice (and very overdue) but at this point it’s almost too little, too late.  Those of us who have to stay in the backwater are just going to have to get used to the faintly stagnant smell.

For most development, the current heading toward C# and .NET is almost certainly a good thing.  Personal computers are not the same as they were when C++ was first rising to dominance in the early 90s.  Multicore machines are the norm now, with multiple orders of magnitude more memory and disk storage than ever before.  Modern CPU pipeline optimizations are so complicated that trying to hand-optimize assembly code for a modern processor is almost laughable; a compiler will always do a better job than you can now, and that certainly wasn’t the case 15, even 10 years ago.

When you have memory to spare, a terabyte of hard disk space, most of the work you are doing is manipulating top-level UI constructs, your minimum-spec machine has an 8-core processor, and preventing obscure malicious exploits is a priority, does it make sense to use a language designed around minimalist efficiency, where threading is a foreign operation bolted on with great difficulty, memory is managed manually out of the box, security is an afterthought and you end up with a static executable optimized for the lowest common denominator of machine?  Or might it be better to use a language with built-in garbage collection, easily-used multithreaded constructs and just-in-time optimization based on the environment the app is running in?

C++ is a great language for many purposes, but the current has passed it by for user-level application programming.  Swim with the stream if you can!

Tags: , ,

The Quern is Digg proof thanks to caching by WP Super Cache