C#/.Net – first tastes

I have just done a little bit of serious C# coding and thought I’d share some reactions.

Overall impression is pretty favourable. If you are only interested in developing for Windows desktops, it will be pretty hard to beat. For GUI construction, it’s all very VB like, without the VB funkiness.

The Visual Studio IDE is really nice. I’ve used Visual Studio in a past life (C++) and I found this version to be more forgiving. In the past, some things were very hard to undo. My PC did crash horribly twice while running it. This wasn’t a blue screen, just a whole load of vertical stripes, which was pretty jarring. I’m not sure if this is related or some hardware glitch developing. Have to wait and see on that.

C# is pretty easy for crusty Java programmers like myself to pickup. It’s full of syntactic sugar, as Matt would say. Let’s hope it doesn’t rot my programming teeth, so to speak. The libraries are unsuprisingly similar to the Java libraries. I was surprised, however, by the omission of a Set collection. Using a hashtable also had some oddities as it complained when I added the same key twice. Huh? You’ve got to use the [] operator thing for that. Why not a Put method? No doubt a lot to do with my java mindset, but these little things made me feel that it somewhat immature. Alternatively, perhaps collections libraries are just degrading over time – we used to have MultiMaps in C++, after all.

The case conventions for methods, fields and properties don’t seem as consistent as Java. Might just be a case of getting used to that. It’s amazing low strongly those Java conventions have become ingrained, so much so that methods starting in upper case appear odd.

Anyway, I’ll keep playing with C# …

Jakarta’s Mediocrity

I’ve started reading Mike Cannon-Brookes’ blog recently. I can’t read it with Mozilla – it’s a guaranteed segfault – but it is worth reading nonetheless. He blogs recently about Jakarta’s mediocrity based on this blog entry. Jakarta may well be mediocre, at least in parts, but there really isn’t some marketing machine pushing this down your throat. Mike’s right when he says

Think. Yes, Think. For yourself.

I’d even add “Rethink, regularly”. If something in Jakarta floats your boat, use it. If not, well, find something better. Don’t be a lemming.

I did find it ironic, however, that the BileBlog is served by Apache Tomcat/4.1.24. Is that a production system?

Core Developers

Well, there certainly is a flap in the Open Source Java world today. I don’t know what is the story behind it all but it will be interesting to watch what happens here.

The article above and a few others I have read today seemed to play up the Apache-Jakarta link. "They have an Apache Jakarta board member, which could make things very interesting". Well there is no such thing as the Apache Jakarta board and the Apache Software Foundation board is certainly not involved in this, that I am aware. I predict nothing “interesting” from this angle.

I’d guess that companies that have adopted jBoss might be a little concerned right now. Let’s hope this development doesn’t kill the goose laying the golden eggs. Might be time to look at the other app servers out there …

Piston

It’s time for my first code feed. After a bit of googling, I’ve decided to call my little email fetcher "piston". I skipped the whole "j" namespace as it’s worn a little thin for me – sorry Matt. The idea behind the name is that the app is like a piston, drawing email from the POP port, and pushing it to the SMTP port. I hope it doesn’t explode too many in between.

You can download it and try it out or just check out the source. The licence is the same as the current Apache licence with the names changed to protect the innocent.

It’s a little rough at the moment – not much in the way of configuration options, logging to the console, etc. It does the job for me and I will probably clean it a little later. To run the piston, you must create a directory ".piston" in your home directory and create a config file "config.xml" Here’s mine

<config loop="120">
  <smtp/>
  <pop username="user"
       password="password"
       host="pop1"
       smtpname="conor"
       max="100"
       nullMessageId="delete"
       duplicateMessageId="delete"/>
  <pop username="user"
       password="password"
       host="pop2"
       smtpname="conor"
       max="100"
       nullMessageId="delete"
       duplicateMessageId="delete"/>
</config>   

When I used to use Outlook, occasionally it would redownload a whole load of old mail sitting on the server. I think this occurs when there is a server problem and the UID values are rebuilt. When it happens it is a real pain. I set out to avoid that happening by tracking the messageIds of the messages currently on the server and not downloading these if I had already seen them. I discovered that a lot of viruses and spam does not have messageIds so I have an option to delete such messages. I have only seen one "legitimate" email that does not have a messageId (a super-12 footy tipping email). The nice thing is that virus payloads are often quite large and this approach allows me to delete them without downloading them. The tracking of messageIds also allows me to eliminate duplicates arising from cross-posting.

So if you send me an email without a messageId, I won’t read it – sorry.

DISCLAIMER This code is capable of deleting emails from your POP account. You need to satisfy yourself that it is working as you expect.

C++ Retro

For the last few months at work I have been working on PocketPC development in C++. It’s funny to go back to a language I once knew so well and get back into its groove. It has helped to heighten my appreciation of Java, while also showing me some things I like about C++ that Java does not have.

Firstly, the separation of the interface and implementation of C++ classes (into .h and .cpp files) probably sounds like good practice but it’s just a pain. To have to deal with your class split over two files especially if some of the code is inlined in the header is tedious. Java’s all-in-one approach is much easier for me.

Having to know who owns allocated memory is blah. If I receive a buffer from a caller, am I expected to free it or will the caller? Are we in sync? Double frees and memory leaks are often difficult to track down. I resurrected my reference-counting templates to remove some of this headache. I also have to interact with a VB UI in this project and I’d not done a lot of that before so I’m still worried about all those BSTRs.

Templates are cool, when they work. Of course, getting templates to instantiate is always something of a black art. Either they are not instantiated at all or you get multiple symbols. I usually end up inlining most things in my template classes.

I love operator overloading. I never abuse it – really. I like to be able to have dynamic structures look like arrays.

Resource Acquisition is Initialization (RAII). This technique is great for things like associating critical sections with code blocks and not having to remember to cover all exit paths, etc. Sort of like a Java synchronized block. In C++ you are always thinking about allocation and management of everything you do. In Java, you don’t worry about this mostly. That ease of use can, however, lull you into to not properly managing non-memory resources such as JDBC connections.

The Microsoft IDE for embedded development makes some of these things easier but it has some annoying failings. Many times my classes just disappear from the class view. I don’t know what triggers this. When this happens lots of the automated wizardy things stop working. Adding a method to an interface under these conditions will not get a stub implementation added to the class providing the interface.

The most grevious problem, however, is that sometimes the IDE grinds to a halt whenever a line is added or removed in the current buffer. I used the SysInternals tools to try and understand what is going on. During these editor pauses the IDE is checking whether a disk is still mounted thousands of times. I’m guessing this is something in my environment but it has affected different machines (laptops, desktops, etc). I have had to resort to an external editor.

The PocketPC emulator sometimes actually starts up. When it’s runnign it seems to pop-up at the most inconvenient times.

I see from Simon Fell’s Blog that there may be an IDE update. I’ll have to check it out.

Anyway it’s good to look again at how different languages do things. It’s relaxing to come back to Java but perhaps the refreshed awareness of all those allocations will make me more careful about object creation in Java.