John Carmack on type systems

It’s just amazing how many mistakes [are made] and how bad programmers can be. Everything that is syntactically legal, that the compiler will accept, will eventually wind up in your code base. And that is why I think static typing is so valuable.

John Carmack (full talk here – note this link jumps to this quote – part one of the keynote is here).

Pretty much sums up how I feel about the static v. dynamic debate for anything other than very short-lived prototypes.

Don’t fear the Monad

I recently watched Brian Beckman’s Don’t fear the monad talk (YouTube version here) and thought it was a really good explanation of functions, monoids & monads and why they’re a useful way to master complexity.

I recommend it to anyone who’s starting to look at functional programming. Here are some of the key points I took away from the talk:

  • Functions are data
    • A function takes an argument(/s) and returns a value, and always returns the same result for the same inputs
    • Think of a function as a table lookup – the table is the data
  • Functional programming is a style that can be used in almost any language
    • But some languages make it easier than others
    • First class functions (or at least lamdbas) are a must have
  • Complexity is killing software developers – we need to control it
    • The best way to control complexity is to put functions into groups where things are disciplined, and where they can be composed in arbitrary ways
    • Build complexity out of simplicity by composing things
  • A monad adds some data to a value, and the implementation of the bind operator defines how that data interacts
  • If you want to add a feature, you shouldn’t even have to know what you’re going to interact with
    • Using monads means the interaction is already built into the structure
  • You don’t need to know what a monad does
    • So long as it follows the rules, it can have arbitrary side effects

Another interesting part was Brian’s reasoning about why functional programming is a ‘hard sell’:

Immediately upon the foundation of computing, the world split into two camps – the bottom up camp and the top down camp.

The bottom up camp is typified by Turing machines – “let’s start with the hardware and add abstraction as we need it to get close to the mathematics, but never at the expense of performance”. That gave rise to FORTRAN, C, C++, Pascal, Java, C# … all of those languages are in that tradition.

The top down crowd says “let’s start with the mathematics and subtract abstractions to get down to the machine, sometimes at the expense of performance”. That tradition starts with lambda calculus … and only subtracts abstraction when it is convenient to do so. That’s the tradition that gave rise to ALGOL, Lisp, Smalltalk, ML, Haskell and all these languages that have reputations of being slow.

As most programmers are familiar with the bottom up way of doing things and the two approaches come from very different origins, it can be hard to convince a bottom up programmer of the benefits of the ‘top down’ approach. It can be even harder to pick up functional programming once you’ve resigned to giving it a try.

[The top-down crowd] are saying “don’t go to the hardware so early, you’ll lock yourself into irreversible design choices”. [The bottom-up crowd] are saying “don’t give me all this math, I can’t handle garbage collection, or function calls or whatever it is that’s getting in the way of my performance, I need every ounce of performance the hardware can give me. And I’m willing to write software into the wee hours of the morning to get it”.

The last sentence here is what stands out to me – as software gets more complex, it seems that bottom up programming is going to require more and more time working in the wee hours of the morning to get the desired performance and functionality.

Maybe Haskell …

After reading Learn You a Haskell on and off over the past fortnight and watching a couple of Erik Meijer’s Functional Programming Fundamentals, I finally got around to installing the Haskell platform and firing up GHCi.

After a couple of hours of implementing the simple functions scattered throughout LYAH, I was up to implementing quick sort. Given the number of times I’ve seen this example, I’m not going to reproduce it here, but it’s pretty amazing 1.

One of the main things I noticed was that after two hours of writing code in a language I’d never used, I’d produced zero run time errors. There were plenty of compile errors, but that’s to be expected – especially given I was using an editor that was inserting tabs in a language with significant white space (which, by the way, makes for fun times when unfamiliar with Haskell compiler errors). I know what kind of error I would prefer to deal with.

So far I’m liking Haskell, and I think it’s a huge shame that there is only one functional programming course at my university (COMP1024), which isn’t available to most dual degree students.

Edit: COMP1024 hasn’t been offered since 2010.


1. I know this isn’t ‘true’, in-place, high performance quick sort, but in how many other languages can you write a readable, generic sorting algorithm in 6 lines of code?

VirtualBox + Dell laptop VT-x issues

I recently had to use a VM for a uni project, and needed to have access on my laptop & desktop. I haven’t used a VM on my laptop in a while, but didn’t expect to see the following error message from VirtualBox (4.2.16):

VT-x features locked or unavailable in MSR.

I’ve used x64 hosts before with no problems, but I guess my BIOS settings were reverted for some reason (using a Dell laptop with Intel PM45 chipset).

So thinking to myself that this should be an easy fix, I rebooted, enabled VT-x and restarted, but I received the same error message. No amount of changing BIOS/VirtualBox settings, rebooting or otherwise reconfiguring would make this message go away.

I eventually read that it’s sometimes necessary to power down and physically disconnect the machine from power to properly enable VT-x. This solved my problem – I decided to make a note of it here to hopefully help someone else in the same situation.

Ubuntu 12.10 – Transmission fails to connect to HTTPS trackers

Transmission, the BitTorrent client installed by default in Ubuntu seems to have an issue with connecting to trackers using HTTPS at the moment.

After Transmission failed to connect to a tracker using HTTPS, I went searching and found this bug report.

The steps there are pretty simple and worked well for me:

  1. Close Transmission
  2. Download the .deb for updated libgnutls26 from here (bottom of page – choose your architecture then mirror)
  3. Install using

     dpkg -i (package name).deb
    
  4. Restart Transmission

UPDATE: It looks like this is now fixed, so running

sudo apt-get update
sudo apt-get upgrade

should get it working again for you.