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."

15 of 97 comments (clear)

  1. Re:Best. Clause. Evar. by Anonymous Coward · · Score: 2, Informative

    Apparently the poster isn't a native English speaker. Anyway, all he meant was that the tarball is about twice as big now. This is almost entirely due to the inclusion of more libs, not an increase in size of the Ruby core.

  2. correct link by oever · · Score: 3, Informative

    Here's the link to the changelog.

    --
    DNA is the ultimate spaghetti code.
  3. Re:Former perl, python, java geek gone to Ruby by tcopeland · · Score: 3, Informative
  4. Includes YAML support by Colonel+Panic · · Score: 2, Informative

    If I'm not mistaken, Ruby is the first language to include built-in support for YAML!

    Thanks to Matz for such a great language!

    1. Re:Includes YAML support by whytheluckystiff · · Score: 2, Informative

      Absolutely. Ruby 1.8 contains a C extension (Syck) for parsing YAML. Benchmarks have shown that Ruby's YAML parser is competitive with the marshalling standards of other popular languages. Which is a big win for developers, as YAML is much more readable.

      I will also mention that if you'd like to learn YAML, you might head over to the YAML Wiki, where general documentation is starting. There's also a complete manual for the Ruby extension.

  5. Re:Former perl, python, java geek gone to Ruby by Anonymous Coward · · Score: 1, Informative

    Perl is faster - no denying it. But then text parsing is Perl's forte and I'd be surprised to see any language beat Perl in that arena.

    How much faster really depends on what you're doing, ranging from as little as 10% faster to as much as twice as fast (in my own benchmarks at least). But then as many Perl folks used to be fond of saying, "If you need speed...use C".

    On that note, you'll find writing C extensions a helleva lot easier than Perl. :) Anyway, it really boils down to whether you're willing to trade a little speed for a cleaner overall language. My advice is to at least give it a try.

    BTW, I should mention that I also used to be a die hard Perl fan....until I found Ruby. :)

  6. Re:Former perl, python, java geek gone to Ruby by Colonel+Panic · · Score: 4, Informative

    I thought that code blocks were a pretty lame excuse for proper functions-as-data, so I'm a little bit surprised to see them mentioned as a great feature. Did I miss something?

    You did.

    Code blocks are probably one of the most important features of Ruby that differentiates it from Python.


    From what I understand, code blocks are basically anonymous functions that the method they are passed to can only invoke with yield, right?


    wrong.

    Or is it possible to treat them as any other parameter, i.e. store them, pass them further around, take more than one etc?


    Yes. Yes. Yes. Yes (well, that last one is a qualified yes, if I understand your question correctly: you have to convert them to Proc objects before you can pass more than one of them to another method due to the fact that the '&' block delimiter in the method's parameter list can only be on the last parameter - it's not a big limitation).

    At first glance, code blocks don't seem that interesting, cool or useful, however, I was able to create a domain-specific hardware description language using them without the need to create any parser for that langauge. It was written in pure Ruby, but to the user it looks like another language in it's own right.

    So I could do things like (if you're familiar with VHDL this should look familiar):

    process(clk,rst) {
    if clk.event and clk == '1'
    counter.assign counter + 1
    elsif rst == '1'
    #do resest:
    counter.assign 0
    end
    }
    #

    It's all written in pure Ruby. The part between the '{' and '}' is a code block that's being passed to the process method which will execute the block whenever the value of clk or rst changes. So essentially, code blocks allowed me to make Ruby look a lot like VHDL. It looks very natural. AFAIK, this sort of thing is not (easily) doable in Python.

  7. A couple of things Python doesn't have by Anonymous Coward · · Score: 1, Informative

    Can you please elaborate on what features Ruby has that Python doesn't?

    Two features that come to mind immediately:
    1) continuations - Python doesn't have'em. While this is a fairly obscure and difficult to understand feature, I've found it to be vary valuable in a couple of instances where without them I would have had to write a lot more code to get the job done.

    2) code blocks - at first they seem trivial, but after you start using them and thinking in terms of passing code blocks around you end up using them a lot. They tend to make your code look very natural (not sure how else to explain it, they're just cool).

    I suspect there are other differentiating features as well, but these are the two that come to mind immediately and Python's lack of these two features tipped the scales in favor of Ruby for me.

    Oh, I suppose I can add an anti-feature that also tipped the scales in favor of Ruby for me:
    Ruby doesn't consider indentation as syntax - I know a lot of Pythonistas seem to like indentation as syntax, but I never got to like it... for example, if I wanted to copy&paste some section of code into another section and they were at different levels of syntax... well, it could just get messy. I don't need those kinds of hassels.

  8. Re:Former perl, python, java geek gone to Ruby by xteddy · · Score: 3, Informative

    > * Blocks are litteraly a bag hung on the side. Needlessly ugly and limiting.

    Why do you feel they are ugly? Ok, they are not real functions like scheme has them, but Ruby wants to be an object oriented language, so it's ok that they are (can be transformed to) objects. Ruby is just consistent in not having any functions but only methods, so you have to use Proc#call(x) or Proc#[x] to call a procedure with arguments.

    They are real lexical closures, too, which wasn't mentioned in any thread before:

    def make_counter
    x = 0
    lambda do x += 1 end
    end

    c1, c2 = make_counter, make_counter
    c1.call # => 1
    c1.call # => 2
    c2.call # => 1
    c1.call # => 3
    c2.call # => 2

    > * The typographic hungarian notation ($ for globals, capitals for constants, etc)

    Hungarian notation encodes the type of a variable into the variable name. In Ruby the sigils are used to show the scope of the variables. You can see at one glance that @@foo is class variable, @bar is an instance variable and $baz is a global variable. I found this to be very useful while refactoring code.

    > * The premptive binding of literals to built in classes.

    In the case of small integers this is more time&space efficient and that's the price you have to pay.

    > * The perl compatibility frosting.

    There isn't really much left of perl compatibility and lots of perl's "features" are about to be deprecated. In general they aren't used very often by Ruby programmers. It's true that a lot of stuff looks like Perl, /^a.*/ and 1..10 for example, but unlike in Perl these are real objects and first class citizens in Ruby.

    > It's still my scripting language of choice though.

    Yeah, all scripting languages suck, Ruby just sucks less. *g*

  9. Thanks, IE. Repost that isn't ruined by Paradox · · Score: 2, Informative
    Never try to post on a windows machine, they're out to get you :P

    Don't forget some of the other unique uses of blocks, that make them very, very powerful.

    They can be used in unique ways that are pretty darn useful. For instance, you can use them to create configuration blocks for objects, without cluttering the constructor.

    myServer = Server.new( socket, something ) {
    set_sercurity_mode 2
    set_logfile_path "/var/logs/speciallogs/"
    }
    A constructor aware of this can use this block to configure the object in ways that normally would require dozens of different constructors, with a relatively unambiguous syntax. Even better, defining those set functions for the configuration block also defines them as instance variables. 2 foe the price of one! :)

    With a little thought and use of Ruby's excellent security model, it's possible to even just dump a file into that block, and use the file as the configuration block!

    --
    Slashdot. It's Not For Common Sense
  10. Re:Former perl, python, java geek gone to Ruby by Dan+Ost · · Score: 3, Informative

    Python doesn't let you subclass built-in types, and it certainly doesn't let you treat integers as objects.

    This is no longer true. As of Python 2.2, I'm pretty sure that both of these
    complaints have been addressed (the first one for sure).

    --

    *sigh* back to work...
  11. Re:Former perl, python, java geek gone to Ruby by xteddy · · Score: 5, Informative

    Why can't I define a method that takes two or more blocks (e.g. if/then/else) with the same syntax I use for methods that take a single block? Why can't I introspect the structure of a block? Why the duality with Proc objects? In short, why aren't blocks first class objects?

    To clarify this first: It's always possible to create multiple Proc objects with Proc.new, lambda or proc and pass them to a method.

    There are two reasons why there are blocks AND Proc objects:

    1. To use a block it's not necessary to create an object and that's good for the performance, e. g. if you have to iterate very often over some collection.
    2. Blocks are used for iterators and control structures, so Matz wanted them to look like those already did.

    It would perhaps be possible to have something like that:

    foo { ... } { ... }
    But there is an ambiguity because the first block could also be a hash constructor. I am not sure if it would be possible to solve that problem by changing the parser. You could limit yourself to use only do ... end with multiple blocks but I thinks that it's better not to have multiple do ... end blocks in one method call.

    BTW: The if/then/else is not a method call and the selectors consist only of a single word in Ruby unlike in Smalltalk. So it would require a big change to the language and the interpreter if blocks should be used there.

    Introspection of blocks is a good idea. Perhaps this will be possible if the new VM for Ruby 2.0, called Rite, is implemented. AFAIK it also should be possible to change code in the parse tree on the fly at arbitrary places then.

    More to the point, in ruby I'd like to be able to change the scope or storage class of an object reference without having to rename it.

    This is clearly a tradeoff. You can choose between having to look up the variables everytime you want to know their scope or between seeing it easily and change every variable if you want to extract a method. I think to choose the latter is a good choice for a language where you don't usually program in a code browser.

  12. Re:That's not what we mean by clean, friend. by xteddy · · Score: 2, Informative
    Clean syntax is not an end in itself. It's good for compiler writers because it's easier for them to parse the language. LISP and Brainfuck have a very clean and minimal syntax but the programmers have to pay a price. Ruby was not intended to be a minimal, clean language (like many academic languages are) but was designed to help programmers write better programmes and make them better programmers at the same time.

    Matz held a talk on his intentions at OSCON (and it's fun to read) named

    The Power and Philosophy of Ruby or How to create Babel-17.

  13. Now will someone please document it? by PizzaFace · · Score: 3, Informative

    Ruby is a cool language, but someone has to break down and document it. There is quite a bit of not-quite-current documentation, including a great online version of Programming Ruby , but the official library reference is for 1.6 and the language reference is for 1.4. The lack of current documentation for 1.8 raises doubts about the consistency of the language's behavior, especially its more Perlish, do-what-I-mean features.

  14. Re:Hmmm... by Guido+von+Guido · · Score: 4, Informative

    You know, reading over the the information available for Perl 6, I get the idea that a lot of the improvements intended for Perl 6 were actually stolen from Ruby. As much as I love Perl, the OO implementation is a bolted-on, pain-in-the-ass kludge. Ruby's is an integral part of the language, and Ruby is a very nice language.