Thu, 05 Feb 2009

Why You Should Use F# if you use C#

So I've been doing a lot of work in C# lately. That is, for the last six months. In fact I've pretty much been doing nothing but C#, javascript (minus all that icky browser-stuff), and the occasional cmd.exe script. In other words, everything new.

And except for cmd.exe, I actually like all of it. I used to think that C# was just like Java (specifically, just like Java 1.5, the version I learned at school and decided I'd rather not use again thanks very much), so why would I want to use it, but I'm a convert. If you're going to be using a C-syntax-style language, C# seems like the cream. I've also been really grooving on the Javascript too, but that's for a later post.

The things about it that I like in no particular order:

  1. Delegates and Lambda expressions. Seriously, there are just so many times when you don't want the overhead of defining a function, or when you want the close over a (set of) variable(s) that I really would miss this if I were working in C++ or Java. I'm still not totally clear on when to use one and when to use the other.
  2. Extension methods. This is just syntactic sugar over the c-style way of doing object oriented programming. Here, you can just define a method, and decorate the first argument with the 'this' keyword, and voila! you can officially pretend that your method was embedded in the original object definition.
  3. var. Seriously, there are just so many times when you don't want to commit to a type yet. This saves you in two places: the places where the type is manifestly clear from the context, and places where you have a method that returns a type, but you anticipate that type changing frequently as you refactor.
  4. Object Literals and Collection Initializers. Not as complete as Javascript object literals, but enough that you can define a dictionary literal for example.

Now all that stuff is great. But I'm actually not here to tell you about that. I want to talk about F#. Not because I know it. In fact, I took a book out of the MS Library recently on it, but I returned it almost unopened. (Ditto for Lisp In Small Pieces. I know, I know, take away my geek license now.). But even though the only F# I know is how to end a statement (;;), it has stood me in good, uh, stead. This is because it fills in the gap of the one thing that C# has been missing: a REPL. And this is one thing that F# provides.

So, if you've ever wondered what is the actual string that a System.DateTime.Now.ToString() provides, wonder no longer. Well, what kinds of strings does a DateTime successfully parse? just try it. And no, this isn't the same as just generating a tiny sample program (trust me, after 6 months of learning/using C# on the job, my Visual Studio Projects directory is full of tiny toy projects that exist only to answer a question about the language/syntax/semantics/libraries. But I've replace the need for that with a single empty F# project that I use strictly to provide a REPL. So now I just leave it running all the time, my beloved FSharp_repl project.

F# REPL

So seriously, go and download it now if you're on Windows (and using Visual Studio). It'll save you hours and hours while you're learning. Plus who knows, you may even learn F#!

posted at: 15:28 | path: /Tools | comments/permalink

Tue, 03 Feb 2009

Things to Learn

It turns out that there are a log of things that need to be learned when you do my job. And as far as I can tell, there is no end in site. So I thought I'd make a little list of things that I'm sort of embarrassed that I don't really know and see how much of it I'm still ignorant of or embarrassed by in six months, a year, five years.

  1. SQL. Yeah, I took a course. The content dribbled out too slowly for me to pay attention. I assume that at some point someone will say "go handle this database issue for us" and I'll finally take the time to learn it.
  2. Linear Algebra. Yeah, This is a special case of "math". Really I could just put 'Math' here and it wouldn't be far wrong.
  3. Javascript. Funny story. I'm actually learning it for a project at work right now. Unfunny part? Almost no HTML/CSS interaction. So really, a very limited form of Javascript.
  4. Parsing technology. Well, beyond recursive descent. You know, Lex/Yacc style parsing. Dragon-book parsing. You know, the hard stuff. ;)
  5. Operating systems. That course that they make you take? I didn't get a chance to take it. I took advanced networking instead. Life is trade-offs.
  6. Assembly. Presumably x86. I've made a few half-hearted stabs, but nothing ever really stuck.

I'll add to this doc as I remember more things, but I'll publish now. I've been doing a lot of thinking about learning in my profession recently, and I suspect it'll be the source of a number of entries.

posted at: 08:17 | path: /Learns | comments/permalink

Fri, 02 Jan 2009

Let's Build a Compiler: The Beginning.

The Post is here

Discussion here: A Compiler is born

Code here

posted at: 17:37 | path: /LBAC | comments/permalink

A Crazy Idea

I had a crazy idea. I wondered if I could use reddit as a blog. Unsurprisingly, the subreddit for my name was unclaimed!

My inaugural post: Welcome To My Blog

I'll see if it works out.

posted at: 17:33 | path: /Meta | comments/permalink

Thu, 16 Oct 2008

A Deployment Plan Emerges

Well, I can't tell you how many times I've broken and fixed my site on the server that hosts it. Ok, it was 5. Anyway, it was too many. So my new system is very high tech. It's called rsync. Yeah. Fifty year old technology. Very swish.

::read more >>

posted at: 00:32 | path: /Meta | comments/permalink