Monday, May 18, 2009

WPF

I'm having a closer look at Windows Presentation Foundation applications today. Below is some of the code automagically generated for you by the IDE. This code is hidden away in the obj directory, presumably because it's part of the build process.

System.Uri resourceLocater;

Ah, and so now we know the real reason this code is hidden. Dudes, if you're going to generate code, learn to spell first please. Go ahead, I dare you to google the word "locater". Allow me to channel Mr. T as I deafeningly shout:

Did you mean: locator, fools?

So why am I nitpicking, you ask? Well, for one thing that's the entire point of this blog, but here's a a few friendly words of advice: Whenever you see a programmer misspelling variables, fear the code. If they can't spell correctly, or even worse, can't be bothered to spell correctly, then what else might they have gotten wrong? My money says a whole lot, most likely.

Also, it doesn't help anything that the properties window of the designer for WPF insists on using ClearType. Antialiasing is all well and fine for smoothing animated jaggies, but blurred fonts cause nothing but headaches. I already turned that bollocks off, so do me a favor and honor my system settings. And why is there a new properties window for WPF anyway? It positively reeks of summer intern.

Renaming is a built in refactoring tool in Visual Studio these days, but oh boy does it ever break stuff when applied in a WPF project. I guess that's what happens when half the "code" is glorified XML. Stop me if I'm wrong, but wasn't XML designed to be easy to traverse programmatically? How hard can it be to cascade the renaming of a variable? Maybe they haven't gotten around to it yet, or maybe developers at MS are perfectly satisfied with the automatic naming of their controls. I don't bother renaming Label1 any more than the next guy, but Window1 isn't exactly the model of readability.

And another thing, what's the point of declaring window properties and such in XML when it AFAICT just gets compiled into the executable anyway? I'd have thought avoiding a recompile was an attractive goal when splitting the code into declarative statements and binaries, but perhaps the main reason for this "paradigm shift" was luring the HTML-ers into application development. Poor souls.

Seems WPF still has some way to go. In summary, it's apparent that what MS has created here is basically a graphic designer's tool, and so I gleefully observe that any proper coder's job is still completely safe from peril. The vector graphics are cool though.

Wednesday, February 4, 2009

C#

Pascal was the first proper language I learned after BASIC, and my IDE of choice was Turbo Pascal, the creation of Anders Hejlsberg, the same man who has now brought us C#. I still rave nostalgically about the brilliant help system built into TP, but when it comes to C#, I have a slightly different view.

I don't hate C#, but I don't love it either. However, that doesn't mean I have a love-hate relation with the language, those emotions are far too strong. Rather, I consider it to be more of a like-dislike relation. Naturally, I focus on the dislikes. Here's the list:

Everything is classes, just like Java, and just like Java, it annoys me. What's wrong with the odd global helper procedure for those pointless-to-classify tasks? The same basic thing can obviously be accomplished by declaring public statics, but it's that much more bureaucratic framework code, just to please the OO fanatics who blindly believe that all globals are evil. The only thing that kind of design accomplishes is an abundance of classes called Library, Framework or System. Suggesting that I use a singleton instead won't improve my mood, either.

Then there's the mollycoddling. Bounds checking? Garbage collection? No pointers? (That last one is a lie of course, but I'll get into that in a bit.) Apparently it's much too deviously difficult or at least much too time consuming for me, a pitiful dev, but I'm pretty sure I can handle the memory management myself, thanks. In fact, I rather prefer to know what's going on under the hood, if I may.

These days, pointers are one of the devil's temptations. Only the most hardened of veterans may use them, and even then only if they incantate the keyword equivalent of a contamination suit, "unsafe". Much easier for the developer, indeed. But does that mean the language is void of pointers (pun not intended)? Au contraire!

In fact, most variables transcending the complexity of an integer that you might want to declare in C# are pointers, or "reference types", as it were. That is, they are pointers to objects. Have a look at this:

  MyClass c = new MyClass();
  someObject.SomeMethod(c);

That method call looks like it takes pass-by-value parameter to me. It does, in fact. It's a pass-by-value of a pointer to the object c. Of course, that means the object can be altered by the called method:

  void SomeMethod(MyClass x) //pass-by-value?
  {
    x.ChangeObjectsInternalState(); //oops
  }

Can someone explain to me how this is more clear than waving the red flag of pointers in order to signal that what's happening is really a pass-by-reference?

  void SomeMethod(MyClass * x); //unmistakable

Also, boxing doesn't improve on any of this.

Something that really has me gritting my teeth is the lack of support for variable shadowing. Googling the matter has informed me that shadowing "is confusing". Huh? I suppose the concept of polymorphism is also confusing for a beginner, but they didn't take THAT out of C#, now did they? How hard can it be to understand that any given variable exists in a, likewise given, scope? Why not skip templates as well? Oh but wait, C# didn't even implement their templates variety "generics" until version 2.0! What was up with that?

Speaking of stuff that's missing from C#, why won't optional parameters with default values be implemented until version 4.0? What is it they're so busy working on instead? Yeah I know, LINQ. As if anyone enjoys SQL so much that they actually want to be able to use it on arrays and linked lists. Get a grip.

There are other things besides LINQ that I fail to appreciate. WCF, for example. Tell me, why is it that I need another layer on top of Berkeley sockets? Maybe connect() is too difficult a concept to grasp? But then again, I don't really care about WSDL or SOAP or anything remotely connected (pun scornfully intended) to "web services".

In the end, I just prefer executables that don't come with a lot of extra luggage. My PC is perfectly able to run software without an extra layer on top of the already installed extra layer that is Windows. In fact, I'm one of those who longingly recall the days when each piece of software came on its own boot disk/tape/cartridge. Who in their right mind forces their users to download and install a virtual machine just to run their software? Sure, soon .NET will have insinuated its way into every Windows machine out there, but that won't stop me from despising the idea in the first place. Unfortunately, it's painfully obvious that bloat isn't exactly high on MS's priority list of concerns.

Tuesday, February 3, 2009

Vista Explorer

There is a single reason I will never install Vista at home (or anywhere, if I have any say about it), and that reason is the horribly disfigured excuse for a file manager the people at MS have decided to force feed us. While there are certainly many other valid reasons to hate Vista, it's really Explorer that takes the cake.

Let me start by stating that Norton Commander for DOS was brilliant. Explorer for Windows 3, not so much. Windows 95 and upwards improved a little on the basic concept, but it seems that Explorer peaked in XP, because now it's not only declining in usability as well as stability, but actually free falling at high speed past their earlier versions, thus managing to render Vista completely useless.

Everybody knows about this first gripe, but let's cross it off the list to begin with.


What on earth were they thinking, when they decided that Explorer should repeatedly and stubbornly assume that every folder on every hard drive must surely be filled with media files that I will want to tag or rate in some addlebrained manner. Easily fixed, yes? Just change view once and apply it to every folder. But no, of course that doesn't work, because that would be too easy. Not only that, but somehow the columns apply even in tiled views. Explorer is out to hurt us.

Have you noticed how sometimes, it's impossible to delete an entire directory structure? Explorer returns with an Access Denied, and you think to yourself, maybe one of the files in there is locked by an application. So you drill down and delete each child directory and their individual files manually, working your way up. At the end, you find the joke was on you - everything was perfectly possible to delete, and no files were locked. You deleted the whole thing, and you're left wondering why Explorer was somehow unable to.

There should really be a switch in Windows. Two modes, selectable from somewhere in the Control Panel. What I want is a way to turn off The Stupid™. Oh please please let me select Advanced Mode, a mode where there is no ridiculous hand holding such as this next dialog, which some might claim to be an improvement over the one found in XP. Guess what - I beg to differ.


If anything, this has just made it that much more difficult to copy files, because now I have to read all that text every time before I can figure out which option is which. More annoyingly, why is the "All" choice suddenly minimized into that check box at the bottom of such a humongous dialog? Let me just press A and be done with it!

While we're on the topic of file moving, why is it that not only is Explorer still unable to properly calculate the time remaining for the operation to be completed, but now it takes that much longer to think it over, or "prepare" as it were, before even beginning to do any actual work. It boggles the mind.

This next dialog is Explorer related, although it doesn't actually display in Explorer itself.


Talk about a downward step in GUI design. This dialog pops up when disconnecting a USB memory or similar. In XP it was just an informative, non intrusive bubble above the system tray, but now it's a full blown dialog, forcing us to dismiss it with a pointless click on a useless OK button in a dialog presenting information I only slightly care about. Barf.

Lastly, the real reason Vista's so called Explorer drives me up the walls. It doesn't synchronize the tree view and the file view properly. When selecting a folder in the tree view, one would expect the file view to display that folder's contents. This still works acceptably for mousers, unless you're used to clicking the little plus and minus icons next to the folders like I am, but apparently there are no keyboard cowboys at MS, because it's horribly broken for those of us, real devs that is, who tend to avoid the mouse when doing any real work. Try stepping around the tree view using the cursor keys, and nothing - NOTHING - happens. You have to press Enter for the folders to sync. Guess where that leaves Vista? BALEETED!

Oh, and it seems Explorer isn't fixed in Windows 7 either. For some mysterious reason MS has apparently and purposely chosen to drive their customers away. Suppose I'll have to start using Linux in earnest then.

(Screens with permission from Martin Rubli's Tech Blog.)
Powered By Blogger