Archive for the ‘Rant’ Category.

Spam…

Sad indeed

Initial C# impressions

(This was originally meant as a comment for Janus’s post about C#, but it turned out to be longer than that…)

Mikkel and I have to learn C# for understanding the code from SCET, a project running before our project. Anyway, we’ve been looking at a tutorial, the one over at http://csharp-station.com/ (just a random one).

And so far my impression of C# is that it is like C++ with garbage collection (so it’s a bit like Java) and with new keywords such as ref, out, etc for parameter passing. The ref is nice and clearer than pointers or C++ references so that’s good.

But the out keyword? I think it’s ugly. First it’s not necessary, just pass a ref parameter and have the method update it. A better solution would be to let methods return multiple values in a — ohh — tuple! That cannot be so hard, especially because it could be implemented as syntactic sugar for the out parameters. Several languages (Python, ML and Haskell comes to mind) have such a construct and it is very useful.

Also, who uses goto these days? I think that is a bit too low-level. But maybe it reflects that C# is mostly C++ with a standard garbage-collector?

The choice of having methods being non-virtual as default is also unfortunate. For you simply cannot predict if a given method will need to be specialized in the future. It hurts extendability if you have to go change the base class when you want to specialize a function in an derived class — the source for the base class might not even be available in which case you are stuck. The efficiency concern of virtual methods is not valid, IMHO. First, the compiler should be able to look at the class tree and note that method foo() isn’t redefined and thus make code that jumps to foo() just as efficiently as if it had been declared non-virtual. Second, the extra pointer indirection incurred for virtual functions shouldn’t be a problem with our modern fast CPUs and with normal programs that spend 99.9% of their time waiting for user input anyway.

In the book Object-Oriented Software Construction it is described how it is always right to call the redefined method B::foo() and often wrong to call A::foo() if class B extends A and if you want to take advantage of polymorphism. The problem is with invariants: since foo() is redefined in B it presumeably adds some functionality to A::foo(), it might update some internal state in the object to maintain a class invariant in B. Class A does not have the same class invariant as B and so calling A::foo() destoys it whereas calling B::foo() would have been the right thing to do. The method B::foo() is always safe to call since it must fulfill both the invariants of class A but also of B. Even though class invariants is something you mostly see in Eiffel code, the principle applies to all languages.

I also don’t get why delegates was invented — aren’t we just talking about a function pointer? It seems that I can declare a delegator for comparing numbers like this

public delegate int Comparer(object obj1, object obj2);

after which I can say

Comparer cmp = new Comparer(CompareFirstNames);

when the CompareFirstNames() method has a signature matching with the delegate just declared. One can then of course pass cmp to a sort() method as usual. But why could I not just pass CompareFirstNames to sort() directly? Why do I need to make a new delegate type (if it is a type, I’m not really sure…)? The notion of agents in Eiffel seem much more elegant and powerful. I would be happily surpriced if someone tells me that you can pass a semi-instantiated function as a delegator in C#. Agents in Eiffel work much like lambda functions in functional languages, giving you the possibility to easily adapt functions for use as callbacks. (Agents are described and compared with .NET delegates here, see also the OOSC course homepage.)

That was a lot of initial comments about what I’ve seen from C#. Don’t take this as meaning that it’s all bad — the idea of properties is a good one, for example. A garbage collector is also something which I’ve come to expect from a modern language, so that too is a welcome change from C/C++.

Fight the boycott — buy Danish

Janus reported on a strange thing that is happening right now: Danish dairy products are being boycotted by several Arab countries because Jyllands-Posten, a major Danish newspaper, printed twelve pictures of the prophet Muhammad.

As Stéphanie argues on his page, freedom of speech is not meant to be used to insult other people. The pictures can, for example, be found here and I can fully understand that they are insulting for a believing muslim since they depict Muhammad as a terrorist and oppressor of women.

But still, buycutting products from random Danish companies is not going to help — it is only going to get innocent people fired, the first 100 employees in Arla has already been laid off. If you must, then attack JP, write letters to your local newspapers and so, but don’t blame the Danish government or Danish companies for something they didn’t do.

Now also with camels?

I logged into [DAIMI][] today using the usual DNS alias fresh-horse.daimi.au.dk. This alias is points to the most “fresh” machine out of a number of machines named horse01 … and counting upwards.

Now the sys admins have apparently grown tired of the horses and have switched to camels, for I was logged into camel04 :-) I love this idea of such an alias!

At the [ETH][] things are much more chaotic — the two times I’ve had to log into the network from home I had to search for a long time to find the name of a suitable host! I couldn’t find it on any of the official ETH pages — in the end I found a working hostname somewhere in an exercise sheet for some course in distributed systems.

WordPress insecurity

WordPress logo Another computer related thing needing attention when I got home was [WordPress][]… version 1.5.2 has just been released to fix yet another security hole, although their announcement has no specifics (as usual).

They write “We’re happy to announce that a new version of WordPress is now available for download.” How can they be happy that a security hole has been found in their “extremely stable 1.5 series” once again?! They have released version 1.5.1 (May 9th, renamed to version 1.5.1.1), 1.5.1.2 (May 27th), 1.5.1.3 (June 29th), and now 1.5.2 (August 14th) in response to security holes being found.

I think that’s a bit too much for me to call this think “extremely stable” (I obviously believe that security is an important feature of a “stable” application.) It’s good that they react to the security holes and they try to fix them fast, but I don’t like the way they just write that they have “addressed all the security issues that have been circulating the past few days”. Some questions immediately spring to mind:

  • How many security holes were there?

  • What was the nature of the hole(s)?

    • Could they “just” change the database? If so, which parts of it?

    • Could they upload files to my server? If so, could they overwrite my previous files?

  • How can I see in my log files if I’ve been exploited?

Instead of being vague I would like to see specific information about the problems. Browsing through the changesets doesn’t really help either, for the WordPress developers seems to make a point out of obscuring their fixes.

Take this changeset (revision 2779) for example, which committed on the 1.5 branch two days before the announcement of version 1.5.2 with the innocent message of “Move above”. Some lines are really moved up a little further in wp-settings.php — they deal with undoing the work of the infamous register_globals setting in PHP. But the lines are not just moved, an extra check is added to ensure that the variable $table_prefix isn’t unset. Why? Is this one of the security problems they’re talking about? Given the extreme lack of comments we can only guess…

Or maybe the fix was smugled in with revision 2780, together with fixes for seven small bugs and feature requests? The change to wp-admin/users.php in that changeset involve replacing

$id = $_GET['id'];

into

$id = (int) $_GET['id'];

and to my eyes this could be the fix they’re talking about. Especially since $id is used in an SQL query next… So if this analysis is correct then WordPress 1.5.2 was sent out to guard against an SQL injection attack. If anybody else has information about this then I would of course be interested!