Article:
  Building Unix Tools with Ruby
Subject:   "It's code like this that causes unrest."
Date:   2003-09-21 02:12:23
From:   anonymous2
I have to agree with the other comments that the code is very un-Ruby-like. Seems like someone who's only recently come from Perl and is trying to write Ruby in a Perl style.


"while gets {}" for example. What nonsense. "$stdin.readlines.each {}" is much more Rubyish.


The reinvention of the command-line and CSV parsing wheels is also something that tends to afflict Perl people, not to mention the fact that the CSV parsing is inadequate and will fail with embedded commas.


Overall, 4/10 for effort.


Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • "more Rubyish" isn't relevant in this case
    2003-09-21 05:13:39  dblack [View]

    > "while gets {}" for example. What nonsense.
    > "$stdin.readlines.each {}" is much more Rubyish.

    These two things are not equivalent. gets returns one line. readlines reads all the lines into an array. There may be cases when these two techniques appear to do the same thing, but in fact they don't. If you try them with keyboard input, you'll see what I mean.

    Since they are different, determining which one is "more Rubyish" is secondary to deciding which one you actually want to do. Moreover, if one needs the gets version, one can then do:

    while (line = gets)

    to get rid of $_. (You'll find this technique used in several places in the Ruby distribution.)


    • "more Rubyish" isn't relevant in this case
      2003-09-23 08:55:57  anonymous2 [View]

      I think $stdin.each_line {} is better and more "rubyish" than any of the above.