An ASP.NET MVC3 implementation of the cancerous Node.js Fibonacci code

I like to tinker with Node.js. Ted Dziuba doesn’t anymore. He thinks node.js is a cancer.
Obviously, a few people disagree – Joshua Kehn and Brian Beck. Ignoring all issues of relevance or flaimbait…and even ignoring all issues of original intent of the article, I was curious to see how C# under ASP.NET MVC3 fared in this little shootout.

I set up a simple MVC application. One controller. It looks like this:

public class HomeController : Controller
        private int Fib(int? n){
            if (n < 2)
                return 1;
                return Fib(n - 2) + Fib(n - 1);

        public string Index(int? n)
            if (string.IsNullOrEmpty(n.ToString()))
                n = 2;
            return Fib(n).ToString();

I ran it on an instance of IIS6.

$ time curl http://localhost/?n=40
real    0m0.343s
user    0m0.015s
sys     0m0.015s

Not too bad really. Haskell, however, is super duper fast – as Mathias Biilmann shows.

There’s a little fun for a Tuesday morning.

Vanilla Forums plugins – escaping SQL strings on Setup

chemical element for vanilla

Vanilla Forums is basically built upon a customised MVC framework called Garden. It makes developing plugins for Vanilla fairly neat, but documentation is somewhat thin on the ground for the actual Garden framework. When working on the Setup() function of my plugin, I was doing some initial data insert into a new table I was creating. Since I was inserting a fair amount of data, I was populating an array which would subsequently be used by the Vanilla/Garden data layer to do the insert; something like this:

$ret = $SQL->Insert('eub_NewTable', 
          array('Name' => 'Grand father', 'TreeLeft' => 1, 'TreeRight' => 28, 'TreeLevel' => 0, 'LevelOrder' => 0, 'ParentID' => 1),
          array('Name' => 'Bill's father', 'TreeLeft' => '2', 'TreeRight' => '365', 'TreeLevel' => '1', 'LevelOrder' => '2', 'ParentID' => '0')

Woops….there’s a single quote in there….

Unfortunately, unless I am doing something very wrong, it seems that Vanilla/Garden doesn’t escape these for you. I suspect there is a function somewhere in the framework to do the escaping for you, but I decided to hack it for the sake of speed… this:

array('Name' => 'Bill's father',

And we have a winner. And I gan get onto more exciting things than populating my base data.

Principles not techniques

I like to think of coding in terms of principles vs techniques. I’ve met tons of good coders with lots of technique. Good technique. Rote technique. I’ve met very few coders who have good principles. A principle will let you look at anything code related…..and understand it….and if need be troubleshoot it.
Continue reading Principles not techniques