Slashdot Mirror


Ruby 1.8.0 Released

waieitch writes "A long-waited new version of the scripting language, Ruby 1.8.0 has just been released. You can download from here, and the changelog is available. With many new libraries, say dRuby, ERB, REXML, this version is doubled by 1.6.8 in size."

9 of 97 comments (clear)

  1. Former perl, python, java geek gone to Ruby by Fished · · Score: 4, Interesting
    For what it's worth, I've been using ruby for about six months, and am totally hooked. It is easily the best language I've ever used. Things that are idiosyncratic and difficult in other languages just flow in ruby. There are also many features to facilitate the way you actually *use* objects (e.g. to do object attributes, all you have to do is add "attr_writer attribute1, attribute2, attribute3" and "attr_reader attribute1, attribute2, attribute3") to the class defs. No more endless get and set functions all of which are more or less identical!

    This language is definitely worth a look. It's not just a python knock-off, as many have supposed -- it offers features python doesn't.

    --
    "He who would learn astronomy, and other recondite arts, let him go elsewhere. " -- John Calvin, commenting on Genesis 1
    1. Re:Former perl, python, java geek gone to Ruby by MarkusQ · · Score: 4, Interesting

      it had the same conceptual structure as Python, but the cryptic syntax of perl

      I'm not sure what language you looked at, but it doesn't sound like ruby.

      • Ruby is a deeply object oriented in the tradition of smalltalk; python is a superfically object oriented language more in the tradition of C++ or object pascal. Until recently, for example, you could not derive your own classes from the built in classes.
      • The basic syntax of ruby is very clean (a fact which is somewhat obscured by the "syntactic sugar" provided for some commonly used features (such as operators) and the provision of aliases for some global objects that are intended to ease the transition from perl). The basic syntax is:
        method_call ::= object.method_name arg1,arg2,...argn
        where object, method_name, and the arguments can all objects and can be given by named constants, literals, variables, or expressions (method calls). The only thing I really miss from python is the indentation (or rather, not having to explicitly delimit blocks, since I indent that way even when I don't have to).
      -- MarkusQ

    2. Re:Former perl, python, java geek gone to Ruby by tigersha · · Score: 4, Interesting

      The major improvement in Ruby over Python and C++ and most OO languages (but not Smalltalk) is the inclusion of code blocks that may be passed in as a parameter to a method and its widespread use throughout the libraries.

      For a simple example, look at this:

      x = [1,2,3,4]

      x.each do |e|
      puts e
      done

      This is NOT syntactic sugar. The list class has a each method that takes a piece of code as an argument and executes it for each element in the list. This can do the same as generators now coming into the new Python and is very similar to higher-order functions in functional languages.
      Basically the do...done part is a parameter (albeit a special one, a method may only have one).

      It is difficult and syntactiucally tricky to do this in most OO languages and trivial to add an each method (or whatever you want to call it) to your own classes. It is also extremely powerful way of doing many thing which requires a lot of messiness in other languages.

      This high-erorder code blocks now allow you to really do the everything-is-anobject thing because you MUST have code blocks to implement control structures such as if or while as an object. It is also very pervasively used in all collections and for instance in REXML where you can say

      x = some XML...

      x.each( xpath expression ) do |element| ...
      done

      Another example

      String.each_regexp( regexp ) do ... done

      Does the code for each place where the regexp was found in the string. Same sort of thing can be done for databases and so forth.

      Ruby also has things like mix-in classes which are usually dissed by OO theoreticians but turn out to be very useful. Mix-in classes were pioneered by some dialect of LISP and are a form of restricted multiple inheritance,. A class can inherit methods from other modules but not instance variables (except for its parent class). This allows you to this (this is pseudocode)

      myclass inherits Ord
      implement = and other operators in terms of and = (which are supplied by your class). And now your class implements all of these methods. This is again tricky to implement in traditional top-down inheritance trees. Think of Java's interface system, but with default implementations.

      This is used to great effect in the collections to implement many things in terms of some primitve operators.

      --
      The dangers of excessive individualism are nothing compared to the oppressiveness of excessive collectivism
    3. Re:Former perl, python, java geek gone to Ruby by RevAaron · · Score: 3, Interesting

      The basic syntax of ruby is very clean (a fact which is somewhat obscured by the "syntactic sugar" provided for some commonly used features (such as operators) and the provision of aliases for some global objects that are intended to ease the transition from perl). The basic syntax is:

      method_call ::= object.method_name arg1,arg2,...argn


      Along the same line, you could just as easily say that C++'s basic syntax is:

      method_call ::= object.method_name(arg1, arg2,...argn)

      and perl's:

      method_call ::= object->method_name(arg1, arg2,...argn)

      So C++ and Perl must be languages with simple, elegant and clean syntax, right? The method call syntax doesn't mean a thing. (well, if the language was particularily ugly it would- like some OO Cobol implementations)

      Ruby has substantially less syntax than Perl and C++, that much is true and pretty commonly known. However, IMHO, Ruby has a bit much syntax, compared to languages like Smalltalk or Scheme. Smalltalk is a language which manages to be expressive, but without the amount of syntax that Ruby has.

      --

      Working toward a usable PDA environment in the spirit of Newton OS: Dynapad
    4. Re:Former perl, python, java geek gone to Ruby by Luk+Fugl · · Score: 2, Interesting

      From what I understand, code blocks are basically anonymous functions that the method they are passed to can only invoke with yield, right? Or is it possible to treat them as any other parameter, i.e. store them, pass them further around, take more than one etc?

      When I looked at Ruby (not in much detail yet), I thought that code blocks were a pretty lame excuse for proper functions-as-data

      Ruby is a completely first-class language, as in scheme, smalltalk, et al. In other words, anything can be passed around and modified as an object -- methods, anonymous procs and even classes themselves.

      It's true that the code blocks mentioned by my grandparent are limited, as the poster said, but ruby also provides the Proc object (mentioned by my sibling).

      But even more exciting than anonymous procs (first class methods to you CS theoreticians) are classes as objects. If I want to, I can provide a class name -- which is really just a handle to an object representing that class -- as an argument to a function call. I can modify that class on the fly, adding or redefining methods. It's true that this extreme power requires extreme care, but IMO it's a verynice feature to have available and used correctly can produce very elegant and readable (and correct!) code.

    5. Re:Former perl, python, java geek gone to Ruby by dbday · · Score: 2, Interesting
      Or even more amazing to me, you can cut out the MoreThanArray subclass and extend the Array class directly:

      irb(main):002:0> class Array; def is_even?; 0 == length % 2; end; end
      nil
      irb(main):003:0> [1,2,3,4].is_even?
      true
      irb(main):004:0> [1,2,3].is_even?
      false
      You can even extend instances of classes, rather than the classes themselves:

      irb(main):001:0> x=[1,2,3,4]
      [1, 2, 3, 4]
      irb(main):002:0> x.is_even?
      NameError: undefined method `is_even?' for [1, 2, 3, 4]:Array
      from (irb):2
      irb(main):003:0> def x.is_even?; 0 == length % 2; end
      nil
      irb(main):004:0> x.is_even?
      true
      irb(main):005:0> x.pop
      4
      irb(main):006:0> x.is_even?
      false
      In this last example, only the Array instance assigned to x has the is_even? method. Other array instances are unaffected.

      This really tickles me for some reason. One of the many reasons to love Ruby. It also makes me want to go back and investigate Smalltalk again.
    6. Re:Former perl, python, java geek gone to Ruby by scrytch · · Score: 2, Interesting

      It's kind of funny- McCarthy didn't intend Lisp to keep the ultra-simple paren-based syntax, but to add an algol-ish syntax down the line.

      Initially. Once macros came around, there was nothing like it in programming-land, and when you notice how many program structures you can implement with macros, there's still nothing quite like it, except perhaps for stuff like OpenC++ and camlp4, both of which have their *own* nasty syntax that doesn't look like anything else... Sexps became a feature very early on.

      That said tho, it is a bit of a shame that there wasn't also a line-based alternate structuring convention and operator set that could elide most of the unnecessary parens. Good enough for haskell (layout rule and $ operator) after all.

      --
      I've finally had it: until slashdot gets article moderation, I am not coming back.
    7. Re:Former perl, python, java geek gone to Ruby by Xlucid · · Score: 2, Interesting

      True - but I am excited that there is a language that I can leap straight to from Smalltalk, without feeling I'm losing significant amounts of the niceness of Smalltalk.

      Plus, I get all the regexp power of Perl, and a substantial part of the Windows-ness of Smalltalk MT.

      Remember, Dave Thomas (the PragmaticProgrammer who co-wrote the first English-language Ruby book, and who helps promote Ruby to the English speaking world) is a Smalltalker.

      Leaping back and forth between Ruby and Smalltalk is, IMO, far more straightforward than the back and forth from Smalltalk to Ruby's obvious rivals.

      That said, I'm still humming and hawing between Ruby and Smalltalk MT for my Next Big Thingtm

  2. Re:Smalltalk elegance & Ruby elegance by Xlucid · · Score: 2, Interesting

    Smalltalk is a language which manages to be expressive, but without the amount of syntax that Ruby has.

    I'm a Smalltalk-er who likes Ruby for its Smalltalk-eyness.

    After all, here are 5 lines of Ruby code that give the count of unique IP numbers listed from a webserver logfile which downloaded a particular file from the server

    Ruby code:
    anIpNum = Regexp.new(/[0-9.]+/)

    aFile = File.open('D:/Savant/copyOfGeneral.txt')

    aDicti onary = Hash.new

    aFile.each_line { | line | aDictionary[line.slice(anIpNum)] = 1 if line.include?("plastic_1.1_lite-UMLtool-fw.exe") }

    puts aDictionary.size

    and the equivalent Smalltalk

    anIpNum := Regexp new: '[0-9.]+' .

    aFile := File open: 'copyOfGeneral.txt' .

    aDictionary := Dictionary new .

    aFile each:
    [ | eachLine |
    eachLine include: 'plastic'
    ifTrue: [ aDictionary at: anIpNum put: 1 ]
    ] .

    aDictionary size

    Of course, in Smalltalk-80 there isn't a standard Regexp class, so I'd have to find one.

    But I hope you all agree that Ruby's syntax is not too far off Smalltalk's elegance in this example.

    p.s. Apologies for the formatting, but until I selected 'Code', Slashdot's lameness filter kept rejecting this post...