How to Learn Ruby (or any programming language)
This guest post is contributed by Geoffrey Grosenbach, who designs, produces, and publishes the acclaimed PeepCode Screencasts for web developers and alpha geeks. PeepCode publishes cutting edge training videos on jQuery, Git, Ruby on Rails, RSpec, and iPhone development.
The first programming language I learned was BASIC. Not Visual Basic or Real Basic but plain BASIC – line numbers, GOTO, and all.
But it wasn’t just my first programming language, it was also my first experience at programming, period. We learned from recipe cards that introduced one aspect of the language and then asked us to write a program (which happened to need the keyword or technique that was just introduced).
At the age of 10, I remember staring at some of the cards with absolutely no idea where to begin. I didn’t have any of the thinking tools that I do now: breaking a problem into smaller parts, rephrasing a problem from the perspective of the user, building a list of expectations.
On the other hand, the problems were small and most could be solved within a single technological epiphany. The best lesson I learned was one I still use everyday: most problems can’t be solved in a single 5-minute session of thinking (which happened to be the length of my attention span at that time). I’ve since learned new skills and thought of creative solutions to problems by noodling over them from many angles and sometimes over quite long periods of time. However, an online information systems degree is still your best option for learning.
Learning Ruby is no different. Here are three angles from which to contemplate Ruby.
Now that I’ve learned the core principles of programming (variables, loops, methods), I start learning any new programming language by comparing the new syntax to other languages that I know.
How are variables set? How do I define and call a method? Do lines of code end in a semicolon or without? The bare basics.
Sometimes I find it easiest to just look at a few pages of existing code and try to figure it out. But this can be dangerous! Things that look familiar may have unexpected nuances. As soon as possible, try out your suspicions by writing a few lines of code to see if it works as you expect. Ruby comes with
irb (an interactive console) but saving code in a file makes it easier to refer to later or run again.
After learning what’s possible, I try to learn how the language is actually used by those who know and love the language.
When I first learned to use the Git source code control system, I was able to do everything I needed. But I soon learned that I was doing it in the wrong way. After talking to someone who uses it every day, I discovered that there were much easier ways to accomplish common tasks.
Ruby developers mostly stick to a similar aesthetic: use underscores for variable and method names, but camel case for class names. Indent with two spaces. Use underscores for file names (even if it contains a class that is camel cased).
Higher-level code strategy gets more complicated. Many Ruby developers prefer the “no code is faster than no code” approach. Write code that covers the most likely scenarios (and error conditions) rather than importing libraries with dozens of methods that will never be used.
Others prefer a more full-featured, full stack approach where everything they need is already available in a framework (but may include tens of thousands of lines of unused code).
Understand both philosophies and use the one that’s most appropriate for the current task. If you know many developers who use Rails, find others who use it rarely and learn from them about other possible ways to organize your code.
Once I’ve learned the syntax and culture of an unfamiliar programming language, I test my new knowledge on a fresh project. This is your chance to combine technical knowledge with a fresh perspective in order to produce a creative outcome.
Although most programming languages can accomplish the same tasks, each has its own differences that make some problems easier than others.
call, and the various code evaluation techniques.
Don’t limit your creativity by the code you see other people write. Have your own ideas. Explore new styles and techniques. This is how advancements in computer science are made.
There are many resources available for learning Ruby. But your most important resource is your mind. The approach you take when learning Ruby will affect not only the speed at which you learn, but the ideas you think of and the programs that you write. If you are serious about learning Ruby or any other programming language, think about obtaining an information technology degree from a college or university.
Post supported by 1st Easy Limited: 1st Easy Limited offer UK based Ruby on Rails hosting running on a Phusion Passenger™ and LAMP stack. If you want to get to know us first, or simply want to try out your Rails or Sinatra skills, let us arrange a free trial hosting account for you – friendly technical support from our team is included!