.NET considered harmful

A friend of mine just told me about what an MS evangelist said at a symposium on multicore (paraphrased), after getting the question:

“Did MS consider that cache awareness for programmers in multicore development?”

…and he answered:

“The average developer is not capable of handling that kind of level of detail. … Most developers are that ignorant. Welcome to the real world.”

To me, this explains a lot. It explains why .NET looks like it does, and to clarify what I mean by that, let me simply copy in extracts from what I had to say about it in a private forum just weeks ago. In what follows, the italics are brief extracts of comments from others. The rest is my own text. It’s not always in a totally logical order and it starts out in midflight, but it’s a synthesis of a longish thread on a security related forum.

Continue reading “.NET considered harmful”

The real iPhone conspiracy

So I’ve used a Mac for a while and I’m just starting on iPhone development and a blinding flash of the almost-obvious strikes me. This is not the Blackberry killer or the Palm killer, it’s the long-fuse Microsoft killer.

Remember the monkey dance? Ballmer yelling “Developers, developers, developers!”, while jumping around like a neurally defective and sweating profusely (one could be excused for suspecting some cholinergic poison, but he lived through it, so that is not the answer). Right. I mean, he’s right. Developers is what makes or breaks a platform, but now he’s losing them, so he really has no reason to celebrate.

When Apple designed the iPhone, they could have created a special development system and language for it, but even though it may have been easier, they didn’t. They chose to tweak the development environment for OSX to include the iPhone, and by necessity, also putting OSX on the iPhone. The result of this is that if you want to develop for the iPhone, you have to get a Mac (strike 1), learn OSX (strike 2), learn Objective-C (strike 3), learn Cocoa (strike 4), and by then you’re so deeply immersed in the Mac environment that you won’t find your way out again. Since you can run your Windows stuff, including Visual Studio, just fine under Parallels or Fusion, you don’t need that Dell or HP machine for anything anymore, and you’re not sorry to see them go. In other words, you’ve got a developer that clearly isn’t going to like going back to .NET development again. I mean, once you’ve used these two environments (Xcode/Cocoa/Objective-C vs .NET/Visual Studio) it’s practically impossible to enjoy .NET anymore. It’s so far behind and so very clunky in comparison it’s almost a joke.

So, every developer you task with iPhone development is almost certainly lost from the .NET camp forever. This I can’t prove, but I’m convinced of it. But now is the question: who are these developers? Do they already develop for the Mac or are they from the “other” side? Again, by the seat of my pants, I’m convinced that a very large and increasing proportion come from large enterprise .NET development organisations that need to add a client for their large systems on the iPhone. See where this is going?

It’s only just begun.

Update: I suddenly realized that I fused two unrelated events together in my mind. Steve Ballmer did the monkey dance and yelled “Developers, developers…!” at two different, equally traumatizing, occasions. I’m not sure that’s any better, though. It’s all very disturbing.

MS patch of… Firefox?

To quote an article on annoyances.org about the new ClickOnce install support that MS has added to .NET:

The Microsoft .NET Framework 3.5 Service Pack 1 update, pushed through the Windows Update service to all recent editions of Windows in February 2009, installs the Microsoft .NET Framework Assistant firefox extension without asking your permission.
This update adds to Firefox one of the most dangerous vulnerabilities present in all versions of Internet Explorer: the ability for websites to easily and quietly install software on your PC. Since this design flaw is one of the reasons you may’ve originally choosen to abandon IE in favor of a safer browser like Firefox, you may wish to remove this extension with all due haste.

Unfortunately, Microsoft in their infinite wisdom has taken steps to make the removal of this extension particularly difficult – open the Add-ons window in Firefox, and you’ll notice the Uninstall button next to their extension is grayed out! Their reasoning, according to Microsoft blogger Brad Abrams, is that the extension needed “support at the machine level in order to enable the feature for all users on the machine,” which, of course, is precisely the reason this add-on is bad news for all Firefox users.

And then follows a convoluted procedure to hack the crap out of the registry. Go there, read it, do it, if you run Windows, this service pack, and Firefox.

Tech Republic put it like this:

In a surprise move this year, Microsoft has decided to quietly install what amounts to a massive security vulnerability in Firefox without informing the user. Find out what Microsoft has to say about it, and how you can undo the damage.

Read the entire Tech Republic article.

PS: this isn’t exactly news (the annoyances.org article is dated February 27, 2009), but I only just noticed through a posting by Rob S on a private list.

A feature?

Had to use the Directory.GetFiles() method in .NET, so I read the description. Now, take a moment and read the following about how an asterisk wildcard character works in the search pattern parameter. Then tell me if this description is of a feature or of a bug. Windows, largely due to legacy, is full of this crap.

When using the asterisk wildcard character in a searchPattern, such as “*.txt”, the matching behavior when the extension is exactly three characters long is different than when the extension is more or less than three characters long. A searchPattern with a file extension of exactly three characters returns files having an extension of three or more characters, where the first three characters match the file extension specified in the searchPattern. A searchPattern with a file extension of one, two, or more than three characters returns only files having extensions of exactly that length that match the file extension specified in the searchPattern. When using the question mark wildcard character, this method returns only files that match the specified file extension. For example, given two files, “file1.txt” and “file1.txtother”, in a directory, a search pattern of “file?.txt” returns just the first file, while a search pattern of “file*.txt” returns both files.

and:

Because this method checks against file names with both the 8.3 file name format and the long file name format, a search pattern similar to “*1*.txt” may return unexpected file names. For example, using a search pattern of “*1*.txt” returns “longfilename.txt” because the equivalent 8.3 file format is “LONGFI~1.TXT”.

The conclusion must be that this function is worse than useless and bound to cause excruciating bugs in your apps. Better use the GetFiles() method without any search pattern and then filter using a regex.

The end of .NET? I can’t wait.

Ok, I admit, that title is a bit over the edge, but still that is how I feel. Developing for .NET is increasingly becoming not fun and far too expensive. The only reason to do it is because customers expect products for .NET, but under slowly increasing pressure from developers, that is going to change. It may take a while, but it will happen. There are a number of reasons for this.

.NET development is single platform. Admittedly the largest platform, but a platform that is increasingly having to share the market with other platforms. And already, according to some, there’s more sales potential for small developers in the OSX market than in the Windows market, due to a number of factors like customers that are more willing to buy and to pay for software, less competition in each market segment, etc.

.NET development is also entirely dependent on Microsoft’s development tools and those are increasingly expensive. For reasonable development, you need an IDE, a good compiler, version control, bug handler, coverage analysis, profiling, and a few more. We used to have most of that in the regular Visual Studio, but recently MS has removed all the goodies and plugged them into the Team system only, which carries an obscene pricetag (in Sweden around USD 13,000 + VAT for the first year…). This means that a regular one-man development shop can barely afford the crippled Visual Studio Professional at USD 1,500 for the first year. Sadly, there aren’t even any decent and affordable third party products to complement the VS Pro so it becomes a “real” development suite. And with every version of Visual Studio this only gets worse. More and more features are added to the Team suite and removed from the Pro. This is not the way to breed a happy following.

Meanwhile, OSX comes with XCode, which is almost as good as Visual Studio Pro, and is free. Objective-C is also a much more modern language with more depth than any .NET language, even though it is actually older. But, sadly, it’s not cross platform either and I don’t see how you can get the Windows fanboys of the Scandiavian healthcare scene to even consider another platform. Same probably goes for most other industries.

I’m no fan of Java, but on the other hand I’ve never worked much with it so that opinion doesn’t count. Eclipse, the IDE often used for Java development, is cross platform, very capable, and open for other languages such as Python, Flex, and many more. Yes, I know, in theory so is Visual Studio, but how many real languages do you have there? You’ve got one: Basic, masquerading as C#, J#, and, um, Basic.

Using Eclipse on any platform, you’ve got a real good chance of covering the line of tools you need, profilers, coverage, version control, without much pain and without breaking the bank. And you can write crossplatform integrated larger systems.

So, I guess it’s time to bite the bullet. I really like XCode and OSX, I really know C# and .NET, but I really only believe in Java, Flex, Python, Perl, C++ under Eclipse for enterprise development in vertical markets. And in XCode under OSX for regular shrinkwrapped desktop apps.

Not even Silverlight is very attractive and that is largely due to the marketing and pricing of the tools for it. A small developer organisation can’t afford it. Flex and AIR looks like serious contenders, though.

x2c source

I finally got around to putting up the source code for x2c under GPL. No, you haven’t heard of this thing and it may not seem immediately useful, but when it is useful, it’s incredibly useful. The hardest thing is coming up with full samples of what it can do, so I’ll just outline it right here.

x2c stands for “XML to Code”, and it’s an interpreter for a little language I made with built-in commands to handle XML documents and write to plain text output files.

It started life as a tool to create VB and C# source code for data access layer classes, based on XML descriptions of an Oracle database. Another possibility is generating language tables from Excel spreadsheets, and I’ll tell you how:

Imagine an Excel spreadsheet with one sentence per row. In each column, the same sentence is written in another language, like Swedish, English, French, etc. Save the spreadsheet as an XML document. Now you can write a pretty short x2c script that reads these languages, column by column, and then produces a C++ header file with the right strings declared as constants. Great for products you want to recompile for a number of human languages.

Especially for this last use, I recently adapted the text output file command in x2c to allow output to ASCII, unicode (default), or any codepage you have installed on the Windows system you’re running this thing on. In the above script example, you see codepage 1251 used for Russian. In this case this was necessary since the C++ compiler used (Borland) couldn’t use unicode header files. This script runs under US or Swedish XP and Vista, as long as codepage 1251 is also installed on the system, and then produces the right MBCS file for Borland C++, resulting in binaries that will look real to russians running russian versions of Windows. Note that above is the complete script that is needed to convert the excel spreadsheet to four different C++ header files and it can easily be run from a build script.

The source is C++ in a VS 2008 solution. Have a go at it.

Strongly typed constant parameters in C#

After a bit of searching, I found a way to have strongly typed constant parameters for C# functions. You know the situation, where you need to pass one of a limited set of strings or chars or other values to a function and you want to make sure somebody doesn’t just go and pass any old thing they find laying around the place. Enums are pretty good for this kind of thing, but it gets hairy if you need to translate it to anything else, like a string or a char.

Any solution also needs to pander to intellisense, making it easy to use and kinda idiot safe (I’m talking about myself a couple of hours after defining any constant, which usually leads to me behaving like the idiot user I had a hard time envisioning just hours earlier).

I think I found a good system for doing this, and as an example, I’ll invent a function that takes a string parameter, but it has to be just the right kind of string. To do that, I first declare the constant strings in a separate module this way:

Then I write my function, the fictional “Rechandler” that takes a parameter of the ConstRecTypeValue kind. And then I write a function that calls it. Now, while writing the caller, I want intellisense to do its thing, and it does:

As you can see, it obediently pops up a tooltip to tell me only a ConstRecTypeValue is accepted here. As soon as I start to type that, it recognizes the ConstRecType static class name and it intellisensively lets me choose which constant member I want:

…which I complete the usual way:

The callee (Rechandler) then easily recovers the string that is hiding inside the passed value (in this case “DELETED”) and continues its merry ways.

Naturally, you can use chars, doubles or entire collections of values instead of the string value in this example and still achieve the same effect.

You can also take it one step further along the path to universality, by using a generic base class for the value type:

If you have this guy in reach in your project somewhere, you can now simplify the definition of the value class like so:

…while everything else stays just the same.

I love it.

Reflect on those constants

This falls in the category “neat tricks” and definitely under “DRY” (Don’t Repeat Yourself). When you have a list of constants that you need to save or retrieve, typically settings, you easily get into a situation where you have say 20 constant strings defining the names of your constants, and then a block of code going through the same 20 variables to retrieve or save them. When you add a constant, you’ve got at least three places to add code and then I’m not even counting the places where you actually use the settings value.

But using reflection in C#, you can easily make it so the system retrieves all your constants and their values into a dictionary at runtime and saves them back, using nothing but the declaration of the string constants.

This is an example of a declaration of the names of the values we want to save and restore:

And this is code that then gets the values of those constants and sticks them into a dictionary in runtime. The rest of the code is trivial and not worth reproducing here