Jan 9

Many a times I have been asked by my friends, “How do you come up with a business idea?”. My instant reply is “Look around. Find a problem thats hurting people. If you can find a way to solve that problem, you have got your business idea.”

Today I want to glorify the above statement with an example in the content of rails development community.

Consider this report The State of the Stack: A Ruby on Rails Benchmarking Report – 10 June 2009 which lists the most commonly used versions of Ruby, Rails, and plugins in actual 1800 production applications. Go to the plugins portion of the report. The image showing the usability of  plugins is as follows:

Rails Plugin usage - june 2009

Now consider the same report but the January 2010 version. The image below shows the the plugin usage in about 3000 rails apps.

Do you see a major difference at the top. The top used plugin in January 2010 doesn’t even exist in June 2009. And what does hoptoad do. In principle it does the same work as exception notification(the top plugin of June 2009) but in a much better way. The problem with exception notification was that you had to manage all your exceptions via email. This means you weren’t able to do the following things:

  • Club exceptions and record the counts.
  • Keep a record of which exceptions have been resolved and which are unresolved.

Hoptoad made it easy to manage your exceptions and in 6 months its one of the most used rails plugins. And mind you its not totally free. Its based on the freemium business model. If you have a decent sized app then the free model wont suit you. (from personal experience). Thus hoptoad solves a critical problem in a better way than existing methods and also earns a handsome revenue. Kudos to the hoptoad team!!

Report Source: http://railslab.newrelic.com/

Jan 7

Coming from C language paradigm to ruby, unless might seem just the “awesome” feature which was missing in C.

Here are some examples highlighting the beauty:

1. When used as a Statement modifier

raise InvalidData unless AllowedDatum.include?(data)

looks much better than

raise InvalidData if !AllowedDatum.include?(data)

2. When used without else

unless condition
  #code block

looks much better than

if !condition
  #code block

However the problem with using unless starts when we have the following two cases

3. using unless with else

unless condition
  #code block 1
  #code block 2

is difficult to understand than

if condition
  #code block 2
  #code block 3

4. Concatenation of conditions

unless condition_1 || condition_2

has to be always deciphered into

if !condition_1 && !condition_2

to get a feeling of whats happening

However using !condition takes the beauty out of your code. For example

if !element.nil? && !allowedParams.include?(element)

is not as beautiful and readable as

elem.call_method unless elem.blank?

To solve the above problem we at intinno have a following mixin defined:

class Object
  def not_nil?

  def not_blank?

  def not_eql?(value)

  def not_empty?

  def not_included?

An example of using the above mixin is

if element.not_nil? && allowedParams.doesnt_include?(element)

Now our code looks like Angelina Jolie and is as readable as any of Chetan Bhaghat’s novels.