My take on the Mono/C# debate

•1 July, 2009 • 48 Comments

As you might have understood if you’re reading me, if you’re easily offendable on this matter, you’d better skip this post.

So, i figured out I should shout out something. Because I am always interested in hearing skilled, readable, balanced and well-made opinions from people such as Richard or Adrian, but I’m fucking tired of hearing random people screaming out why mono is cool or not. These kind of people don’t even know what coding is about, or they just learned Java or C# at university and they’re like “oh shit, I can code!!”. STOP THAT.

This is a technical, and ethical problem that regards DEVELOPERS. Users will end up having choice. All you pro/anti-mono fanboys, what is difficult in installing or removing mono, being it provided by default or not? No matter what your position is.

After this small rant, hoping to have made some things clearer, let’s move forward.

I’d like to skip the ethics/politics part for a variety of reasons. First of all, I’m all for things that work, if they’re free, much better. That’s why I’m using closed nVidia drivers, because they work better. Secondly, everyone has freedom of choice. And this also means freedom on choosing where to be free. And I hope some false freedom advocates will revise their concept of freedoms. One should be free of being not free as well. And more than that, this is not my field, so I’ll just leave the word to someone knowledgeable (following what I said before)

That said.

I am still asking myself why on earth people should need Mono, .NET, C# or similar stuff. I am starting to think that while more and more people are starting to code, the overall coding skills are getting lower and lower. Maybe it’s just me being too strict in using almost always C/C++, but I remain extremely confident in the fact that if you don’t know how/don’t want to manage memory, you should be doing something else. I’m not saying that using python, ruby or similar stuff is bad: I do it as well, and enjoy doing it. I think being capable of using JUST python, ruby or similar stuff is bad. Also for broadening your mind and knowledge. Just my opinion anyway.

Before you start yelling at me: yes I used C#, and some friends such as Java (similarity is almost ridicolous). I wrote about that as well. There were some things I liked, but a majority of things I disliked.

Now, comparing what Java/C# has to offer (just to demonstrate that I’m not blindly bashing C# only, that I also like better than Java) with Qt, there should be a single question.

Why on earth someone should choose C# over Qt/C++?

I don’t know, really. Maybe introspection, it’s much better. Maybe serialization, it really works out. Maybe something else. But when i talk about something that should be the backbone of your program, such as event loops, threading, events, and whatever, Qt/C++ puts C#+Forms/WPF/etc to shame. Please come up with some technical reasons why C# is better. And don’t start with compilation: I don’t think it’s so relevant for a deployment.

I don’t want to spend more time talking about this: you can verify what I’m telling you is true by looking at the percentage of KDE code written in languages different from C++. And we have some great bindings.

So, what’s the conclusion? Why people can still code fast, efficiently and easily with an “old” language like C++? Probably because the toolkit/framework integrates extremely well and extends the language to fit everyone’s need. That’s what Qt does.

So this is the point, on which you are free to flame me until death: the problem is GTK. Consider the amount of programs recently written in GTK. A huge percentage of them is in Python or Mono. Let’s be clear: I don’t have anything against bindings. But try stopping your flaming ego and follow me a bit more.

We have PyQt and Qyoto. Yet they are not so widespread and planetkde is filled with new C++/Qt apps. So where is the problem? Probably people are no longer comfortable in programming with GTK/C. I did it a while ago, and it was quite a pain to me actually, and it made me want to look into python, damn my laziness. I think that this is the kind of route a lot of people take nowadays.

Now you’re expecting a sort of GTK/GNOME flaming here, right? Well, bad for you. This was not meant to be a flame, just an introspection to understand the reason why mono existed (see the introduction). And my take is that mono is just a way to “modernize” something that is NOT obsolete (and I repeat: NOT obsolete), but simply no longer fitting the 2009 attitude of “oh shit I need to create a program in 3 lines of code!!!”. To demonstrate that I’m actually not attacking GNOME and/or GTK, I’ll give you Microsoft.

If you think about it, the iter that Microsoft followed for getting more developers is not that different from the one GTK took. So, what’s the conclusion?

Mono is not the panacea. Mono is a great way of developing easily, without spending that much time. But some skilled GNOME developers already showed the world (*cough*GNote*cough*) how Mono is NOT saving time to someone who is skilled and knows how to do things the right way. To me, GNote is not a symbol of freedom, but a symbol of the fact that people can still use GTK with success with C or C++ (and by this point I hope you realized that this is not a war against GTK, more some constructive criticysm).

So, Mono is nice to have, but not required to have, and not necessary to have. And I don’t see (today) a reason why a developer should choose C#/.NET/Mono over Qt or some other great frameworks out there. And I still think it is a nicer bridge FROM Linux TO Windows, and not the other way round. You should be blind if you can’t see it, or you’ve been simply hiding in your house without looking for a job those days. People need to make money, dude.

Last line, I bored you enough: my solution to the debate is not boycotting, insulting or anything: is having easier, crossplatform toolkits, and more skilled developers.

And now come on, the flaming box is just some pixels away from you!

Some help on a possible new instrument

•23 June, 2009 • 7 Comments

Dear lazyweb,

As you know, it’s not in my style filling PlanetKDE with non-KDE related stuff, but this time I really need some help from the community, as I know that there are some good musicians around you.

I’m about to buy a synthesizer, since we’re adding some electronical influences in our band (we’re mostly playing rock music). So, here it comes. I need something on a decent budget, with good action on the keys (I’m quite choosey as a pianist), and decent piano, strings, and lead sounds (square and sawtooth are the sounds that intrigue me the most at the moment, but I’m opening to a new world in which I’m quite ignorant).

I would use it with piano sounds, and with synth sounds, mostly to harmonize guitar parts (such as solos). I would let you taste a sample of our latest work but it’s still in the studio. Anyway, this synth should be suitable especially for live performances and optionally for composing.

At the moment, my choice for budget and everything is the roland Juno-G. It fits my budget and it looks like it will fit my needs as well.

Here’s the question: any advice on this being a good/not bad/worst ever choice? Any other synths you would recommend me?

Oslo, day two

•6 June, 2009 • 1 Comment

Well, it’s day 3, but yesterday I had no time to blog or whatever, so I’m just writing with a day of delay.

So yesterday I woke up at a decent time to check out from Anker and getting to Munch. After having left my luggage over there, waiting for Will to arrive, I took a tour of the Oslo fjord, which is really nice, especially the park around it. I had a nice and relaxing walk, and then I catched up with Will and headed up for Nokia offices.

Once there we met all Qt software guys, that were basically waiting for us after having read my previous blogpost. I suppose that is the web 2.0 deal everyone’s talking about. Anyway.

We had lunch with Knut, Thiago and Alexis and talked about some stuff, while waiting for Frederik and the students to catch up with us. We actually discussed some plans about the networkmanager applet and we now have a defined direction, that we will probably make real today. That was worth quite some hours of work, and we left the office around midnight to get some fun in the town.

So me, Frederik (who is basically sitting next to me writing probably the same stuff on his blog, and that feels kinda weird), Will and Olivier took the chance and went into the Garage having a beer. After Will left us, since he was really tired after his flight, the three of us went to Rock Inn to get another beer and some nice music.

Waking up today felt kinda hard, and me and Frederik are basically waiting for the other guys to arrive. Well, it’s always like people going to bed later are the ones waking up earlier. And hopefully, you should see some code today as well.

Oslo, day one

•4 June, 2009 • 4 Comments

So I finally arrived in Oslo for the NM applet meeting. Today I’m alone, since the meeting starts tomorrow, but I came here one day before to cut the travel costs (yes, hard to believe, but it’s true) and I decided to write a small something everyday, since it’s a whole new experience for me.

I left from Bergamo at 10.45. 2 hours and a half later and 20°C less after, I finally arrived in Torp, greeted by the awesome view of the Danish and Norwegian coasts, one of the most amazing things I’ve ever seen. It still took an hour and a half to get to Oslo, and some more time to reach Anker, where I’m staying just for this night (I’ll join the rest of the KDE people in Munch tomorrow). The room is really nice, especially for the price paid.

Oslo is kinda expensive, but I fit myself finding some pizza slices at 20kr (2 for 30). Not the best deal ever, but quite cheap for the standards indeed, I hope tonight I’ll be eating somewhere decent.

The city is nice. Well, it rained almost all the time, but I took the time to walk on the Opera theatre, have a quick look at the fortress, and walk through the main streets of the city.

A fun fact is that I needed an adaptor for my PC. Without knowing which kind of ac plugs they had in Norway, I brought an english one from home, and came here to find out that they have german-like ones. So I went to a shop (on advice of the people at the hostel) to buy another adaptor, and they told me they the only ones they had were for english plugs. As you can imagine, my setup now consist of my laptop plugged into my adaptor, which is plugged into the adaptor I just bought. Lucky chance indeed.

Tonight I’ll look around for some pubs & clubs, hoping to have a great night in Oslo. And if you’re hanging around there, be sure to catch us in the next days to join the fun!

Getting a hold on small things

•2 June, 2009 • Leave a Comment

I’m sitting on my bed sipping one of the great beers I took home from bruxelles, eating some great Provolone (an Italian cheese) and salami, while I’m listening to Queen, Beatles and Rush, chatting with some friends and doing some code in the very spare moments.

Shit, this is happiness.

I feel so comfortably well that I really have to realize (once again) how small things change your life; how small things _are_ your life. There are a lot of small things, like this one, like seeing a smile, reading a pink post-it, play your music until your fingers and throat hurt, that make you feel happy, well, without knowing a reason. It’s like being in love. Most of the times it’s a person. Some times you’re simply in love with your life. And sometimes you happen to be in love with a person that made you love your life again.

This post is simple, small and short too, to keep things consistent :) (and hoping it will be beautiful as well to read)

The future of PowerDevil (and of power management)

•3 May, 2009 • 31 Comments

Long time no see, again a post on PowerDevil.

PowerDevil has proven to be quite a solid software, and I’m both proud and happy about it: the 4.2->4.3 transition has happened almost with no maintainance (apart from a critical bugfix from Jacopo, thanks!). The proportion of bugs affecting it regard 20% up/downstream problems, 25% “please implement the feature x” and 15% “oh, the GUI sucks and looks confusing” (yeah, percentages are not accurate, I can tell)

The problem is that PowerDevil GUI does suck, big time, because it’s way too cluttered. However, I can’t add cool and nice features without cluttering it even more. Result, there has to be something wrong. The topic came back today by chance in a short conversation with Martin, and while I was eating, suddenly (and by chance, I was not even thinking about it) I got struck by an idea.

Let’s start knowing that Power Management is something that is very much linked to the hardware, and the average user should have a minor part in configuring/dealing with it.

Today, power management systems are based on profiles, more or less configurable. They offer the user access to a set of things to configure, and that’s it. There are some problems, though.

  • The options are limited. Some features will still be missing
  • The options can’t be expanded: code gets fat, GUI gets unusable
  • Everyone loses on the long run: developers have a dirty code base, users have limited possibilities and/or an unusable GUI, distribution don’t have much flexibility in providing custom and effective settings, hardware vendors even less.

To me, this means one thing: the current profile concept fails. That’s why I thought about an alternative: putting an additional layer of abstraction: let’s call it “Actions”.

Actions are containers of, well, actions such as setting CPU scaling, brightness, and anything you can configure with PowerDevil right now. They come in form of plugins (KPlugin ftw!), so that you can create custom Actions (mind the capital letter) by defining your very own set of actions. But let’s make an example, to make things clearer.

You create a new Action, name it “Set Powersaving mode”. In it, you define (using the available plugins), that the scaling should be ondemand, the brightness 10%, the power scheme “powersaving”. That’s it. In the profile chooser, you now have a similar situation: a single page that has some per-event based fields: for example, “When PC is idle for more than 15 minutes, do”. Now what do you do? Just set an Action, in this case “Set Powersaving Mode”.

Everyone wins. Still can’t see why? I’ll tell you:

  • Average users: they have to do almost no configuration, and they have it in a very readable form (as Actions can have human readable names, such as “Set Powersaving mode”), and with the best combination in the Actions, that were defined by KDE team, or by the Distro (better), or by the hardware manifacturer (even better)
  • Power user: you finally can do the f**k you want with no limits, and I think that’s enough. And the GUI would be damn clean.
  • Distributions: you have a way to define your very own actions based on your specific configuration, in a truly easy way, providing your users the best defaults possible
  • Hardware vendors, and netbook vendors, I’m mainly looking at you: suppose your new motherboard has a “WOWSAVEALOTOFPOWER” feature, that can be used only on your motherboard by calling some weird functions. Pretty fine. Go ahead, and write 100 line of code to add a new plugin to PowerDevil’s Action system, to let Powerdevil handle it. Netbook vendors shipping KDE can also include it in their default Actions, to give their users the very best.

Looks cool? Obviously, we still miss one step, the configuration of events. I mean, leaving “When the pc is idle for … minutes” gets you limited and hardcoded. So simple, let’s apply the same concept to events too. A profile configuration GUI would look like this (squallid, more conceptual than anything else mockup):

That's the concept. Slick, huh?That’s the concept. Slick, huh?

Well, even if it’s a fast and quick mockup, I think you will agree with me that it already looks much more polished than the current one :D And as you can see, adding a new event is very, very easy and human-readable. I also have a mockup for the Action editor:

Even more slick!Even more slick!

That’s it, the Events one would be analogue to the action one. As you can see, both GUIs need some love, but have a very simple and powerful concept behind. What’s more, is that this way we are getting even closer to Power Management integration in the system: all application would be able to define their own events/actions, allowing, for example, to stop your music when you enter deep powersaving mode, or anything you can think of.

Now, I’ve been eloquent enough, and now I would like to grab opinion and ideas. Do you like it? Would you like to see it in 4.4? Do you think it’s a major improvement and/or sucks? Let’s gather some ideas so that I know where to work on :)

Quick notice for fellows at Politecnico di Milano

•1 May, 2009 • 3 Comments

Hello people,

if any of you happen to study at Politecnico di Milano, use Wicd, and being frustrated by opening 6 shells to open up a f*****g connection, I might have something for you:

http://github.com/drf/policonnect/tree/master

It’s a Qt+Polkit-qt generator of templates for Wicd to connect from Wicd to the “internet” network just by entering a password, as if you were using a standard WPA connection. Try it out, if you like, and report any issues to me.

Beware: italian language only, even though I’d appreciate if somebody at least wrapped up all the strings and provided an english translation. Patches more than welcome.

UPDATE: For people using Arch, you can also grab the pkgbuild.

Laters,

Strange things happen

•16 April, 2009 • Leave a Comment

It was not a great day today. Sky was cloudy, I was pretty tired, really not that into talking/seeing/wanting to do something, I studied a bit (very small bit), sat at my PC doing anything, had a phone call that really didn’t want to show my apathy (but hey, I’m not a great actor in those matters), and such. The kind of days you say “Let me go to bed now and let’s see what happens tomorrow”.

Then something happened. I was sitting at my pc, listening to last.fm. And then somehow the feeling of listening to Bohemian Rhapsody struck me in my back, so I turned it on. Years passed since I’ve listened to that song for the last time.

It was magic. Pure magic. Just a whisper in the beginning, like you are about to be brought in another world. Then the piano kicks in, and a voice grows out of the choir.

Anyway the wind blows, doesn’t really matter to me

Then it strucks you with that progression: 4 adjacent semitones in a row, appearing slightly out of tune, that makes me shiver every time. And with a such epic progression, hearing “I don’t want to die” really calls you to bursting out in tears of joy. And then, one of the most amazing solos I’ve ever heard.

What can you do? You can just sit at the piano, take the guitar, sing to the top of your lungs. And the day gets suddenly brighter. You suddenly have a smile on your face. You would like to take back the phone, clear the previous call, and doing another one, much quicker, but saying the things that really matter, that no matter how much times are being said, are always able to make me happy.

Then you look outside and you see that the sky is clear and the sun is shining.
Is there anyone, up there?

If anyone (me included) needed a confirmation that if God exists, he hides behind a bunch of notes, I think you have another one

Adventures in C# and Windowsland, part 2b – Threading/Event loops

•15 April, 2009 • 2 Comments

I thought that my previous post needed a follow-up, after the whole discussion and what happened.

Before stepping on, I would like to thank everyone who commented and gave me some precious advices. I really appreciate it. Now, to the point.

I discovered (thanks to previous comments) the existance of BackgroundWorker, that I still didn’t understand if it’s part of Windows.Forms or not (belongs to System.ComponentModel namespace but somehow makes me feel it’s part of the Forms stuff). So I ditched my ExtendableThread and switched to it.

I liked the fact that you can report progress just by calling an event that reports a percentage. Pretty nice, especially for some basic usages, where it really saves you the hassle of reimplementing such small things on your own. Thumbs up to that. Solved the threading stuff, it was now time to make the threads talk one another. And here came the point where I needed to start messing with my own events.

Events have some points stronger than Qt’s Sig/Slots, and some points weaker. Let’s get through them.

Declaration: As any Qt developer might notice, declaring an event or a signal/slot connection takes exactly the same amount of code. To roll down my own event, it came up to this:


public delegate void ExchangeCompletedHandler(object source, Message reply);
[...]
public event ExchangeCompletedHandler ExchangeCompleted;
[...]
ExchangeCompleted(this, reply);

vs


Q_SIGNALS:
void ExchangeCompletedHandler(Message reply);
[...]
emit ExchangeCompleted(reply);

Ok, you actually see it takes one line less in Qt. Anyway, declaring a delegate is both a nice and a odd feature. The plus is that safety of connections is determined at compile time, and there’s no way in the world that a connection might fail at runtime (with Qt it can). On the other side, I like to do this sometimes:


connect(blah, SIGNAL(test(int,QString,QWhatever)), this, SLOT(plainTest()));

Not having a compile-time check lets you create dynamic connections that doesn’t force you to have the same parameters as the signal, but one of them, none, etc. In C# that would require declaring a delegate for each form of your “slot”. But in the end, I think the approach that C# takes can give some more assurance to the inexperienced programmer, so I guess they’re even.

Calling the “slot”: One other thing you might have noticed by comparing the 2 declarations is that the Qt one lacks a parameter. Or better not, you can retrieve the sender just by calling sender() inside the slot. Qt’s metaobject rocks definitely, and that’s something I miss in C#. This also made me wonder if I could fake the streamer when streaming an event in C#, since I have to declare this explicitely. I didn’t try, but I hope there is actually some way of checking this, otherwise it might lead to some unexpected results to the poor programmer.

So far so good, I think I’m quite satisfied with C# events. But then again failure struck me. I came to write that bunch of code:

IAsyncResult res = client.BeginConnect(serverBox.Text, Convert.ToInt16(portBox.Text),
new AsyncCallback(register_ConnectCallback), null);
}

private void register_ConnectCallback(IAsyncResult rs)
{
client.EndConnect(rs);
// Let's generate the XML request
RegistrationRequest req = RegistrationRequest.createRegistrationRequest(usernameBox.Text, passwordBox.Password);

So far so good, but my program wouldn’t work without telling me anything. After some weird try to see what was wrong, I tried debugging it, and I got stuck with an Exception that was not notified during the application run (very, very bad): “Can’t access Text since the object resides in another Thread”.

1 point more for throwing exceptions at this. It is actually nice that being non thread safe is considered an error at runtime, from my point of view. 1 less for not notifying me and not quitting the application and simply destroy the thread. 1 less since why on earth should I be in a different thread. Ok, nevermind that for now, and let’s try this hack:

Dictionary data = new Dictionary();
data.Add("username", usernameBox.Text);
data.Add("password", passwordBox.Password);

IAsyncResult res = client.BeginConnect(serverBox.Text, Convert.ToInt16(portBox.Text),
new AsyncCallback(register_ConnectCallback), data);
}

private void register_ConnectCallback(IAsyncResult rs)
{
client.EndConnect(rs);
// Let's generate the XML request
Dictionary data = (Dictionary)rs.AsyncState;
RegistrationRequest req = RegistrationRequest.createRegistrationRequest(data["username"], data["password"]);

Works, but it has a really bad shape. BeginConnect explicitely gives you the opportunity to pass some data in form of a generic object to retrieve it in the result. So this made me wonder if it was actually AsyncCall fault and it wouldn’t happen with events. I refactored the code to make the same function being an handler of an event that was streamed in the very same thread (I called Connect instead of BeginConnect and then streamed the event). Guess what? Same result.

This boils down to my very first concern about events: they’re belonging in a different thread, so thread safety goes to hell (it was definitely not the Timer, as you can see). The problem is, that hack does not suffice. I need to do this:


Storyboard cstory = (Storyboard)Resources["FeedbackAnimation"];
cstory.Begin();

To notify the user of the progress, and I obviously can’t. I’m stuck finding a way that will make me be able to do this without passing the Resources object to the thread (that, honestly, I don’t even think will work), also because I can’t overload my delegates with some parameters to pass the event custom data. I think there’s got to be a way, otherwise C# has somehow a big problem. The very first scope of using async methods in GUI applications is to have the gui responsive and give feedback to your user. What if the design of events prevents you from doing that?

For reference, Qt’s signals and slots are thread safe, and slots are delivered to each thread’s event loop, so that you are sure that your connection happens safely. You can even post events to the event loop of each thread in a completely thread safe way, if that’s not enough. I am fairly much missing that in C#, and I hope I can find a solution for this.

Spoiler on next post: Handling of data (XML and DataSource)

UPDATE: Found out about this.Dispatcher.Invoke(new Action(delegate() { cstory.Begin(); })); . Not very elegant and depends on WPF, but works. I’ll search for a better solution

Quick updates

•13 April, 2009 • 17 Comments

Howdy,

quick updates:

  • Moved Solid-Wicd to KDEBase, post coming soon
  • Released polkit-qt 0.9.2, here. Pick it up as soon as you can, K3B is already depending on it, and you want to have a taste of how KCMs can behave greatly with polkit
  • Laters.