Saturday, September 01, 2007

I love c#.. but lately.. whoa!

So lately I’ve been wanting to get into some programming on my Mac (yes I own a mac and develop .NET at work). Well I don’t really have a lot of time to devote to some new language like Objective-C. Yes I could use Java.... but I’ve really started to like c# a lot better than Java lately (maybe because it’s just what I’m used to, and I want to avoid people bashing me for taking sides :) ).
Anyways I’ve kept tabs on the Mono project every now and again and recently decided I’d give it a go. So I downloaded the latest (right now it’s 1.2.5) and started to tinker. I did the cheesy ‘Hello World’ console stuff just to start out. Well I’d really like to develop ‘real’ things, ‘useful’ things, but I was a little concerned about the GUI aspect (WinForms). I’d read a few places saying you need to install GTK and blah blah to get it working and that kinda turned me off of the whole thing.
Well I think I had been reading some slightly out-dated material. I wrote a little program to just pop-up a MessageBox and what do you know.. it worked!... and it worked on my Mac! (well you do have to run X11 first, but hey it’s a small price to pay)..
Then I wanted to see what new stuff was added to Mono. So I implemented a quick Lambda just for fun. Well it didn’t work right off the bat but after a couple Google searches I found the answer.
To use Lambdas, and some of the other c# 3.0 features, you need to use the ‘gmcs’ not the ‘mcs’ mono compiler command. (I remember reading that gmcs was newer and they plan on getting rid of mcs I think with v 2.0... don’t quote me though that’s from my wonderfully not so good memory). AND you need to provide this argument to compiler ‘-langversion:linq’. And that’s it!
So here’s my little program I did..
using System;
using System.Windows.Forms;
namespace Test {
   delegate string GetMessageDelegate(string name);
      public class Test {
         public static void Main(string[] args) {
            Console.WriteLine(“Hello from the console”);
            GetMessageDelegate getMsg = name => string.Format(“Hello {0}”, name);
And here’s what I did to compile and run.
gmcs -langversion:linq -r:System.Windows.Forms Test.cs
So basically you’ll get the message on the console and a message box that displays “Hello Frank”;
So I’m pretty sure I’m gonna stick with Mono/c# as my choice for development on my Mac :)