Category Archives: C#

C# regrets? No.

I mentioned the decision to implement Toves in C# earlier, leaving discussion of C# itself for later.

I came to C# after years of developing in Java, including Logisim but also several other smaller projects. I had grown familiar familiar with Java. Since C# is quite similar to Java, I expected the adjustment to be easy. And while it has been straightforward, it’s been more involved than I expected. The two languages do have some key differences.

Overall, the differences are just that C# has more features – the language has evolved at a more rapid pace than Java has. Some features are nice, others just aren’t very useful. I particularly like properties, language-level event support, and anonymous functions. Also, extension methods are a nice idea that works better than I would have expected.

What I miss most from the language is Java’s package-level protection. Instead, C# has “internal,” which allows access across all namespaces in the assembly, which is more permissive than is useful. I’ve ended up doing some ugly work with “keys,” which some objects generate and which other classes demand in order to perform a method. What I’d really like is “friend” classes such as C++ has, but only members specifically marked as for friends (“shared”?) would be available to them.

My complaints about C# have to do mostly with the infrastructure. First, as I already mentioned, I haven’t yet figured out a way to make it easy to install and execute Toves across multiple platforms. I’m sure there’s an answer, but it’s not there yet.

The libraries are decent, but I miss the JavaDoc API reference. Mono’s documentation is too spotty to be competitive. The MSDN documentation is reasonably complete, but it’s not as easy to navigate as JavaDocs. For GTK#, I find I often have to go to the original GTK+ documentation of the C API and then guess how it might have been translated into the GTK# API.

There’s also the matter of the development environment. I’ve heard that Visual Studio is impressive, but I’m developing on a Macintosh, so I’m using MonoDevelop. It’s a passable development environment, but I miss Eclipse. One persistent though simple missing feature: It’s difficult to view compiler error messages in their entirely. Another is that the IDE seems to pause unreasonably at times, even when code completion is turned off.

Overall, though, I’ve been happy working in C#/Mono, just as doable as Java.

Choosing C#

In starting Toves, one of the first decisions was: What language to use? Of course, Logisim uses Java. This has served it well, particularly in providing a platform where development can happen on any platform and it easily ports to Linux, MacOS, and Windows computers. Being cross-platform is a central feature of Logisim: Many universities assign Logisim projects as homework, and students want to complete the projects on their own computers, whatever they are.

At the same time, a lot of people have wanted to run Logisim on a tablet device (iOS and Android in today’s world). Unfortunately, there’s no strong solution for executing Java under iOS; and while Java works well for Android, its Swing GUI API does not, and unfortunately Swing is more deeply embedded throughout Logisim than it should be. (With Toves, I’ve been careful to add a layer so that the core program doesn’t refer to the GUI.)

Beyond tablet compatibility, Java also has some political problems – to me, these are secondary to tablet considerations, but they still can’t be ignored. One problem is the open-source angle: Oracle doesn’t seem committed to a genuinely open system (witness the Google lawsuit). More practically, Java suffers from a bad reputation on the security front. As far as I can tell, this reputation is unfair. Sure, the browser plug-in for running applets has shown persistent problems, but Logisim isn’t an applet. Though the message people should get is “Java is OK, but disable the Java browser plug-in” (as I certainly recommend, since it’s not too useful anyway), but what they hear is “uninstall Java.” That’s unfortunate, since Java is quite useful for applications like Logisim, and I believe Java has a good security record for such applications. Nonetheless, it’s reality that Java’s reputation suffers.

What about a browser-based implementation using JavaScript? Actually, I looked at this fairly carefully. Performance would take a hit, but the no-installation benefits were too great to ignore. Last summer (Summer 2013), I used JavaScript to develop a bare-bones browser-based logic simulator (Electra’s Workshop, http://www.electras.org/workshop.html) – which does roughly everything that Toves currently does. Despite quite a bit of effort, it still doesn’t work as well as I’d like, which is why I haven’t publicized the effort much. In any case, I don’t think browsers are ready for a Logisim-scale program.

Ultimately, I chose C#, since it still allows development that works across Linux/MacOS/Windows, and it should also port to iOS and Android (though I haven’t really toyed with this enough to be sure). I had some reservations, largely because I would have to learn the language from scratch, though admittedly C# is very similar to Java.
So far, I’ve been happy with C#. My biggest surprise is that, despite being so similar to Java, C# is just different enough to require a substantial adjustment. I still haven’t adjusted entirely, and overall I still prefer Java, but I’m finding C# a very workable alternative. I’ll probably write more later about my critiques of C#.

My biggest recent frustration has been in packaging Toves for cross-platform distribution. This wasn’t particularly easy with Java, but over the years I had basically figured out a workable solution. I’m confident I’ll be able to figure it out for C# as well. For right now, I have some fairly ugly instructions written up for each platform at http://www.toves.org/download.html. Linux and MacOS are OK – though not as easy as I’d like – but installing and executing Toves on Windows is a major pain. You might think: C# was originally designed for Windows, so shouldn’t it be easy? But Toves depends on Mono being installed, and I haven’t yet found a way for Toves to automatically find Mono upon startup. I’ll be looking for a better technique.