December 14, 2007

Threading is Hard

Here's to another obvious title. Even in .Net, where they have done a lot to simplify things (thank-you background worker), however threading always seems to cause the biggest headaches even when just coding things. Usually if you ignore the issues with threading there are random crashes in testing, but as you design the code you sit there and try to think about what you want to do. First, there are very few references on threading in .Net. Secondly, all the tutorials that there are involve simple things like launching a bunch of threads that sleep, and output their thread id to the console. Or they are examples of how to update the UI from a background thread. Not to pick on these, but there never seems to be any examples of how to interact with real objects in your application in a thread. What requires a lock, and what doesn't? How do I make my own classes threadsafe without locking entire classes of functions. And then how do I ensure I don't end up with deadlock in my applications (this tends to be one of those things that only show up when the application is under the kind of load it never is either in testing or in development). One of the few really good resources on threading in C# was this article, which lead me to buy the book C# 3.0 In A Nutshell and I was very glad I did.

But enough whinging and complaining about how difficult threading is, that is, as they say, why we get paid the big bucks. Here are my suggestions to make it easier, use Attributes to declare which functions have the potential of being used in multiple threads and then have the compiler throw a warning on the access of potentially non-threadsafe variable usage. This is the kind of thing that compilers are good at, and is the kind of thing that programmers suck at. If Microsoft decides not to include this, why not a company like JetBrains add it to Resharper. Another thing that might be done is exposing in intellisense whether or not an object is thread safe. That's it, that's all, until the next time I have to debug some obscure bug due to some unprotected variable that somehow got accessed on multiple threads, at which point I will come back and curse threading again...

November 19, 2007

The Start Menu and why it won't stay organized.

I am a bit OCD about keeping my Desktop and Start Menu organized, bookmarks too (which is now much easier since I discovered Foxmarks six months ago) but that is another story. This is about the Start Menu. Even in the new Vista Start Menu (which I think I am about to switch back to the Windows 2000 Classic menu) Apps that upgrade themselves, STILL insist on installing themselves in the root every time there is an upgrade. I know that some installers let you choose where to put the links (unfortunately very few developers use this feature), but can't Windows remember where you moved an application in the Start Menu? It isn't rocket science, but even in Vista there isn't even hooks written for this -- oh thats right we are all supposed to be using the Search Bar, which works Ok sometimes. Except I hate the fact that I can't have it just index the Start Menu (like Launchy does), I have to turn it on (and have my hard drive seem to be always spinning away and chewing up CPU and resources) or turn it off completely. Another quick bitch about installers, is Apple and its #@$!@ iTunes (which if Winamp had half decent support for podcasts I wouldn't need anymore, cause really the new Winamp 5.5 fixed a ton of things that had been bugging me for years) installer which seems to be bitching at me every week to upgrade iTunes. The problem being, iTunes doesn't create a real shortcut. It creates some daemon child shortcut that doesn't point to the executable and is wrong every time you update iTunes. So the horrible step is upgrade iTunes, delete old shortcuts on the taskbar and the Start Menu, move iTunes into the place on the start menu I want it and then create the taskbar link, YUCK!

Anyhow, I am away until next week, more rants and complaints then...

November 18, 2007

Microsoft Stupid Keyboard

Now I know that my keyboard is almost 5 years old (why buy a new keyboard when you don't need it?), and I like the feel of the keyboard but it has one of the most stupid features I can imagine, the dreaded F Lock. Now, I like most Microsoft hardware, I used their mice for years -- though I must say my new Logitec Mouse is the cats pajamas, but some brainboxes at Microsoft decided that the function keys we all know and love, and use daily, need to be remapped to special keys that bear no relation to say the values displayed in the shortcuts on application menus. Or what the values that video games expect, etc. They added this key, that cannot be programmatically controlled, that in the hardware remaps for example F2 (which I use a lot for Rename in explorer) to Undo. You have no idea the havoc this warps your brain around early in the morning when you have forgotten the feature is enabled because Microsoft felt it was fine to reboot your computer in the middle of the night because it wanted to install the latest and greatest version of Windows Genuine Advantage (don't get me started on that).

Now, they have fixed this in Keyboards released after 2004 (the F Lock key remembers its setting between reboots), so my whining is really more of a lesson in what not to do for user interface. Do what the user expects, not what what you think they may want.

November 17, 2007

Does anyone use Perl anymore?

Always start with a provocative title, thats what I remember someone saying. Anyhow, I was thinking about this a few days ago when I was forced to to figure out something I had written 5+ years ago (the problem of working at the same company for almost 10 years is that you are constantly forced to fix the crap you created years ago -- the joy is when something you wrote years ago actually impresses you). Now I won't say this particular piece of code did anything amazing, but back then the only hooks the application offered was the ability to execute some Perl code. And after spending an hour or so with my fairly well commented (and very non-Perlesque code) I got to thinking about why anyone would want to program in this read-only language.

We, well not me, but the programming world in general, has been waiting for Perl 6 for what seems like a decade. 7+ years is a long time to wait for anything (ask Microsoft about that). And 7+ years in the scripting language space is an eternity (hell there is even a programming language for cats now). Everything that Perl can do, Ruby can do (even the new kid on the block back then, Python is taking a back seat to Ruby, at least in trendiness). And Perl 5 is still stuck with write-only code, a truly bizarre object system (inside out objects, blessing, oh my!), and why oh why can't a variable figure out how you want to access it (%@$, looks like I am swearing in cartoon). Perl's once unassailable strength: CPAN, has been duplicated in PEAR for PHP, RubyGems for Ruby, hubris for Python, and Google and others (krugle, koders, codase) for C# and every other language I use.

When I started in this business, the web was a new frontier where CGI was written in Perl (or even C), and boy did Perl look easy compared to writing CGI or ISAPI scripts (yes, I have written a few ISAPI scripts in my day -- why did Microsoft make everything in Visual C++ an impossible tangle of Wizards and generated code that if you didn't work with it every second of every day, you spent most of your time with a head in manual). This was the days of altavista.digital.com, yahoo.com, excite.com and when the last episode of Sienfield had more advertising revenue than an entire year of advertising on the internet.

Not to be the crotchety old man, but I remembering for my first Co-op job, I researched what was available for creating a web application. The choice was between Internet Application Servers (yup that was what they were called back then) where there was Borlands Intrabuilder, ASP 1.0 (which we could never get connected to the Oracle Database running on VMS), and Cold Fusion. The other choice was client side Java applets, which Oracle was pushing at the time -- the idea here was that standard Oracle forms (oh Oracle forms, how I hated thee) could be compiled into Java bytecode that would be sent to the client web browser and run as an applet. Now this is back when everyone was on dialup, and even within the facility I worked in over ethernet it would take 5 minutes to get these suckers to pop up (if they would), and it only ever worked if you had the version of Java that Oracle packaged with their Java forms, and only one Windows (never got it working on Unix, VMS or a Mac).

So I ended up sticking them with Intrabuilder, which probably would have been fine if this wasn't shortly beforethe point in history that Borland decided to self destruct.

Anyhow, when I arrived fresh on the scene in job world, there was two ways you could work on the web. Dreaded ASP on the Windows side, or Perl on the Unix side. Then I landed at a company that had bet its future on Linux and this crazy little language called PHP/FI. Every now and then I was dragged into Perl (and still am), but oh how I am glad that the company I work for (funny, they haven't updated much on their website in the past 10 years I have been working there) was using PHP and not Perl.

Not that I work all that much in the web space anymore, and not that PHP is without faults...