Ruby Under a Microscope and over 2 million other books are available for Amazon Kindle . Learn more


or
Sign in to turn on 1-Click ordering.
Trade in Yours
For a 4.78 Gift Card
Trade in
More Buying Choices
Have one to sell? Sell yours here
Sorry, this item is not available in
Image not available for
Colour:
Image not available

 
Start reading Ruby Under a Microscope on your Kindle in under a minute.

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

Ruby Under a Microscope: An Illustrated Guide to Ruby Internals [Paperback]

Pat Shaughnessy
5.0 out of 5 stars  See all reviews (1 customer review)
RRP: 25.99
Price: 17.05 & FREE Delivery in the UK. Details
You Save: 8.94 (34%)
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
Only 7 left in stock (more on the way).
Dispatched from and sold by Amazon. Gift-wrap available.
Want it Monday, 25 Aug.? Choose Express delivery at checkout. Details

Formats

Amazon Price New from Used from
Kindle Edition 16.20  
Paperback 17.05  
Trade In this Item for up to 4.78
Trade in Ruby Under a Microscope: An Illustrated Guide to Ruby Internals for an Amazon Gift Card of up to 4.78, which you can then spend on millions of items across the site. Trade-in values may vary (terms apply). Learn more

Book Description

22 Nov 2013 1593275277 978-1593275273 1

Ruby is a powerful programming language with a focus on simplicity, but beneath its elegant syntax it performs countless unseen tasks.

Ruby Under a Microscope gives you a hands-on look at Ruby's core, using extensive diagrams and thorough explanations to show you how Ruby is implemented (no C skills required). Author Pat Shaughnessy takes a scientific approach, laying out a series of experiments with Ruby code to take you behind the scenes of how programming languages work. You'll even find information on JRuby and Rubinius (two alternative implementations of Ruby), as well as in-depth explorations of Ruby's garbage collection algorithm.

Ruby Under a Microscope will teach you:

  • How a few computer science concepts underpin Ruby's complex implementation
  • How Ruby executes your code using a virtual machine
  • How classes and modules are the same inside Ruby
  • How Ruby employs algorithms originally developed for Lisp
  • How Ruby uses grammar rules to parse and understand your code
  • How your Ruby code is translated into a different language by a compiler
No programming language needs to be a black box. Whether you're already intrigued by language implementation or just want to dig deeper into Ruby, you'll find Ruby Under a Microscope a fascinating way to become a better programmer.

Covers Ruby 2.x, 1.9 and 1.8


Product details

  • Paperback: 360 pages
  • Publisher: No Starch Press; 1 edition (22 Nov 2013)
  • Language: English
  • ISBN-10: 1593275277
  • ISBN-13: 978-1593275273
  • Product Dimensions: 23.4 x 18 x 2.2 cm
  • Average Customer Review: 5.0 out of 5 stars  See all reviews (1 customer review)
  • Amazon Bestsellers Rank: 167,025 in Books (See Top 100 in Books)
  • See Complete Table of Contents

More About the Author

Discover books, learn about writers, and more.

Product Description

About the Author

Well known for his coding expertise and passion for the Ruby programming language, Pat Shaughnessy blogs and writes tutorials at https://patshaughnessy.net/. He also develops Ruby applications at management consulting firm McKinsey & Co. Shaughnessy is a regular presenter on the Ruby conference circuit, and his articles and presentations have been featured in the Ruby Weekly newsletter, the Ruby5 podcast, and The Ruby Show.


Inside This Book (Learn More)
Browse Sample Pages
Front Cover | Copyright | Table of Contents | Excerpt | Index | Back Cover
Search inside this book:

Customer Reviews

4 star
0
3 star
0
2 star
0
1 star
0
5.0 out of 5 stars
5.0 out of 5 stars
Most Helpful Customer Reviews
1 of 1 people found the following review helpful
5.0 out of 5 stars See the wiring under the board 12 Feb 2014
Format:Paperback
Let's start with a disclaimer. I'm not a Computer Science major, nor did I complete a Computer Science course of study in school. I'm a software tester, and one that finds themselves frequently using programming languages of various stripes for various purposes. Ruby is one of the most popular languages in current use, and for many, it's a language that allows them to learn some basic terms, some programming constructs, and then lets them just use it. It's clean, it's elegant, it's almost simple. It's a language that invites the user to just go with it.

For some, though, there's that sense of curiosity... what is my Ruby program really doing? How can I see what the system is actually doing with my code? What's going on underneath the hood? If such explorations interest you, then "Ruby Under a Microscope" by Pat Shaughnessy tackles that subject handily.

A word of warning going in. This is not a general language book. You will not learn much about programming in Ruby here. You should have a decent understanding of what Ruby syntax looks like and how it works. Having said that, you don't need to have years of experience with Ruby to appreciate this book for what it does. It takes some key areas of the language, and through examples, some small programs, and a variety of tools, lets you see and understand what Ruby actually looks like up close and personal.

Chapter 1 focuses on how Ruby understand the text that you type into your Ruby program. Ruby converts your source code first into tokens, and then converts that input stream into an "abstract syntax tree”. Through tools like “Ripper”, you can see this process and watch it in something resembling natural language (well, kind of.
Read more ›
Comment | 
Was this review helpful to you?
Most Helpful Customer Reviews on Amazon.com (beta)
Amazon.com: 4.9 out of 5 stars  9 reviews
12 of 12 people found the following review helpful
5.0 out of 5 stars A technical deep dive that remains fun and enjoyable 17 Nov 2013
By Federico Lucifredi - Published on Amazon.com
Format:Paperback
Ruby Under a Microscope is a remarkable dissection of the internals of Ruby's runtime environment. Definitely too much for the casual user, but an absolute must for the power user - the dissection of how hash tables work in Ruby "under the hood" is worth the book in of itself. Coverage of the innards of the runtime's garbage collection process is equally useful.

The experiments the author carries out throughout the book to show the language's behavior, or to measure performance, are not only great explanation of how things operate, they are entertaining to read - at least for those with a performance tuning eye or a desire to really understand what is going on. I love it, I have seen this done in class, I have done it myself, but it is a teaching model rarely seen in writing that fits this technically deep subject very well.

Fans of lisp will appreciate the credit that the author gives the venerable language for closures and for McCarthy's garbage collection algorithm, among other things.

The book is richly illustrated, and the diagrams help a great deal in following the details being discussed - as you can imagine, pointers^Hreferences are everywhere, and diagrams really make decoding the lay of the land much easier.

A minor negative, looks like No Starch used a lighter paper choice than their regular, thick heavy paper - a fancy attribute of their books that I have come to look forward to. I would expect this was done to limit the heft of this particular tome, that at 330-plus pages would have come out rather thick in the usual paper choice.
7 of 8 people found the following review helpful
5.0 out of 5 stars Very approachable look at Ruby language implementation 22 Nov 2013
By IADev - Published on Amazon.com
Format:Paperback
This book is not for learning Ruby syntax or about building websites. Instead, it focuses on how Ruby does work under the covers. Explanations use diagrams and are clear overall. While the author does point out C files and some C code, understanding of the material does not depend on C knowledge as noted in the introduction. In my opinion, this is a great work for those trying to bridge the gap between using a programming language and really starting to think about how it works. I would say that the best audience for the book would be those who have some interest in compiler or language design. If you have already focused on such areas in formal course work, you probably won't come across as an in-depth theory approach, in my opinion, in this material (for example if you have the "Dragon Book" sitting on your reference shelf). However, the treatment is very approachable for the interested casual learner to pick up and understand subjects like tokenization and parsing and leave one with a solid foundation. The first 9 chapters focus on CRuby but chapters are also included on JRuby and Rubinius. I appreciated the author's use of "Experiments" such as showing how to use Ripper and RubyVM::InstructionSequence from your own Ruby programs. It's one thing to be able to see an example of YARV instructions for a canned book example but it is even more powerful to have the tools to get the output of your own custom scripts and modifications.

Overall conclusion: Very approachable look at Ruby language implementation. Having been interested in compliers, I found this a great introduction into this specific CS topic. It was also nice to see the book use a real language for the examples. I found the book unlike any other programming book I had read on Ruby and enjoyed the practical look under the hood of Ruby.

Disclaimer: I got a copy of this book for review as part of O'Reilly blogger program.
3 of 3 people found the following review helpful
5.0 out of 5 stars Relevant and mandatory - Akin to K&R's 'C' reference, or Windows Internals for the Windows OS for the Ruby developer 5 Jan 2014
By Richard T. Kingslan - Published on Amazon.com
Format:Paperback
Ruby has become a major player in application and (by extension) Web development due to the easy to acquire skills to use the language, the expansive library sets due to the open source nature and the integration and support on nearly any platform.

Me, being a Windows OS guy, I look to major references like Microsoft Press’ “Windows Internals” to understand how things really work – not just at the surface – but why something does what it does. For example, if the distributed processing calls (DPC) result in interrupts consuming the processor, I know I’m usually looking at a driver or hardware problem.

“Ruby – Under a Microscope” is much like “Windows Internals” in that the how and why of Ruby is revealed.

What should be clear from the idea of an in-depth, deep technical details book – this isn’t for the beginner, like Microsoft Press’ “Windows Internals” isn’t for the newbie Windows OS user. If you don’t know what DPCs are and what they do – knowledge of DPCs is pretty much useless. To get the full value from this book, you should already be an experienced Ruby programmer (or have depth in similar languages). What the experienced developer will get from this book is the details that will allow them to extract more power from Ruby, better understanding of why things happen, and how to better use Ruby to solve the really hard problems.

Now that we’re past the “who this book is for” part, there is one more thing to understand before you decide that this is of value to you: Exactly WHICH Ruby are we talking about? Yes, Ruby is available on nearly all platforms. However, this is because some hard working people wanted to make sure that the language was widely available, and these hard working people made it available on platforms other than what the original Ruby was developed for.

So, how do you know which version of Ruby this book is focused on? The book is focused on the Matz (Yukihiro “Matz” Matsumoto) Ruby Interpreter, written in C. Other implementations are discussed, and these are discussed in the context of how others implemented the language that Matz created in 1993.

The book treats Ruby as a science study, much like a scientist would study microbes (“…Under a Microscope”, get it?). Instead of looking at organisms, the book looks at the base elements of Ruby: The actual ‘C’ source code. If you’re a computer science major, this is nothing new. The source code is studied to understand what Ruby does to perform the tasks that you give it. As you go through the book and look at Ruby at the very base elements, you can gain a complete understanding of how computers really work. There is nothing more basic than the process of providing information to a computing machine and seeing how the actual process of creating tokens, parsing of tokens, compiling into an intermediate format, and then passing onto the virtual machine (YARV – Yet Another Ruby Virtual Machine) that interfaces at the machine level. Once the processing is complete, understanding how to receive the output, convert it back into something that the programming language can understand is absolutely vital to knowing why things work. And, probably most importantly, knowing what’s wrong when they don’t work.

This is the real goal of “Ruby: Under a Microscope”. Providing understandable information for the knowledgeable programmer to gain a deep understanding of what Ruby is, what it does, and how it attains the goals that it sets for itself. This opens the door wide open for those that want to add to the language with libraries and extensions – which is the real power of a successful language: Expansion by anyone with a great idea.
1 of 1 people found the following review helpful
5.0 out of 5 stars The title alone was enough to get my attention. What a great idea to write a book the way Pat Shaughnessy did. I loved it. 25 Feb 2014
By S. W. Y. Zegveld - Published on Amazon.com
Format:Paperback
The title alone was enough to get my attention. What a great idea to write a book the way Pat Shaughnessy did. I loved it. I am not a real expert on Ruby (yet) but I really enjoyed the different approach to learning the internals behind Ruby.
When you are looking for a good book about Ruby, but are afraid to learn Ruby internals because it might be too hard/difficult, this is the book for you. The book is not a good idea for people looking for a book to learn Ruby from scratch. The book is divided into 12 chapters with each chapter having a couple of experiment sections where you are guided to learning how Ruby does what it does.
To give you some idea what you can find in this book I will give you some keywords: MRI, hashtable, modules, JRuby, Rubinus.
I read this book from start to finish and I must say that it was really worth it! What a lovely book, wish more people would write heavy technical books this way, then these difficult to understand topics would become a lot easier to understand. I did know already a bit about Ruby but this book made all more clear and easier to understand why and how it works behind the scenes of Ruby.
1 of 1 people found the following review helpful
5.0 out of 5 stars See the wiring under the board 12 Feb 2014
By Michael Larsen - Published on Amazon.com
Format:Kindle Edition
Let's start with a disclaimer. I'm not a Computer Science major, nor did I complete a Computer Science course of study in school. I'm a software tester, and one that finds themselves frequently using programming languages of various stripes for various purposes. Ruby is one of the most popular languages in current use, and for many, it's a language that allows them to learn some basic terms, some programming constructs, and then lets them just use it. It's clean, it's elegant, it's almost simple. It's a language that invites the user to just go with it.

For some, though, there's that sense of curiosity... what is my Ruby program really doing? How can I see what the system is actually doing with my code? What's going on underneath the hood? If such explorations interest you, then "Ruby Under a Microscope" by Pat Shaughnessy tackles that subject handily.

A word of warning going in. This is not a general language book. You will not learn much about programming in Ruby here. You should have a decent understanding of what Ruby syntax looks like and how it works. Having said that, you don't need to have years of experience with Ruby to appreciate this book for what it does. It takes some key areas of the language, and through examples, some small programs, and a variety of tools, lets you see and understand what Ruby actually looks like up close and personal.

Chapter 1 focuses on how Ruby understand the text that you type into your Ruby program. Ruby converts your source code first into tokens, and then converts that input stream into an "abstract syntax tree”. Through tools like “Ripper”, you can see this process and watch it in something resembling natural language (well, kind of. It’s still debug code, but it’s a lot less intimidating than one might think.

Chapter 2 covers how Ruby compiles code. Wait, isn’t Ruby a “scripting language, no compiler required? With 1.8 and earlier, yes, but with 1.9 and up, Ruby is compiled just like many other languages we are familiar with. The difference? Ruby does it automatically. You never need to invoke the compiler. Ruby also has its own “virtual machine” (YARV, or "Yet Another Ruby Virtual Machine) that it compiles its bytecode for. Ultimately, the byte code for YARV is what we witness running.

Chapter 3 goes into greater detail about how YARV runs our code. By comparing the steps necessary to run a simple program, we can compare the time it takes to run a program in Ruby 1.8 (which doesn’t have a compile sequence, it just runs) and Ruby 1.9 and 2.0, which do have compile sequences. For simple and brief interactions, it actually looks like Ruby 1.8 performs better, but for longer runs with more iterations, 1.9 and 2.0 have a huge advantage over 1.8 by virtue of its compile cycle.

Chapter 4 focuses more attention on the virtual machine and how control structures and methods are handled within the YARV. If statements, for loops and calls to various methods demonstrate how ruby breaks down the instructions, as well as how it utilizes its internal calls to “jump” from one piece of code to another. Ruby categorizes methods into 11 types, and labels its built-in methods as CFUNC methods, meaning they are implemented in C. Ruby also uses a hash to keep track of the number of arguments, her labels and what their default values should be.

Chapter 5 looks at objects and classes, specifically, Ruby’s internal objects and classes. Each Ruby object is, ultimately, a class pointer paired with an array of instance variables, and everything in Ruby is an object. Several generic objects are shown, along with their C structures (RString, RArray, RRegexp, etc.), and demonstrate how they, likewise, are also simple combinations of a class pointer and instance variables. Classes are a little more involved. Each Ruby class can be defined as Ruby object (with its class pointer & instance variables) plus method definitions, attribute names, a constants table and a “superclass” pointer.

Chapter 6 brings us deeper into methods and constants, specifically how these aspects are found and represented. Ruby lets a programmer look at programs with two contrasting paradigms. Code can be organized through classes and super-classes, or it can be organized through "lexical scope". Which approach makes the most sense? it depends on what you want to have your program accomplish.

Chapter 7 gets into one of the key attributes of Ruby internals, the Hash Table. These are interesting data structures that allow a program to return values quickly, and to automatically increase in size as more elements are added. the chapter takes a deep dive into Ruby’s hash function and how it allows for elements to be accessed quickly.

Chapter 8 covers blocks, and how the Blocks concept in Ruby borrows from the “closure” idea first prosed in the Lisp language several decades back. Blocks can be defined as “a combination of a function and an environment to use when calling that function”. Using “lambda”, a block can become a data value that can be passed, saved, and reused.

Chapter 9 discusses Metaprogramming, a means to program in a way that code can inspect and change itself, dynamically. In other words, by referencing itself, your program can change itself! I’ll admit, this is one of the aspects of Ruby (or any language) that I have trouble getting my head around, and while I won’t claim to have mastery of these ideas after this chapter, I feel I have a little better feel for what’s happening.

Chapter 10 takes us into the Java realm and shows us Ruby implemented in Java, as opposed to how we’ve been interacting with it thus far in C. The flow is similar, but each Ruby script gets compiled into a Java executable, and then is physically run by the Java Virtual Machine. We see how “Jay” parses the lines of code (much the way Bison does for MRI). By monitoring Java’s Just In time Compiler, we can see which class and structures are called whenever we create a script and run it. We can also see where, by focusing on various “hot spots in our program and compiling them into Java, we can save time in key areas compared to C implemented MRI.

Chapter 11 introduces Rubinious, a version of Ruby implemented with Ruby. Well, it’s actually a virtual machine using C++ to run Ruby code. What makes it different is that, rather than relying on C or Java Structures for the built in classes, Rubinious does it with Ruby code. What does this mean? we can see how Ruby works internally without having to know C or Java. It’s all done in Ruby, and we can see how by reading the source code.

Chapter 12 explores Ruby’s Garbage Collection, and how it differs, and is similar, in MRI, JRuby and Rubinious. Garbage collection helps us with three processes; allocating memory for use by new objects, identifying which objects a program is no longer using, and reclaiming memory from unused objects. Various programs and examples demonstrate which objets are mapped where, and how to see when they are deallocated and their memory freed. Various algorithms for the various virtual machines are explored, but this is just a cursory overview of all the options and how they are implemented. Still, it’s an interesting view into a process that many of us take for granted because Ruby and many other languages basically let us take them for granted.

Bottom Line:

"Ruby Under a Microscope" does something fairly ambitious. It attempts to write a system internals book in a language that non computer scientists can readily understand. While there are numerous code snippets and examples to try and examine, the ability to look at the various Ruby internals and systems and see how they fit together can be accomplished by someone with general skills and basic familiarity with programming at the script level (which for many of us is as far as we typically get). An old saying says you can’t tell where yo hare going if you don’t know where you’ve been. Similarly, we can’t expect to get the most out of languages like ruby without having a more clear idea what’s happening under the hood. It’s entirely possible to work with Ruby and never learn some of this stuff, but having a guide like "Ruby Under a Microscope” opens up a variety of avenues, and does so in a way that will make the journey interesting and, dare I say it, even a little fun.
Were these reviews helpful?   Let us know
Search Customer Reviews
Only search this product's reviews

Customer Discussions

This product's forum
Discussion Replies Latest Post
No discussions yet

Ask questions, Share opinions, Gain insight
Start a new discussion
Topic:
First post:
Prompts for sign-in
 

Search Customer Discussions
Search all Amazon discussions
   


Look for similar items by category


Feedback