Writing in C# on Mac OS X
Curiosity got the best of me, It really did. I had listened to Hanselminutes “State of the Mono Project” and I had to try it. I have a current version of Mono for windows installed on my work PC, but I had to try it on a Mac. My Beautiful Wife has a Mac and has for a long time. Truthfully I am a huge fan of Apple’s hardware and software. I think that iTunes is one of the best pieces of software the PC has ever seen. Writing Mac OS X on top of BSD was simply brilliant in my opinion. I’ve always wanted to write software for the Mac. However I work at a Microsoft shop, so there hasn’t been any really need or opportunity for me to write software for the Mac. However now with the Mono Project and .NET the idea that I can write something on the Mac, compile it to IL (Intermediate Language) and it can run in Windows is exciting. This is exciting in two ways, first, who doesn’t want to write code in a language they are very comfortable with (C# for me) that will run on just about any OS. Secondly, like I said before, I am a big fan of Mac stuff, and I would love to be able to work on a Mac, even though I work in a Microsoft shop. This idea came to me when I was watching a screencast of C# code being ran in both Mono and .NET interchangeable. Well if the frameworks are that interchangeable I should be able to write code on the Mac and have it run in Windows or Linux. Although after I did some research I found I wasn’t the only one that has had this idea. Good that means I won’t be in undiscovered county alone. Since most of my work is done in ASP.NET and C#, these are the two components of .NET/Mono that I am concerned about.
Coding on a Mac
It’s been a long time since I’ve written anything on a Mac. The last thing I wrote on a Mac was a web site. So HTML isn’t nearly as complicated as compiled code. That being said most of the code I write is in Visual Studio .NET. This is a pretty complete IDE, that has a designer and a code editor and includes intellisense. I am so addicted to using intellisense that it is something I feel I need for writing all code. Of course we use Windows XP SP2 at work, so these are the environments I am use everyday, so that is what becomes my benchmarks so to speak.
As with any new venture I did a little research. Of course Mono Project’s web site was my first stop. After a little bit of reading I downloaded the Mono Framework for Mac OS X and installed it. It gets installed in /Library/Frameworks/Mono, this is something you’ll need to know a little later. Also I always like to know where things get installed. The other thing gets installed is Cocoa# (Cocoa-Sharp). Cocoa, is the UI for Mac OS X, so Cocoa# lets your Mono/C# code use Cocoa for the UI instead of GTK. While this isn’t as completely ambiguous as using GTK for a “windows” application, it is nice to be able to use the Interface Builder and XCode. I’m installed this stuff on my Wife's computer, so I need to be careful about what I am installing and how hardcore it is. That is why I haven’t installed MonoDevelop yet. I’ll need to upgrade her computer to Tiger before I start down that road.
The first project I tried was an example on the Cocoasharp.org site, the HelloWorld Tutorial. It’s tradition your first project for any new programming language or style has to be Hello World, and who was I to break tradition. The Tutorial was laid out nicely, and had you use TextEdit to write C# code in. Of course it doesn’t have intellisense built into it but I was game. It’s a really nice text editor that lets you use rich text or plain text, for this project we were using plain text of course. It took me about ten minutes to work through. Most of the time was just getting familiar with where things were on the Mac. And I do have to say that I kind of dug using the terminal windows (command line console for windows folks) to compile and package the application. In the end I got a little window that Popped up and said “Hello World”. Whatdya now, this stuff works.
The second Tutorial I tried was the Simple Tutorial from Cocoasharp.org. This one delved into the Interface builder a little more then the previous tutorial. While this is a Simple Tutorial I learned quite a bit about Interface Builder. How events and object are tied to the code and each other. While coming from the Visual Studio side of things, I am fairly use to using a form designer, It did take me a minute or two to catch on to how things are done in Interface Builder. My overall impression is that this is a great tool. Unlike Visual Studio it doesn’t seem to try to straddle the link of a designer you can code in, and that is a good thing. In the right hands, a beautifully designed application can be created without the designer having to know code at all. While that does leave what seems to be more work for the programmer, I definitely see the benefits. First you don’t have to erase any code, and links to that code as you do in Visual Studio. VS, will set up your objects, events and events handlers auto magically, which is nice, unless you want something that is a little different, or non-standard. Then you have to go through and find all the references to the object, event and event handler and remove them or edit them. I sometimes like to write my own event handlers or a generic event function to deal with several objects, textboxes let’s say. So if I have a form in Interface Builder, I created an instance of the class and then link it to my generic event function. I like that. Of course, it’s not called events and functions, it is Actions and Outlets, but I found that pretty easy to get use to.
When it comes to Xcode, I don’t have a lot to say. Mostly because I was using version 1.2 and the current version is 2.2. I’ve also found out that there are Xcode Additions for .NET that would of made coding a prettier experience. So I’ll not give any criticism because I didn’t do enough homework on this IDE to give any worthwhile information. The one thing I will says is I like being about to choose between a multi-page layout for editing and a single page layout where I could arrow to the next page/code class I was working on.
First, man I need to get a Mac. I really enjoyed coding on it, and I love the OS. As far as some of the coding go, it would of been really nice to have had everything completely update, because that is what the frameworks, really require. The fact it was an older version of Xcode kept me from installing MonoDevelop, and I am sure that would of changed the experience quite a bit. I also ran in to some confusion as to use the “Apple.Foundation” and “Apple.AppKit” namespaces verses the “Cocoa” namespace when interfacing with the
“nib” file that Interface Builder produces. Again however, I believe that if I had had the current version of XCode and installed MonoDevelop, it wouldn’t of been an issue. So my plans for the future? See about getting a Mac Mini, or iBook and start coding.