Red Green Repeat Adventures of a Spec Driven Junkie

Your first programming language should not be Ruby

(but Ruby should be one of the programming languages you know!)

Ruby is a great language, but it is definitely a hard language to learn the first time you start programming a computer. I learned Ruby as my third maybe even fourth programming language and I still get caught up in some concepts. Ruby is a great language and I love working in it, but there are some things about the language that make it very hard to learn as your first programming language. The design of Ruby is not meant to be your first language. There are too many ways to do one thing. There are many advanced concepts rolled into Ruby.

Ruby design philosophy

“The goal of Ruby is to make programmers happy.”

Yukihiro Matsumoto, creator of Ruby programming language, Aug 2011

If you are not a programmer, you might not have a good time using Ruby because, well, it’s designed for people skilled at programming! At its very core, Ruby is designed for other programmers. Never for someone to learn programming. Designing something an advanced practitioner can use joyfully and something a new user can learn easily are diametrically opposites. Having such an advanced programming language as your first language is not going to be easy.

Syntactic sugar

Ruby is so full of syntatic sugar, many ways of doing the same thing. A friend got an introductory course on Ruby and his main comment was: “there’s so many ways to do things!” (and he’s a Computer Science graduate from a top tier university who has worked in a few languages already!) Ruby has a lot of ways of doing one thing. Take for example: Getting the first value from an array.

  • array[0]
  • array.first
  • array.take(1).pop
  • array.fetch(0)
  • array.at(0)

and if we include methods that mutate the array:

  • array.pop
  • array.shift
  • array.delete_at(0)

array[0] is the standard way to get the first element of an array. C has it, Python has it, JavaScript has it. It’s almost universal in every programming language. Array access not only has this, but there are another handful of ways to access the first value from an array. I know all are not used in practice, but there’s a lot of ways to do the same thing. As a first programming language, simpler is better. As my second or third language, I love this syntactic sugar, it makes programming fun.

Many concepts; one language

Ruby has been inspired by so many languages, primarily: Lisp & SmallTalk, but also borrows paradigms such as: functional, procedural. object-oriented. In essence, it means you can apply many ways of solving a problem using different programming concepts or paradigms.

Want to find the largest element in an array? How about procedurally:

array = [1,2,3,4,5]
max = 0

array.each do |i|
  if i > max
    max = i
  end
end
puts max

How about functionally?

puts array.inject(0) { |i, max| i > max ? i : max }

How about building an object?

def my_max(*values)
  values.max
end

puts my_max(array)

How about using the built-in method?

puts array.max

A coworker suggested a good programming question to ask in an interview is: “reverse a string in place”. In Ruby, the solution can be: ‘string.reverse’. QED.

As awesome as it is to have so many programming concepts in one programming language, learning how to program for the first time with Ruby is very hard, mainly because there are so many ways to solve it. Seeing others’ code will be confusing because they will apply different techniques to solve the same problem.

Learning how to program by doing it one way only is very valuable. Having too many ways of solving a problem at the beginning of learning how to program is tricky as a student will have to grok multiple concepts at once.

I love Ruby, but not as a first language

As a language, I love Ruby. I love all the syntactic sugar it provides, the multi-paradigms rolled into a single language, and that Ruby is a language designed for programmer happiness. I feel these things can only be appreciated by someone that is a programmer and has learned programming in a different way, a harder way. Jumping straight into Ruby without any other programming language experience is tricky as there’s too many ways to do things, too many different concepts going on, and it is a language designed for someone that is already a programmer. If you know another language, definitely check Ruby out. It’s still one of the funnest languages I’ve programmed in.

What can I do if I don’t know another programming language?

What’s the solution? Learn another programming language first.

Any other one, preferably a small one that is relatively stable. Go with C. It’s very straight-forward and the standard library is pretty small and stable. The entire C language book, “The C Programming Language” by Brian Kernighan and Dennis Ritchie, is less than 250 pages. Ruby is built on C, wouldn’t it be great to start learning Ruby with a good foundation?