Archive for the ‘Programming’ Category

Early 2014 I needed to write a website transaction monitor, that receives instructions on transactions to perform on websites using a real web browser. It performs the transactions and verifies that the website is working. Examples of transactions include log in to a website to verify that users can still login, or checkout on an e-commerce site to verify that the shopping cart is working. Being mostly an OOP programmer (with Ruby exposure to high order functions and anonymous functions), I quickly realized that my imperative style of programming would not be sufficient for this project. This program needed to be declarative and correctness was extremely important.

It was time to search for solutions outside the Ruby community and outside any community that favors OOP or imperative programming.

I first turned to the Common Lisp community searching for enlightenment, I started with the book “Practical Common Lisp” by Peter Seibel. Common Lisp seemed cool, way more capable than Ruby but I wasn’t feeling any enlightenment. My biggest problem with Common Lisp was that the language and its tooling is outdated in today’s modern programming world. Luckily I found and switched to Scheme.

After reading the book “Simply Scheme – 2nd Edition: Introducing Computer Science” by Brian Harvey, Lisp clicked in my brain, I got my first spark of Lisp enlightenment. I then read the “The Little Schemer” by Daniel P. Friedman, which is now one of my favorites books. Scheme became my favorite programming language.

Next I read the Wizard book, “Structure and Interpretation of Computer Programs” by Harold Abelson, then came the next level of enlightenment. Few chapters into the book I found answer to writing my declarative website transaction monitor. In a few lines of code, I wrote a website transaction monitor that works like a tiny lisp interpreter, takes instructions for transactions in the form of S-expressions which gets evaluated and performed on a website using a real web browser. This was written in Ruby available here on github, its part of a bigger project I’m working on and i’m still going to be cleaning it up.

At that point I was all about Lisp, I tried to see if I can use Scheme in the real world. Chicken Scheme is a good implementation to use for real world Scheme apps but around that same time, I discovered Clojure.

Clojure and its tooling is modern, and even got some inspiration from Rails and the Ruby Community. Clojure has programmer happiness in mind. I started learning Clojure bought the books “Programming Clojure” by Stuart Halloway, “The Joy of Clojure” by Michael Fogus, “Clojure Cookbook: Recipes for Functional Programming” by Luke VanderHart. Published my first Clojar little-couch, which is a simple port of my RubyGem Leanback from Ruby to Clojure. All just for fun.

I write Ruby code fulltime at my day job, my side projects are 99% Ruby, I’m heavily invested in the Ruby ecosystem, and Rails is still a powerhouse in web development, Rails is always a safe bet when building a web application, most problems you run into have already been solved by Rails. These are strong arguments for me sticking around with Ruby otherwise I would switch to Clojure/functional programming and never look back.

I wanted to experience a pure functional language, so I started learning Haskell, read and still reading “Learn You a Haskell for Great Good!: A Beginner’s Guide” by Miran Lipovaca. I enjoyed the book but I need to read other sources to understand Monads. I plan to spend some more time playing with Haskell in 2015. To fully understand functional programming I feel I should learn a pure functional language thoroughly. For now Haskell is my first choice with OCaml a close second. I also have Elixir in mind as a language to get into at some point.

In 2014, through functional programming I re-discovered programming once again, it felt like the time I first started programming, I felt that sense of adventure and endless possibilities. 2014 was the most fun I have ever had programming. I can say with evidence, that functional programming is the most fun you can have with a computer.

Also worth mentioning, I enjoyed reading the book “Functional JavaScript: Introducing Functional Programming with Underscore.js” by Michael Fogus.

From the recent poll on Hacker News “Poll: What are your liked and disliked programming languages?” I compiled a list of all the programming languages ordered by the percentage of their dislike votes. Cobol & Coldfusion are the two most hated languages with 94% dislikes. C & Python still gets a lot of love as the two most liked languages. I find it strange that my favorite language Ruby is not even in the top 15 most liked. Most Rubyists believe Ruby is the best scripting language to ever run on a computer, but 38% of these votes don’t agree, Ruby and Javascript are tied at 38% dislikes.

Since ruby class variables belong to the class hierarchy, all objects in that class hierarchy all the way up to ruby’s main object, share the same class variable. This could lead to unexpected behavior, especially since the class variable can be modified in the main context. See below modifying @@name in the main context changes its value on all objects.

I recently upgraded from Ubuntu 12.04 to 12.10 and Ubuntu automatically upgraded my CouchDB installation from 1.0.1 to 1.2.0. After the upgrade I started getting the error message “Bad request… Invalid JSON” anytime I try to add or query an existing design document.

A lot my code depends on CouchDB so this was a big deal, after hours of googling, still no solution until I found the JSONlint test. I realized that the old JSON parser in CouchDB 1.0.1 would parse invalid JSON with no problems but the parser in CouchDB 1.2.0 would throw an error.

This code below is invalid JSON but works fine on CouchDB 1.0.1. It will throw the ‘Invalid JSON’ error on CouchDB 1.2.0

There you have it and jQuery was everywhere. I write this as a Ruby/Unix guy, who thinks JavaScript had an extra-ordinarily great year. I may have missed other important moments. Feel free to add more in the comments.

It’s equally important to give credit to the players that helped make JavaScript the Technology of the Year. I will list them below:

The Open Source community: For all the awesome wizardry.

Google: For moving the open web forward, supporting the FOSS community and releasing great open source technologies like Google Chrome and V8.

The Webkit Open Source project and Apple.

Steve Jobs for excluding Flash on iDevices and selling HTML5 as the future of the open web.