Backbone.js by example – Part 1

Backbone.js is a Javascript MVC (model-view-controller) library that provides complete support for building clean and easy to maintain client side code. What I like in Backbone.js is its light weight (~4.5kb) and that it doesn’t get in my way by imposing how my application should be architected or organised. Backbone.js is not even restricted to single page interfaces or to Javascript heavy applications. It lays a good foundation that helps writing well structured, easy to maintain and easy to extend client side code.

I started learning Backbone.js a few weeks ago and I fell in love with it. In this post we will build a concrete application step by step: a simple graphical editor (for the impatient, here is what we are going to build in about 100 lines of javascript). We will focus on basic aspects of models and views. Routing and communication with the server will be covered in the next part of this tutorial.
Read the rest of this entry »

Benchmarking numeric base conversion in C#, Java and Scala

A few days ago, I needed to encode numeric identifiers in a short and url-safe format. Something similar to what url shorteners use (e.g. jcsSXP in Encoding the ids in base 64 would work if an alternative alphabet is provided for the non url-safe symbols. But since I wanted to have only alpha-numeric characters, I chose to use base 62 instead.

While working on this problem, I had the idea of the coding exercise I’m sharing here: a utility for converting back and forth base 10 numerals to strings of base X equivalent –just like itoa and atoi in C (except that atoi doesn’t take a base parameter). In order to make things a bit more interesting, I decided to learn myself some Scala and translate the code to functional style. Both implementations are detailed here and available online under the terms of the Apache version 2 license.

At the end, I didn’t resist the temptation to do a C# vs. Scala performance benchmark. I also coded and added a Java implementation to the tests in order to distinguish the performance change due to switching from the CLR to the JVM, and the one introduced by the translation to functional style and to the Scala runtime.

Read the rest of this entry »

You are not protected by the compiler

Dynamic vs static typing debates are often passionate. Probably too passionate to be totally objective. During one of these discussions I was involved in, a well respected senior engineer have made an interesting statement :

” … My lisp program crashed after hours of computation right before delivering the result due to a missing method runtime error. This would’ve NEVER happened in a statically typed language. For instance, this would’ve never happened in C++ using the latest Microsoft C++ compiler. With all the static analysis it performs, these errors are prevented. You are protected by the compiler! …”

Well, I don’t know how good is the MS compiler compared to other C++ compilers. Still, we’ll show how ridiculously easy it is to fool it and have the same missing method crash.

Read the rest of this entry »

Binary Heap, Heap Sort and Priority Queue

In this post I share another code Kata : an implementation of a binary heap. Once we have the heap implemented, we will easily deduce a heap sort and a priority queue based on it. It takes about 100 lines of C# code.

Read the rest of this entry »

Recursive and Iterative Merge Sort Implementations

I find merge sort elegant and easy to implement and to understand for both iterative and recursive approaches. In this post I’ll share a quick (and probably dirty) iterative and recursive implementations of merge sort. Both versions share exactly the same merge operation. The implementation takes less than 30 lines of C#.
Read the rest of this entry »