Sunday, February 24, 2008

Ruby 1.9 -- talk by "Matz" Matsumoto 2/22/08

Matz talks about Ruby 1.9 @ a recent Google talk... I took some notes while watching it via YouTube. You can read the notes, and watch the video below

Ruby 1.9 -- Released on Christmas 2007

1.8 - Stable -- daily use, stable, compatible (1.8.6 latest)
1.9 - Bleeding Edge -- faster, more powerful, done right, but incompatible
2.0 - "Innovation Bait" -- vaporware, Open Source Software should move forward or die, scalability is the Keyword (data size, program size, team size)

Ruby 1.9 incompatibility: some big ones, some small ones.
Big incompatiblity: block params, strings, unicode
block params: local variables only, block scoped
"functional programming people love to abuse the blocks"
ary.each{|$var|...} #=> ERROR}

Non enumerable Strings in 1.9... no longer Strings are enumerable... now you need to specify (no ambiguity anymore):
"foo\nbar".each_line{...}
"foo\nbar".each_char{...}
"foo\nbar".each_byte{...}
or similarly:
"foo\nbar".lines.each{...}
"foo\nbar".chars.each{...}
"foo\nbar".bytes.each{...}

Ruby 1.9 Unicode is based on Characters... 1.8 was based on Bytes
1.9 supports character encoding
E.g.:
"ABC@#$"[0] # => "A"
"ABC@#$"[3,1] # => "@" (index, num characters)

like Python, accepts character encoding:
# -* coding: UTF-8 -*-
(won't work with UTF-16 yet)
also can specify with file:
open(path, "r:UTF-8") { |f|
...#read all strings in this file as UTF-8 data
}
Lot of little small incompatibilities with this improvements... most of them trivial

Some Features are Gone in 1.9 (we were warned about these in advance)
- VERSION and friends
- Object#type
- Hash#index
- Symbol#to_int
- Removed Array and Hash #indices, #indexes
...

Lot of new features (too many to list)

New feature Highlighted:
- Lambda by ->
- Method Invocation by .()
- Enumerators

Lambda by ->
->(x)(x*2).(2) # => 4
->(x=5){x*2}.() # => 10
(Perl does same syntax with the '->')

Chain of Enumerator:
ary.map.with_index{|x, i|
... # can have "with_index" with any method
}

External Iterator:
e1 = [1,2,3,4].each
e2 = [10,11,4].each
loop {
p e1.next + e2.next
}
#prints 11, 13, 7

The New Implementation
YARV -- Yet Another Ruby VM

-Yarv is integrated into the core of 1.9
-History of Ruby.. many people tried to improve performance by creating a virtual machine. So many attempts... very tough job... Matz had a plan for a long time to create a VM... but he couldn't do it, didn't have enough time... he didn't expect much from YARV, because so many people fail... yet YARV is nice. It replaced the official Ruby interpreter.
VM developed by Koichi Sasada, Bytecode interpreter, Optimized for Ruby... Scheme compiler.
-Maximium 50x faster core performance
-x2-10 Faster in benchmark tests
-Improves CORE only (using same library)
- programs do not run 50x faster (b/c they have libraries, classes, garbage collectors, etc)
-about 1.5x faster on average... makes us "comfortable", "fairly fast".. vague perceptions from Matz

Memory Diet for new interpreter
- reduced memory footprint
- showed a comparison for 'rdoc', for instance

What is Ruby Anyway?
- the language (dynamic, flexible, productive)
- the community (nice people!... Martin Fowler...one of the best communities, proud of that)
- the implementations (Ruby has Multiple Implementations... 1.8, 1.9(YARV), JRuby (JVM), IronRuby(.NET), Ruby.NET(CLR, DLR), Rubinius)

Google Restricts languages to Java, Python, C++, JavaScript(Client side)
Steve Yegge, JS on Rails (using modified Rhino, for good reasons)... Matz believes those are fair reasons.

But we have JRuby. Ruby running on JVM... compiles class files... 1.8 compatible... can execute Ruby on Rails... now Runs faster than 1.8... accesses all Java Libraries

Matz hopes Ruby helps all world programmers to be Productive, Enjoy and be Happy programming (I agree!)... was written to satisfy Matz as a programmer, to help him enjoy programming. He hopes it helps Google programmers as well! (with JRuby maybe!)

20 minutes of questions (not a transcript, just my notes):
-Q: stability of 1.8... new features in 1.9... will there be any 1.9 features added to a 1.8x branch? Matz A: Yes
-Q: why release on Christmas? Matz A: enjoys the Holiday break! He lives in non-Christian country yet he is a Christian.. wanted to mention Christianity in a modest day. Next year its going to be a week before Christmas!
-Q: any spec for Ruby language? Matz A: JRuby people worked with Rubinius (implemented in SmallTalk way... Ruby implemented in Ruby)... set of test suites... working with Matz, et al... will have a specification of 1.8 language when its finished.
-Q. what are you doing now? Matz A: improving 1.9. after release of 1.9.1... he will start working on 2.0, which is vaporware now...
-Q. is 2.0 close to being started? Matz A: the time is finally near, yes.. moving forward
-Q. what RegEx engine will Ruby 1.9 use? Will the RegEx syntax be documented this time? Matz A: Oniguma... and we are working on documenting 1.8 and 1.9... it will be available.
-Q. wondering... do you have any timeline when callCC will come back? I noticed it was not on slides. Matz A: you can use it, from 1.9, you have to explicitly declare 'i'm going to do something dangerous'... a guy suggested how about naming Continuations library as "Continuations-i-agree-with-dangerous-thing".
-Q. wondering about String data type.. noticed that you have direct indexing...do you use UTF-8 and how do you efficiently implement that access? Matz A: UTF-8 data...process it as UTF-8... set of C functions to filter and give illusion of the sequence of characters... from Matz+team's experience... it's okay. Most of the character based process is based on RegEx. If RegEx is optimized, problems can be avoided.
-Q. sounds like your index of a character by RegEx is inefficient? Matz A: ~ in many cases we can have 'tricks' to reduce the complexity
-Q. what is the status of named parameters in Ruby 2.0? Why not just copy from Python syntax which is easy to understand and use? Matz A: named parameters will be added in 2.0... and it's very primitive to those in Python... a hash of symbols that can be specified at the end of argument ... attribute:value, attribute:value, ...
E.g.:
open(path, {encoding: "utf-8", newline: "auto"})
...get it? it is a Hash at the end.
-Q. why do you want to add a Hash to these little parameters... could be confusing? Matz A: this is Hash... It's merely an extended Hash

That's a wrap!


3 comments:

Wolf said...

Regular expression is really wonderful to parsing HTML or matching pattern. I use this a lot when i code. Actually when I learn any new langauge, first of all I first try whether it supports regex or not. I feel ezee when I found that.

http://icfun.blogspot.com/2008/04/ruby-regular-expression-handling.html

Here is about ruby regex. This was posted by me when I first learn ruby regex. So it will be helpfull for New coders.

SEO Services Consultants said...

Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck! Web Design Company

rocky case said...

Stephen Stapinski

Really your blog is very interesting.... it contains great and unique information. I enjoyed to visiting your blog. It's just amazing.... Thanks very much for the share.