Ruby: Optimized for Programmer Happiness
Sep 2, 2020 • posted by Michael Hartl
Learning to code? Learn Enough is based on the idea that you don’t have to learn everything about tech to get started—you just have to learn enough to be dangerous. This is the seventh in a series of posts introducing the main Learn Enough tutorials. You can also read the previous one or the next one. You might also enjoy the Learn Enough Ruby free sample chapters and free sample videos.
Michael Hartl here from the Rails Tutorial and Learn Enough.
Of all the programming languages I’ve used, Ruby is my favorite. My first programming language was BASIC; the first language I really loved was Python; and I’ve also used Pascal, Perl, PHP, C/C++, Mathematica, Lisp/Scheme, and JavaScript. But Ruby has an expressiveness and playfulness that the others all lack.
I don’t think this is a coincidence; Ruby was engineered this way. As Ruby’s creator Matz (Figure 1) puts it, the language is “optimized for programmer happiness.”1 As a result of this design philosophy, Ruby is a joy to read and write. It’s also an eminently practical language, with a wealth of built-in libraries, and has a powerful object-oriented design.
Learn Enough Ruby
Learn Enough Ruby to Be Dangerous, which is available as an online course, book, and videos, is designed to get you started writing practical and modern Ruby programs as fast as possible, with a focus on the real tools used every day by software developers. Among other things, it’s the perfect prerequisite for learning professional-grade web development with the Ruby on Rails Tutorial.
As a general-purpose programming language, Ruby is limited only by the developer’s imagination. As hinted above, Ruby has enjoyed especially robust adoption in web development, the art of writing dynamic web applications for the World Wide Web. But Ruby thrives in many other niches as well, such as shell scripting, text parsing, and package management.
Learn Enough Ruby to Be Dangerous can serve either as a prerequisite to the Ruby on Rails Tutorial (especially for those who haven’t programmed much before) or as a natural follow-on (for those who want to solidify their command of the underlying Ruby language). In particular, Learn Enough Ruby to Be Dangerous includes an introduction to web development with Sinatra, a small and relatively simple Ruby web framework that is excellent preparation for Ruby on Rails while also being a useful tool in its own right.
As noted above, there’s more to Ruby than web development, though, and Learn Enough Ruby to Be Dangerous treats Ruby as a general-purpose programming language right from the start. The result is a practical narrative introduction to Ruby—a perfect complement both to in-browser coding tutorials and to the voluminous but hard-to-navigate Ruby reference material on the Web.
Learn Enough Ruby to Be Dangerous broadly follows the structure of Learn Enough JavaScript to Be Dangerous, which can be studied either before or after its Ruby counterpart. Because many of the examples are the same, the tutorials reinforce each other nicely—there are few things more instructive in computer programming than seeing the same basic problems solved in two different languages.
You won’t learn everything there is to know about Ruby in Learn Enough Ruby to Be Dangerous—that would take thousands of pages and centuries of effort—but you will learn enough Ruby to be dangerous (Figure 2).2
There are no programming prerequisites for Learn Enough Ruby to Be Dangerous, although it certainly won’t hurt if you’ve programmed before. What is important is that you’ve started developing your technical sophistication (Box 1), either on your own or using the preceding Learn Enough tutorials. These tutorials include the following, which together make a good list of prerequisites for this book:
- Learn Enough Command Line to Be Dangerous
- Learn Enough Text Editor to Be Dangerous
- Learn Enough Git to Be Dangerous
- Learn Enough HTML to Be Dangerous
- Learn Enough CSS & Layout to Be Dangerous (optional)
- Learn Enough JavaScript to Be Dangerous (optional)
All of these tutorials are available for individual purchase, and we offer a subscription service—the Learn Enough All Access subscription—with access to all the corresponding online courses.
An essential aspect of using computers is the ability to figure things out and troubleshoot on your own, a skill we at Learn Enough call technical sophistication.
Developing technical sophistication means not only following systematic tutorials like Learn Enough Ruby to Be Dangerous, but also knowing when it’s time to break free of a structured presentation and just start googling around for a solution.
Learn Enough Ruby to Be Dangerous gives you ample opportunity to practice this essential technical skill.
In particular, as alluded to above, there is a wealth of Ruby reference material on the Web, but it can be hard to use unless you already basically know what you’re doing. One goal of this tutorial is to be the key that unlocks the documentation. This will include lots of pointers to the official Ruby site.
Especially as the exposition gets more advanced, Learn Enough Ruby to Be Dangerous also includes the web searches you could use to figure out how to accomplish the particular task at hand. For example, how do you use Ruby to manipulate a Document Object Model (DOM)? Like this: ruby dom manipulation.
If you’re up for a challenge…
If you’re up for a challenge, here’s what you’ll get if you join me in following Learn Enough Ruby to Be Dangerous.
We’ll begin at the beginning with a series of simple “hello, world” programs using several different techniques (Chapter 1), including an introduction to irb, an interactive command-line program for evaluating Ruby code. In line with the Learn Enough philosophy of always doing things “for real”, even as early as Chapter 1 we’ll deploy a (very simple) dynamic Ruby application to the live Web.
After mastering “hello, world”, we’ll take a tour of some Ruby objects, including strings (Chapter 2), arrays (Chapter 3), and other native objects (Chapter 4). Taken together, these chapters constitute a gentle introduction to object-oriented programming with Ruby.
In Chapter 5, we’ll learn the basics of functions, an essential subject for virtually every programming language. We’ll then apply this knowledge to an elegant and powerful style of coding called functional programming (Chapter 6).
Having covered the basics of built-in Ruby objects, in Chapter 7 we’ll learn how to make objects of our own. In particular, we’ll define an object for a phrase, and then develop a method for determining whether or not the phrase is a palindrome (the same read forward and backward).
Our initial palindrome implementation will be rather rudimentary, but we’ll extend it in Chapter 8 using a powerful technique called test-driven development (TDD). In the process, we’ll learn more about testing generally, as well as how to create a self-contained Ruby library called a Ruby gem (and thereby join the large and growing ecosystem of software packages managed by RubyGems.org).
In Chapter 9, we’ll learn how to write nontrivial shell scripts, one of Ruby’s biggest strengths. Examples include reading from both files and URLs, with a final example showing how to manipulate a downloaded file as if it were an HTML web page.
In Chapter 10, we’ll develop our first full Ruby web application: a site for detecting palindromes. This will give us a chance to learn about routes, layouts, embedded Ruby, and form handling. As a capstone to our work, we’ll deploy our palindrome detector to the live Web.
How to get it
There are multiple ways to get Learn Enough Ruby to Be Dangerous. All the different formats cover the same basic material in slightly different ways.
- All Access Subscription: Get full access to the online courses for Learn Enough Command Line, Text Editor, Git, HTML, CSS & Layout, JavaScript, Ruby, and all the Learn Enough courses for one monthly price. Includes the full 6th edition of the Ruby on Rails Tutorial.
- The Learn Enough Ruby to Be Dangerous online course subscription or ebook (including three free sample chapters).