Slashdot Mirror


Programming Ruby: The Pragmatic Programmers' Guide

James Edward Gray II writes " Programming Ruby: The Pragmatic Programmers' Guide (Second Edition), known as the Pickaxe II to its fans, is an extremely current view of the Ruby programming language. Revised primarily by Dave Thomas, a founding father of the English Ruby community, Programming Ruby is distilled expertise from a reliable source. In the past, quality English documentation of Ruby has been in short supply, but if any one volume could solve that problem, this is it." Read on for the rest of Gray's review. Programming Ruby: The Pragmatic Programmers' Guide author Dave Thomas with Chad Fowler and Andy Hunt pages 830 publisher Pragmatic Bookshelf rating 9 reviewer James Edward Gray II ISBN 0974514055 summary The definitive source for all things Ruby.

If you're not familiar with it, Ruby is a very fun and elegant scripting language that has been described as "more powerful than Perl and more object oriented than Python." I won't start a language war by defending that statement, but I will tell you what makes Ruby very attractive to me: Extremely object oriented, super clean syntax, and a smooth blending of iterators and code blocks for straightforward, concise solutions. If that sounds like a language you would like to know more about, Programming Ruby is the book for you.

At 830 pages, this edition is considerably larger than the first. It represents an expansion on many topics originally covered, in addition to all new coverage on topics like unit testing, RDoc documentation for Ruby source code, and more. Better still, "Duck Typing," a topic central to Ruby philosophy, receives its own enlightening chapter. This volume covers the very latest release of the language, often highlighting new features and even giving tips for things to watch for in future versions.

Programming Ruby is divided into four distinct sections. "Part I - Facets of Ruby" is a tutorial on the Ruby Programming Language. It's very effective, but I probably better give a warning here: This book teaches you how to program in Ruby, not how to program. You likely won't feel comfortable, even in this tutorial section, unless you have some experience with other programming languages. As an example, Ruby is object oriented on a scale with languages like Smalltalk, so you'll need to know object oriented programming. This book makes no attempt to teach such concepts, excepting how they apply to Ruby. As long as you come with the proper background, this section will get you on your feet with Ruby in under 200 pages. It's very well thought out.

"Part II - Ruby in its Setting" is a mixed-bag tour on the many places Ruby sees use. Web programming, command-line hacking, using TK to build GUIs, and Windows programming are just some of the covered topics. Other chapters in here focus on elements unique to Ruby, like the earlier mentioned RDoc or "irb," the interactive Ruby shell. There's even a chapter in here on package management with RubyGems.

When you're ready, "Part III - Ruby Crystallized" will take you deep into the core of Ruby syntax and functionality. This section tells you all the details about how Ruby reads your code, and how it runs. I think few people could soak in all the tidbits in here in one scan. I've read it twice now and learned about as much both times. There's a lot of great Ruby knowledge waiting to be mined out of here.

Finally, "Part IV - Ruby Library Reference" is the best Ruby reference I've yet run across. It covers every class, module, method and constant in core Ruby. The descriptions for these entities tell you exactly what you need to know, the examples, though short, are inspiring, and the comments sneak in subtle hints that are more than useful. Following this, the book gives an overview of all Standard Libraries included with Ruby. This section really opened my eyes to the tools I've been missing out on simply because I didn't know they were there. Be warned: These Standard Library summaries won't teach you every feature available. They just tell you what they're for so you'll know where to look for the information you need. The last great feature in this section is a terrific index. I care about the index and a book that has a bad one will really bother me. Luckily, that couldn't be further from the truth here.

Programming Ruby isn't perfect, of course. Some of the chapters are not as thorough as you wish they could be, simply because of the amount of information that needs to be covered. The chapter on threads is probably the biggest example of this, but remember that entire volumes have been written on threading. Another minor point is that some of the examples are quite contrived. This bothers some people, but I don't feel it's too much trouble for the book's target audience. As I've said, you're expected to know how to program going into this book, just not how to program in Ruby.

Programming Ruby at least touches on most things central to the Ruby Programming Language, and goes into considerable detail more often than not. There's something for all levels here. You can learn Ruby from the tutorial, as I did with the first edition, but you'll keep coming back to the wonderful reference and to go deeper into specific areas of interest. That's a lot of great mileage for one book. I'm willing to bet most Ruby Gurus keep it in arm's reach, because Ruby wouldn't be half as much fun without it.

You can purchase Programming Ruby from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

59 of 231 comments (clear)

  1. First edition is available online. by Kenja · · Score: 5, Informative

    http://www.rubycentral.com/book/

    --

    "Have you ever thought about just turning off the TV, sitting down with your kids, and hitting them?"
    1. Re:First edition is available online. by Anonymous Coward · · Score: 4, Informative

      The 1st edition is very out-of-date. It's kinda like reading a Perl 4 book to learn Perl 5.8. But the author was generous to provide it for free and it is available in MANY formats online from PDF to Microsoft Help to HTML.

      I own the 2nd edition and am VERY happy with it except for the quality of paper. Reminds me of Java in a Nutshell because it quickly teaches the language and also provides a reference to keep on your desk. This is my first and only hardcopy Ruby book and I doubt I'll need another one for a few years.

      For those of you new to Ruby or just curious, here are some useful links:

      Ruby Home
      http://www.ruby-lang.org

      Ruby Forum (new! primarily for beginners)
      http://www.ruby-forum.org/bb/

      Ruby Online Docs
      http://www.ruby-doc.org

      Ruby Project Archives
      http://raa.ruby-lang.org
      http://rubyfor ge.org

      Ruby Package Manager (easy to install ruby apps)
      http://rubygems.rubyforge.org/wiki/wiki.pl

      Ruby IDE (free!)
      http://freeride.rubyforge.org/wiki/wiki.p l

      Ruby One-Click Installer for Windows
      http://rubyinstaller.rubyforge.org/wiki/w iki.pl

      Ruby IRC channel
      #ruby-lang at irc.openprojects.net

      Ruby Newsgroup
      news://comp.lang.ruby

      Ruby Links
      http://www.rubycentral.com/links/index.html
      http://dmoz.org/Computers/Programming/Languages/ Ru by/Software/

  2. About the Ruby Gems chapter... by tcopeland · · Score: 4, Insightful

    ...it was written twice. Chad Fowler wrote it the first time while he was on vacation in Europe. Then he had to rewrite it after his Powerbook was stolen on his trip home. Argh!

    More on Ruby Gems here.

    1. Re:About the Ruby Gems chapter... by chadfowler · · Score: 4, Funny

      In my own defense, I was backing it up...to a USB drive that also got stolen ;)

    2. Re:About the Ruby Gems chapter... by goldspider · · Score: 3, Funny

      After reading that, I think Ruby has a long way to go in terms of security.

      --
      "Ask not what your country can do for you." --John F. Kennedy
    3. Re:About the Ruby Gems chapter... by johndeeregator · · Score: 3, Funny

      I hope he learned a lesson about doing work while on vacation. Hell, most of us don't even do work while at work.

    4. Re:About the Ruby Gems chapter... by chadfowler · · Score: 2, Insightful

      But, if you're doing Ruby, it's not work ;)

  3. Ruby is great. by nullvector · · Score: 4, Insightful

    Ruby is like the glue that holds alot of my programs together.

    The first edition of this book came in really handy in college, when I'd have to find creative ways to do something (especially text manip), where C++ or Java just seemed to get in the way.

    Ruby is quick to learn, and Dave Thomas from Pragmatic is a great teacher...he came to my school for a little lecture/speech one day, and talked on the merits of Ruby, which is how I got introduced to it.

    The network aspects of Ruby are great too. Small concise ruby programs can do a whole lot :)

    1. Re:Ruby is great. by hoggoth · · Score: 4, Funny

      > The first edition of this book came in really handy in college

      Man, I feel old.
      For me, 'Programming Cyber 7600 Assembly' came in really handy in college.

      --
      - For the complete works of Shakespeare: cat /dev/random (may take some time)
    2. Re:Ruby is great. by nullvector · · Score: 2, Funny

      The nice thing about computer engineering, though, is that I took a look at quite a few of those old assembly books as well :) The Motorola 68HC11 book was a well-worn part of my arsenal also.

  4. Given all the gem analogies... by grunt107 · · Score: 4, Funny

    Why didn't reviewer say 'Brilliant, but slightly flawed'.

    1. Re:Given all the gem analogies... by GMFTatsujin · · Score: 4, Funny

      Put three copies of it into your Horadric Cube ... that'll upgrade it from "flawed book" to just "book."

      Anyone want to do the math on making a perfect book?

  5. Goodbye Ruby Tuesday by Timesprout · · Score: 3, Funny


    Who could hang a name on you

    Oh come on someone had to do it.

    --
    Do not try to read the dupe, thats impossible. Instead, only try to realize the truth
    What truth?
    There is no dupe
  6. It's got to better than... by foistboinder · · Score: 2, Funny

    The non-Pragmatic Programmers' Guide

  7. RubyConf 04 was held recently.... by tcopeland · · Score: 3, Informative

    ...thanks to Ruby Central for sponsoring it.

    A BitTorrent of the presentations is available here.

    1. Re:RubyConf 04 was held recently.... by chadfowler · · Score: 2, Informative

      Thanks Tom. It's actually http://rubycentral.org.

    2. Re:RubyConf 04 was held recently.... by tcopeland · · Score: 2, Informative

      Curses... thanks. Would that there was a post editing capability... ah well. Retry:

      Thanks to Ruby Central for sponsoring RubyConf 2004!

  8. Re:pickaxe? by Rich_Kilmer · · Score: 5, Informative

    It comes from the pick and axe on the front cover of the book :-)

  9. Eager to have this book by rolling_bits · · Score: 4, Informative

    Many of us, Rubyists, have been introduced to Ruby by the very first version of this book. And the first version is online and is still handy for consulting:
    http://www.ruby-doc.org/find/pickaxe

    But this new version covers all the changes from Ruby 1.6 to Ruby 1.8; making this book a must have.

    As far as I know, it's available as PDF and as paper, and I'm gonna have both.

    Thanks Dave for helping the occident know Ruby and Matz for creating the must inspiring language for me.

    Cheers!

  10. Too many new languages at once... by Doesn't_Comment_Code · · Score: 2, Interesting

    I have to admit I've never tried Ruby. I use C++, Perl and PHP all the time. I just got started learning Python because of a book review I saw here on Slashdot. In fact, I also got interested in Python because someone suggested I use it to solve a problem that needs extensive parsing (Perl strength, nightmare in C++) and large, pointer-addressable arrays of objects(C++ strength, Perl weakness).

    Anyway, I was told Python was a good compromise. I've just started into it, but maybe Ruby is a better fit for this problem? I can only learn so many languages at once, and still have time for my projects.

    Can I get any advice? Is Ruby really "more powerful than Perl and more object oriented than Python" - is this what I'm looking for, or should I put it off and learn Python first?

    --

    Slashdot Syndrome: the sudden, extreme urge to correct someone in order to validate one's self.
    1. Re:Too many new languages at once... by tcopeland · · Score: 4, Informative

      > Ruby is a better fit for this problem?

      There's a good C2 Wiki page on this - PythonVsRuby.

    2. Re:Too many new languages at once... by jonastullus · · Score: 2, Informative

      at the risk of being totally flamed by all the ruby followers out there:

      i have for quite some time now been programming in python and it just works like a CHARM!!
      i used to be so proud of my perl skills, but at some point i just felt dirty using perl and once i had started with python there DEFINITELY was no turning back! (well, maybe for a few-line regexp script...)

      from what i have gathered about ruby, the distinction between ruby and python is really slight! the syntax of ruby is VERY similar to that of python and python's object orientation is really decent.
      so in case you have already started into python i wouldn't swap for ruby, but as i said, the difference seems rather marginal to me, so it doesn't make that much of a difference.

    3. Re:Too many new languages at once... by cmowire · · Score: 4, Interesting

      No, there is a difference. It's a mistaken notion that Ruby is like Python meets Perl.

      It's more like Smalltalk + Regular Expression + Incidental Other Goodies + Culture.

      I've tried both, and I like Ruby far more than Python. Ruby is an incredible language that tends to enable really simple, yet sophisticated code. When people talk about the Ruby Way, they aren't kidding. Ruby is endearing to me in ways that Python never was.

      Ruby and Python are both drinking from the smalltalk fountain, but they are still very different. Ruby plows head-on into more functional-programming types of paradigms while still using objects.

    4. Re:Too many new languages at once... by CatGrep · · Score: 4, Insightful

      Can I get any advice? Is Ruby really "more powerful than Perl

      That's really difficult to quantify. How do you define 'more powerful'?

      Personally, I prefer Ruby's clean syntax to Perl's (especially when compared to OO programming in Perl, which is just a disaster from an aesthetic viewpoint, as well as the amount of work that is required from the Perl programmer to do OO). There are a few features that Ruby has that Perl doesn't: continuations, code blocks and exceptions.

      and more object oriented than Python" - is this what I'm looking for, or should I put it off and learn Python first?

      This tends to be an area where there is a lot of dispute between the two camps. I've already revealed my bias toward Ruby, so take that into consideration regarding the following comments: In Python I get the feeling that object orientation was tacked on. Granted it was tacked on much earlier in the language's development than it was in Perl where OO programming is essentially a do-it-yourself project. There are a couple of nagging issues in Python which give me this idea:
      1) why do I need to include 'self' as the first parameter of each method definition?
      2) In Python people tend to prefer, for example, to find the length of an array by saying:
      length( array ) instead of array.length (the latter being the way you would do it in Ruby). Of course Pythonistas are now screaming that you can also say: array.__length__ (or something similar) in Python as well.

      Python now also has something similar to Ruby's iterators (though they're a bit different), but something to keep in mind is that Ruby's standard libraries and built-in classes were built from the ground up with iterators in mind - I think that's a big advantage that Ruby has over Python.

      I suggest that you try to write a smallish program in each language (pick a project that might take an hour or two) and see how each language 'fits' with the way you think. I find Ruby fits my way of thinking much better than Python does, but as they say, YMMV.

    5. Re:Too many new languages at once... by fredrikj · · Score: 2, Informative
      It is not true that Python is "half-OO", at least by the merit of your argument. Finding the length of an object is done by calling a method:
      >>>"bla".__len__()
      3
      >>>class Foo:
      ... def __len__(self): return 5
      >>> Foo().__len__()
      5
      You can also do len(Foo()) or len("bla"), and although I agree that the existence of this legacy function makes the language less consistent I fail to see how it makes it any less OO.
    6. Re:Too many new languages at once... by rolling_bits · · Score: 2, Insightful

      Yes, you could keep punching cards or writing asssembler. Or maybe, write C or Java. Or... You could use Ruby and build your programs and libraries in a special way, that makes them concise and much more maintenable. That way instead of creating one program per year, you could create one per week, and keep improving them as needed. You are not free from creating your own libraries, though. You are even encouraged to. And it's much easier to create a library in Ruby than in other languages. The payoff is that *you* will have the library *soon*. I could say that in other languages either you find a library to do what you want, or you are sold. With Ruby, you don't even think. You create the library right away. Though we don't need to write all the libraries necessary for our programs, because I think that Ruby has advanced from being used by early adopters to being used by application developers. See this article by Eric Sink, for example: http://software.ericsink.com/Act_Your_Age.html Cheers!

    7. Re:Too many new languages at once... by baka_boy · · Score: 3, Informative

      Ruby has first-class functions; you just have to disambiguate them syntactically, since bare property access (like foo.bar) is actually calling method bar on the object foo. So, if you want to reference the method explicitly, you have to write foo.method(:foo), which returns a Method instance which can be invoked or used like any other scalar value.

      So, while in Python, you might write something like this:
      controller.set_handler('some_action', myObject.handle_some_action)
      ...the Ruby idiom would be one of the following:
      controller.set_handler('some_action', myObject.method(:handle_some_action))

      -or-
      controller.set_handler('some_action') { myObject.handle_some_action }

      The extra method(...) syntax is needed to ensure that all communication between objects is via method calls, rather than direct property access. Python allows you to directly assign to and read from object attributes, much like public members in C++ or Java classes. Ruby forces all attribute access to be wrapped in get/set methods, but provides a lot of support to make implementing those methods effectively automatic.

      The latter example also uses a code block, cover many cases where first-class functions would be otherwise -- they're basically a compact syntax for lambda expressions, and prevent you from needed sugar like list comprehensions in most situations.

      For example, instead of the following Python list comprehension:
      [x*2 for x in myArrayOfValues if x % 3 == 0]

      ...you would use this:
      myArrayOfValues.map {|x| x*2}.find_all {|x| x % 3 == 0}

      Blocks are also a general idiom used throughout the standard library and most Ruby code in the wild. You can use them to write callbacks, query databases, and even to build domain-specific languages (another traditional stronghold of functional languages).

      Really, though, neither Ruby or Python is a truly functional language; both borrow from the more "academic" languages those features and concepts they find useful, and leave behind those that the maintainers and users don't want, need, or understand. (Except for continuations, of course -- Ruby has those, and I would guess that only a very small percentage of Ruby coders ever grok them.)

    8. Re:Too many new languages at once... by fredrikj · · Score: 2, Informative
      1) why do I need to include 'self' as the first parameter of each method definition?
      It's nicer for unbound methods, and makes calls to superclass methods clearer. This is also answered in the Python FAQ.

      2) In Python people tend to prefer, for example, to find the length of an array by saying:
      length( array ) instead of array.length (the latter being the way you would do it in Ruby). Of course Pythonistas are now screaming that you can also say: array.__length__ (or something similar) in Python as well.
      See my previous post in this thread. I agree that this is something of a wart, but a minor one.

      As for Ruby vs. Python, I don't think it's a big deal as they are similar in many ways. If you're comfortable with either language, there's probably no need to switch to the other. Myself, I don't think the higher level of consistency in Ruby's object system offers any practical advantage, and find Python's syntax much nicer. Haven't seen anything particularly interesting in Ruby that isn't also in Python.

      Indeed, if I had discovered Ruby before Python, it's quite possible that I would've stuck to that instead.
    9. Re:Too many new languages at once... by MetalNoise · · Score: 2, Insightful

      I know both languages, although I know Python better. I first learned Ruby and then switched to Python. In many ways I think both languages fit the same niche. They both make many tasks easier and you really can't go wrong with either. If you started with Python I would stick with it. You'll never regret knowing Python well. For me, Python offered 1) more bindings to existing "C" libraries. 2) a bigger community with more support. Ruby is pretty decent in both 1) and 2) also, just not as far along (I'm about 2 yrs out of the loop though). In many ways the languages are similar. Some major differences are: Python: list comprehensions, generators. Ruby: blocks, cleaner OO, more complete closures, continuations. By the way, both languages helped me realize that you can do many things easier and cleaner without OO techniques. Both languages have a bit of a functional side to them and I find this to be one of their stronger attributes.

    10. Re:Too many new languages at once... by xteddy · · Score: 3, Interesting
      You don't have list comprehensions in SML. Last time I checked, this was still a functional language.
      The comp.lang.functional FAQ says
      Functional programming is a style of programming that emphasizes the evaluation of expressions, rather than execution of commands. The expressions in these language are formed by using functions to combine basic values. A functional language is a language that supports and encourages programming in a functional style.
      Actually Ruby only has expressions, so it seems to be a pretty good candidate. You can also create functional objects and use them as arguments:
      def add(x, y) x + y end

      (1..10).inject &method(:add) # => 55
      The same in Common LISP, also a functional programming language:
      (defun add(x y) (+ x y))

      (reduce #'add (list 1 2 3 4 5 6 7 8 9 10)) ; => 55
      Doesn't look so different, does it?
    11. Re:Too many new languages at once... by cmowire · · Score: 2, Informative

      Notice I said "functional-programming types of paradigms", not functional programming.

      It does have first-class functions (the Proc class) it's just that the syntax is driven towards making closures accessible instead of functions and creating Procs is a lot more involved.

      On the other hand, what they do with the closures (a.k.a. Code Blocks) is quite amazing on its own merits. The concept of being able to iterate over arbitrary stuff in a variety of ways with them comes in quite handy, plus all of the other ways to make the language easier to deal with.

      And, then of course, there's the functional library. ;)

    12. Re:Too many new languages at once... by Jerf · · Score: 2, Informative
      There are a couple of nagging issues in Python which give me this idea:

      Here's how I think people should evaluate Python vs. Ruby:
      1. Run Python, downloading it if necessary.
      2. Run a Python shell (OS-dependent).
      3. Type "import this", and read it.
      If everything speaks to you, as it does me, than try Python first. Otherwise, try Ruby. I'll leave a Ruby-ist to explain the exact differences.

      I can give a couple of the differences, though; mostly, the differences between the languages and capabilities are philosophical. Ruby has more "purity", Python says "Although practicality beats purity." (although with a strong cultural understanding that purity isn't worth tossing away as Perl seems to). Python also thinks "Readability counts.", Ruby seems more interested in making the syntax always concise. I'd much rather read a Ruby program than a C++ program, but the Python one will look more like pseudo-code with real English words, and Ruby will have a bit more syntax. Python has no culture of saving keystrokes and such things are usually considered a joke when the topic comes up, as are various language comparision benchmarks that incorporate that as a measure. (Typing speed is very, very rarely the constraint on programming speed.)

      Which is right? Well, it mostly depends on what you want.
    13. Re:Too many new languages at once... by xteddy · · Score: 2, Insightful

      Following this logic and given there were enough libraries for brainfuck available, we could program everything in brainfuck as well?

  11. Re:Web programming by Luk+Fugl · · Score: 4, Informative
    The review mentioned web programming, does one need a specific platform installed or it "just runs"?

    I'm not sure what you mean by platform or "just runs". If you mean, do you need a certain OS? No. Do you need Apache in particular? No, though Apache and Ruby work very well together. Do you need any external web server? No. One of the standard libraries that comes with Ruby is WEBrick, which is a standalone webserver. You can get Ruby running web apps using WEBrick on any OS, no other software required.

    Along those lines, let me throw in a quick plug for Ruby on Rails. Rails makes web application using the MVC model very quick and easy. The default setup includes a WEBrick servlet so you can have your application listening for requests minutes after installation, literally.

    Visit #ruby-lang and #rubyonrails on freenode for more information about Ruby in general or Rails.

    Jacob Fugal

  12. Note that the Ruby standard library docs... by tcopeland · · Score: 2, Informative

    ...are also available on ruby-doc.org here.

  13. Re:What demand is there for RUBY in the workplace? by Rich_Kilmer · · Score: 3, Interesting

    We have built an extremely robust distributed testing framework for a Java-based multi-agent system completely implemented in Ruby (see Cougaar for more on the project and the ACME testing framework). We were told on starting this project (at DARPA) that it would never work...I really like proving people wrong ;-) My company is using its Ruby expertise as a differentiator in the market and getting very good reception.

  14. Poignant vs Pragmatic by weston · · Score: 4, Informative

    Why's Poignant Guide to Ruby has got to be the most entertaining Ruby read out there....

  15. Ruby + C == World Domination by Anonymous Coward · · Score: 2, Insightful

    Well not exaclty, but the combination of Ruby and C is unbelievably powerful.
    A graceful and dynamic OO language coupled with, well C - fast, portable (more or less) and used everywhere.
    Because it is so easy to go back and forth between Ruby and C you get the strengths of both languages (also all those C libraries out there).

    If you haven't used Ruby, your missing out to say the least - and this book is an excelent way to get started.

    1. Re:Ruby + C == World Domination by CatGrep · · Score: 2, Interesting

      mod the parent up!

      Ruby isn't the fastest language on the block, but it's so easy to write C extensions for a Ruby program. Usually only about 10 to 20% of your code is speed critical, so this allows you to write that small part of your code which is speed critical in C while writing the rest of your code more quickly in Ruby. Oh and there's a profiling module that comes with Ruby that will help you figure out where your code is spending it's time.

      I would also add that if you use Swig, it's quite easy to integrate your Ruby code with your C++ code. I tend to prototype in Ruby to get my design squared away, then I translate methods to C++ while all along using the same unit tests written in Ruby to make sure that everything is still functioning the way I intended.

  16. Dave Thomas by dfn5 · · Score: 2, Funny
    a founding father of the English Ruby community...

    ... and hamburgers

    --
    -- Thou hast strayed far from the path of the Avatar.
  17. Ruby and Perl over Python for cross-platform dev by Dystopian+Rebel · · Score: 5, Insightful

    I can live with Python's having no statement terminator (";" in C, C++, Perl, Java).

    What I find unacceptable in Python is that whitespace (tabs) determine the logical flow. I once wrote a script on Windows and moved it to UNIX; the UNIX editor handled tabs differently, and my script wouldn't work without a few hours of attention just to set the spacing right.

    Ruby has Pascal-like blocking. That alone makes it superior to Python. And for all other situations that do not require a good OO implementation, there is Perl.

    --
    Rich And Stupid is not so bad as Working For Rich And Stupid.
  18. Great book, great language by CatGrep · · Score: 2, Insightful

    I got my copy a couple of weeks ago. It's a great followup to the first edition - much more information. I've already learned new things from it even though I've been programming in Ruby over 3 years now.

    I also think that the philosophy espoused in the chapter on 'Duck Typing' could apply to other agile languages like Smalltalk and Python. I haven't really seen these ideas come out as strongly in other language communities as they have in the Ruby community.

    I don't think there is any one thing about Ruby that's truly revolutionary, but the combination of features (code blocks, very consistent and complete standard libraries, OO'ness, etc.) make it very compelling. Do yourself a favor and buy the book - learning Ruby can help you think differently about how you approach problem solving in your day-to-day programming work (even if you don't program in Ruby for pay).

  19. Re:Good/bad points by PragDave · · Score: 3, Informative

    Could you give some examples? I'd love to fix stuff. if it's broken.

    Why not e-mail me directly as well as posting here: dave pragprog.com

    Cheers

    Dave

  20. Re:What demand is there for RUBY in the workplace? by CatGrep · · Score: 2, Informative

    These Guys just hired about 4 Ruby programmers to work with Rails (a Ruby-based web application framework that uses an MVC model that's generating a lot of interest in Ruby)

    I suspect that you'll see more small shops using Rails (and thus Ruby) in the coming months.

  21. Comment removed by account_deleted · · Score: 2, Informative

    Comment removed based on user account deletion

  22. Language selection parameters by Mr_Icon · · Score: 4, Insightful

    There are several kinds of programmers, at least when it comes to the language selection:

    • The Hardcore Kind: Everything must be written in something as low-level as possible, meaning C, but only if you absolutely cannot do ASM.
    • The I'm Special Kind: I am going to pick a language that is not commonly used, because having an obscure preference in programming languages makes me feel special. To justify my preference, I am going to learn a few facts that make this language marginally better than a similar language $FOO, ignoring all other advantages of $FOO.
    • The Hammer-Happy Kind: I know one language and I will use it whether it makes sense or not

    The first kind gives us applications that cannot be easily ported to other OSes or platforms, because everything is so low-level that it is tied to the underlying architecture. The second kind gives us duplicated effort and software that becomes unmantained whenever the main developer quits, since few other programmers know the language in which the project is written. The third kind gives us solutions that make sane people scream, like shell scripts that start with #!/usr/bin/php -q.

    It's fun to learn other programming languages, and contribute to the development of new ones, but in the open-source environment it is also very important to remember that you a) do not and should not work in a vacuum, b) that there are freaks who will probably try to run your software on bizarre setups, and c) that there is always a chance that circumstances will require that you quit working on that project.

    This is the reason why when picking a development environment for a project it is important to consider things like portability, maintainability, and suitability for the purpose. I'm not sure I can justify writing something in Ruby at this point, seeing as its adoption is far below Python, while its advantages over Python are slim to questionable.

    --
    If you open yourself to the foo, You and foo become one.
    1. Re:Language selection parameters by shirai · · Score: 2, Insightful

      I use language zealotry as a clue-factor. Anybody who says "A" is better than "B" with strong conviction and no caveats, tells me how much they know about programming.

      Great developers know two rules that keep them happy:

      1. Choose the best tool for the job

      2. Given that, know that the best tool is not always the best choice (e.g. everybody in your company knows Java but you want to write in PHP)

      And I suppose even before all of this is, learn at least a few languages. It will give you the clue factor that each language does indeed have its strengths and its weaknesses.

      --
      Sunny

      Be my Friend

    2. Re:Language selection parameters by Anonymous Coward · · Score: 2, Insightful

      You know, there are some people who actually enjoy programming, and enjoy the aesthetics of different languages. Some of us are interested in obscure languages because they represent a different way of thinking about programming, algorithms, and other such issues. It's not about "feeling special", it's about enjoying a particular language on its own merits.

      If everyone adopted the perspective you seem to present, people would only be interested in math because of what it can do, not what it is.

  23. awesome book, awesome language by Anonymous Coward · · Score: 5, Informative
    I've been using Ruby since I read about it in DDJ a while back.

    What really struck me about Ruby is how it "solved" many of the issues that had been bugging me about other languages (and I've used a bunch). Such as:

    * In many languages, a built-in method will either mutate an object "in-place", or it will work on a copy of the object and return that, leaving the original untouched. Sometimes pretty arbitrarily. But in Ruby, there's a convention like in Scheme (and maybe others): methods ending in "!", like "array.sort!" will sort the array in-place, and the other methods return a new sorted copy. Nice! One annoying issue solved.

    And booleans end in "?" which is nice too. instead of "is_foo" you write "foo?".

    * In many languages, you can have fields on objects, and you can have methods. So when you have "attributes" (like "first_name", "last_name" on a customer object), do you use fields which are simple and straightforward with natural syntax:

    object.first_name = "Joe"

    or do you use methods, which can be refactored:

    object.setFirstName("Joe")

    So, do you go for the awkward syntax, keep the fields private, and allow refactoring? Or do you expose the field, and rewrite all the code later when the requirements say "name must default to 'Anonymous Coward' when no name set"? Or do you convolute your code around the issue?

    Ruby solves this elegantly. There are NO PUBLIC FIELDS! Instead, you always use methods:
    # setter
    def first_name=(f)
    @first_name = f
    end

    # getter
    def first_name
    @first_name
    end

    object.first_name = "Joe"
    And no goofy "set_first_name" .. it's UNIFORM ACCESS. Beautiful! Now when the anonymous coward requirement comes in, just rewrite:
    def first_name
    @first_name || "Anonymous"
    end
    No client code has to be changed. And "first_name = 'joe'" still works.

    AND you don't even have to create the basic getter/setters! Ruby classes have a built-in class method that creates them dynamically:
    class Customer
    attr_accessor :first_name, :last_name
    end
    Very elegant! Well-written programs are very clean and light.

    * No need to use exceptions for non-local flow control.

    Ruby has exceptions, but sometimes you want to jump out of a deep tree search (for instance), and an exception is what you need: "raise SearchFinishedException" or something like that.

    But is that a good idea? Using "exceptions" for flow control? No because exceptions are, well, *exceptional*, they don't occur normally.

    Ruby helps me here too. It has catch()/throw() which is a simple alternative to exceptions, designed for nonlocal flow control. And of course you can write your *OWN* flow control because it has continuations (encapsulate program flow into an object for later return).

    Anyway Ruby is such an amazingly elegant language, and the pickaxe book is the appropriate companion! Buy a copy now, even if you don't use Ruby, it's very clear and easy to read (not just because of the language, but because of the enthusiastic and talented authors).
    1. Re:awesome book, awesome language by OmniVector · · Score: 2, Informative
      one of my favorite featuers of ruby is the ability to dynamically modify built in data types at runtime. say, for example, i want to add a pretty format method to hashes. i just type:
      class Hash
      def format
      data = self.keys.collect do |key| key = "#{key} => #{self[key]}" end
      "{ #{data.join( ', ' )} }"
      end
      end

      now i can make a hash and print it just by saying:
      hash1 = { 1 => "one", 2 => "two", 3 => "three" }
      puts hash1.format
      which outputs
      { 1 => "one", 2 => "two", 3 => "three" }


      i don't know of any OOP language that has an ability that powerful.
      --
      - tristan
  24. ruby documentation by pizza_milkshake · · Score: 4, Informative
    one thing that really hurts ruby is that it's documentation is sparse. i used to be a big ruby fan, but documentation has not kept up with its releases. whereas i think ruby is a very nice language, languages like perl, php and python have much more complete docs, and it makes the difference between 30 seconds to figure out the right function/method and digging around 15 minutes through out-of-date docs and finally going in and reading the source code.

    i own the first edition, it's a good tutorial-type ruby book

  25. Re:Syntactically significant whitespace by dozer · · Score: 4, Interesting

    Ever notice that there's tons of Perl, PHP, and Ruby snippents all over the web but very few Python snippets? It's because you really can't copy Python from the browser and paste it into a text editor! The whitespace gets changed and the program breaks in very hard-to-diagnose ways. It's rather funny.

    There are many features of Python that will be adopted by future languages, but I doubt that significant whitespace is among them.

  26. Re:Ruby and Perl over Python for cross-platform de by prockcore · · Score: 2, Interesting

    What I find unacceptable in Python is that whitespace (tabs) determine the logical flow.

    It also means you cannot take advantage of the auto-indenting feature of editors.

    If I need to go back and wrap a chunk of code in an "if" statement, I can put a { at the beginning and a } at the end and the editor will correct the indenting.

    Python will require me to go line by line and insert spaces or tabs.

  27. Re:Good/bad points by PragDave · · Score: 2, Informative

    Please drop me an e-mail (dave pragprog.com) and let me have them: I'll fix up any you find.

    Cheers

    Dave

  28. Re:What demand is there for RUBY in the workplace? by Phrogz · · Score: 2, Interesting

    a) See http://www.rubygarden.org/ruby?RealWorldRuby

    b) It's a marvelous tool to increase productivity; I wrote something in ~2 hours which parses ~70 XML documents in ~10 directories and creates 150+ static HTML pages (for a help system shipping with the application) from moderately complex business logic off of 5 template files.

    Changed or added an XML document? Run the ruby script. Need an HTML tweak? Change one template file and run the script. 3 seconds to parse the XML documents (and apply Textile markup to certain sections) and 3.5 seconds to create the HTML.

    Ruby allowed me to very quickly write a complex tool that now saves me a huge amount of time every time I use it. Even *if* no companies were hiring specifically for Ruby skills, having a tool in your belt that makes you stand out is still a Great Thing.

  29. Re:Ruby and Perl over Python for cross-platform de by Tellalian · · Score: 3, Informative

    Python will require me to go line by line and insert spaces or tabs.

    No offense, but that's a load of crap and evidence that you've never actually coded anything in Python. If you had, you'd know that Python comes with a fully functional editor called IDLE, which includes auto-indentation. You can also select whole chunks of code and press ctrl+] to indent or ctrl+[ to unindent. Explicit scope declarators serve no purpose but to frustrate the programmer who forgets to declare that last '}' of 'end' statement. All Python forces you to do is write clean, readable code.

  30. as a complete non programmer by cinnamon+colbert · · Score: 2, Insightful

    I downloaded both python and ruby when I started thinking about learning how to program. I cd download and install correctly both languages on my Win2K OS laptop, but ruby had two things python did not: a really neat intro tutorial out of berkeley, and some sample progams (like abouncing red ball in a box) to play with. For kids learning to progam, this sort of basic hold your hand stuff is invaluable
    Based on this, ruby is better thought out. ON the other hand, I started to puke at all the ruby way stuff.

  31. Do Real Programmers write in Ruby? Or in Python? by Anonymous Coward · · Score: 2, Interesting

    Sorry for an off-topic rant by an old man, but this pointless duscussion has just reminded me a recent story comparing Java to C# when someone apparently devoted to the macho side of programming made the bald and unvarnished statement: Real Programmers write in Perl.

    Maybe they do now in the 21st century, in this postmodern era of blogs, smartphones, and "user-friendly" software, but back in the Good Old Days, when the term "software" sounded funny and Real Computers were made out of drums and vacuum tubes, Real Programmers wrote in machine code. Not Perl. Not C. Not, even, assembly language. Machine Code. Raw, unadorned, inscrutable hexadecimal numbers. Directly.

    Lest a whole new generation of programmers grow up in ignorance of this glorious past, I feel duty-bound to describe, as best I can through the generation gap, how a Real Programmer wrote code. I'll call him Mel, because that was his name.

    I first met Mel when I went to work for Royal McBee Computer Corp., a now-defunct subsidiary of the typewriter company. The firm manufactured the LGP-30, a small, cheap (by the standards of the day) drum-memory computer, and had just started to manufacture the RPC-4000, a much-improved, bigger, better, faster -- drum-memory computer. Cores cost too much, and weren't here to stay, anyway. (That's why you haven't heard of the company, or the computer.)

    I had been hired to write a FORTRAN compiler for this new marvel and Mel was my guide to its wonders. Mel didn't approve of compilers. "If a program can't rewrite its own code," he asked, "what good is it?"

    Mel had written, in hexadecimal, the most popular computer program the company owned. It ran on the LGP-30 and played blackjack with potential customers at computer shows. Its effect was always dramatic. The LGP-30 booth was packed at every show, and the IBM salesmen stood around talking to each other. Whether or not this actually sold computers was a question we never discussed.

    Mel's job was to re-write the blackjack program for the RPC-4000. (Port? What does that mean?) The new computer had a one-plus-one addressing scheme, in which each machine instruction, in addition to the operation code and the address of the needed operand, had a second address that indicated where, on the revolving drum, the next instruction was located. In modern parlance, every single instruction was followed by a GOTO! Put that in Pascal's pipe and smoke it.

    Mel loved the RPC-4000 because he could optimize his code: that is, locate instructions on the drum so that just as one finished its job, the next would be just arriving at the read head and available for immediate execution. There was a program to do that job, an "optimizing assembler," but Mel refused to use it. "You never know where it's going to put things," he explained, "so you'd have to use separate constants." It was a long time before I understood that remark.

    Since Mel knew the numerical value of every operation code, and assigned his own drum addresses, every instruction he wrote could also be considered a numerical constant. He could pick up an earlier "add" instruction, say, and multiply by it, if it had the right numeric value. His code was not easy for someone else to modify.

    I compared Mel's hand-optimized programs with the same code massaged by the optimizing assembler program, and Mel's always ran faster. That was because the "top-down" method of program design hadn't been invented yet, and Mel wouldn't have used it anyway. He wrote the innermost parts of his program loops first, so they would get first choice of the optimum address locations on the drum. The optimizing assembler wasn't smart enough to do it that way.

    Mel never wrote time-delay loops, either, even when the balky Flexowriter required a delay between output characters

  32. It is extremely important to mention Parrot by Pan+T.+Hose · · Score: 2, Interesting

    Can I get any advice? Is Ruby really "more powerful than Perl and more object oriented than Python" - is this what I'm looking for, or should I put it off and learn Python first?

    No, it is not more powerful than Perl. But than again, nothing is. The points is not what is more powerful per se, but rather which is more powerful in your hands and which one best fits your own brain. At this point it is extremely important to mention Parrot: "The amazing project [...] to really unite Perl and Python one day (not to mention Tcl, Scheme, Forth and Ruby, to name just a few)."

    Perl, Python and Ruby, while not the only ones, are certainly the most important languages for the Parrot development. Parrot will not be considered ready until all of them are fully supported, and at this point Parrot will be their main target Virtual Machine, running each of them and allowing them to interoperate. At this point it won't matter which of those languages you personally use, because whatever you choose you will still have access to all of the libraries and module, class and object, of each of them.

    Few years ago I will tell you: "go for Perl because of CPAN." Now my advice woule be: "go for whatever you please, for in few years it won't really matter. We will be able to work on the same project, write the same application. I will write my part in Perl 6, you will write yours in Ruby, someone will write in Python and another one in Scheme. We will all subclass our classes, invoke our methods, use our objects, and we will produce a single, monolithic Parrot application anyway."

    Just imagine picking up some fresh, young and cutting-edge language designed weeks ago--or even designing your own language--and having every module from CPAN available at once, working just fine using your new language syntax. This is the future Perl, Python and Ruby. Interoperation instead of competition.

    --
    Sincerely,
    Pan Tarhei Hosé, PhD.
    "Homo sum et cogito ergo odi profanum vulgus et libido."