Matz's keynotes
Posted by kev Sun, 16 Oct 2005 09:12:00 GMT
Keynote Address - Why Arrows are Bad Visions for the future
Yukihiro “Matz” Matsumoto
Thank you, people, for attending here. I’d like to talk about the vision for the future. Two years ago, I gave the same kind of title(?).
Programming Languages are Now Commodities
Like Cars; They are All Good Enough
- Basically Same Structure
- Difference in Design
- and Small Functionality
We choose our own brand of language, based on the small differences that we like, personally.
Japanese are Good at Making Commodities
- Toyota
- Honda
- Sony
- Panasonic
- … and Ruby
Developing Commodities
- Need to be Cheap
- Design Matter
- Small Things Matter
- Need to Keep Moving
- …with wild and crazy ideas
The key to developing commodities - they need to be cheap. Ruby is cheap, because it’s free.
Toyota develops a new car every six months or so.
Since Ruby is Good Enough
- Its OK to try Crazy Ideas
- If they don’t work out, just try another
- Just not to stop moving
- activate community
- to have FUN!
The real theme of tonight’s address is…
Wild and Weird Ideas
The New Path
- Yet Another Ruby VM (YARV)
- 1.9 New Feature Testbed
YARV
- Faster
- Simpler
- Native Thread Aware
Ask ko1 There
I’ll focus on the crazy ideas.
1.9 Possible New Features
- keyword arguments
- constants
- multiple assignment
- eval
- lambda
- annotations
- traits
- namespace
- method combination
- multilingualization
Keyword Arguments
- Make method calls more descriptive
- Order Free Arguments
- Help you save Brain Power
Keyword Arguments
def foo(a,b=0,c:4)
...
end
foo(1) # a=1,b=0,c=4
foo(1,2) # a=1,b=2,c=4
foo(1,c:2) # a=1,b=0,c=2
foo(1,2,c:3) # a=1,b=2,c=3Keyword Arguments (2)
def bar(a:,b:0)
...
end
alias :foo :bar
foo() # error! is a mandatory
foo(1) # error! no positional argument
foo(a:1) # a=1, b=0
foo(a:1,b:2) # a=1,b=2
foo(b:2) # error! a is mandatory
foo(c:2) # error! c is not definedAll positional arguments go before any named arguments.
Can have optional default values for positional arguments.
Cannot have two adjacent commas to represent omitted arguments.
One goal of this is to replace fragile optional arguments.
Can specify “c: :foo” to represent a default value of symbol :foo.
Spaces are not allowed before the first ‘:’ (i.e., “c : 1” is not allowed).
Keyword Arguments (3)
def bar(*rest, a:4, b:0, *keys)
...
end
alias :foo :bar
foo() # rest=[],a=4,b=0,keys={}
foo(1) # rest=[1],a=4,b=0,keys={}
foo(a:1) # rest=[{a:1}], a=1,b=0,keys={a:1}
foo(a:1,b:2) # rest = [{a:1,b:2}],a=1,b=2,keys={a:1,b:2}
foo(1,2,b:2) # rest=[1,2,{b:2}],a=4,b=2,keys={b:2}
foo(c:2) # rest=[{c:2}],a=4,b=0,keys={c:2}Both *rest and *keys are optional. Note that *rest and *keys name new local variables, so are completely arbitrary.
Keyword Arguments Summary
- Keyword arguments are passed as a Hash at the end of arguments
- Rest argument (*) contains a keyword hash as well
- Keyword argument ( *) contains a Hash (without default values)
- Unspecified keys are allowed if keyword argument is present
The *keys hash contributes 1 to arity().
Chad steps in and stops the madness that ensued.
Constants
In short, constants will become more like class variables
- with better appearance
- with restriction in assignments
- with warning for direct modification
Multiple Values
- Too complex to understand
- Virtually No One on Earth Understands
- Much simpler rules
“Real” Multiple Values
a la Common Lisp
- Methods can return multiple values
- Multiple values in ordinary context give the first value
- Array to Values (RHS *)
- Values to Array (LHS *)
Multiple Values Example
def multi()
return 1,2,3
end
a = multi() # a=1
a,b = multi() # a=1,b=2 **
*c = multi() # c=[1,2,3]
a,b = 1,2 # a=1,b=2
a,b = [1,2] # a=[1,2],b=nil **
a,b = *[1,2] # a=1,b=2** Are the different behaviors.
Multiple Values Example (2)
def multi()
return 1,2,3
end
def output(*args)
p args
end
output(multi()) # => [1]
output([1,2]) # => [[1,2]]
output(*[1,2]) # => [1,2]
output(*1) # error! 1 is not an array
output(*multi()) # => ??Eval
- Prohibits Optimization
- Turn it to Keyword
- I’m not sure if this is a good idea
Lambda
- An anonymous function
- Currently arguments are emulated by block parameters
- But they are different
- number check
- optional arguments
- keyword arguments
[number check == arity check?]
Lambda Syntax
? args {…}
Fill ? as you like most.
- lambda(n=5) {…}
- ->(n=5) {…}
- ^(n=5) {…}
- (n=5) {…}
- :(n=5){…}
- .(n=5){…}
- (n=5)->{…}
Dave Thomas suggests def(n=5) {…} Matz suggests y = def(x=5) end Dave suggests lambda(n=5) end be a closure, and def(n=5) end be not.
Annotations
To declare additional attributes of methods, class, etc.
# @require: arg1 >= 10
# @overriding: true
# @visibility: public
def foo(arg1)
...
endTraits
- Mix-in can be Complex Sometimes
- Traits - Mucnh Simpler Solution
- Make Modules More Like Traits
Traits (2)
Traits are a set of methods
- can be included to classes
- can be merged with another trait (+ operator)
- can exclude methods (- operator)
- can rename some methods (rename operation)
T3 = T1 + (T2 - [:foo, :bar])
class Foo
include T3
endT3 would have all method in t1 except for foo and bar, and would put all of these in the class Foo
Traits like Modules
- Merging (+ operator)
- Excluding (via undef)
- Renaming (via alias)
- Duplicate Inclusion
Much Like Traits but Symbolic
Symbolic Inclusion
module Traits
def foo
end
end
class Foo
include Traits
end
module Traits
def bar
end
end
f = Foo.new
f.bar # should be avaliableNamespace
- Open class is Too Dangerous
- Global Modification
Restrict Namespace in a Particular File
Selector Namespace
- or something different
Namespace Example
[involves Japanese characters… the ‘require’ is local to the file?]
Method Combination
a la Common Lisp
- Similar to Aspect Oriented Programming
- Allow before/after/around hook for each method
- No concrete syntax is set
Method Combination Example
class Foo
def foo
p :foo
end
end
class Bar<Foo
def foo:before
p [:foo, :before]
end
def foo:after
p [:foo, :before]
end
end
bar = Bar.new
bar.foo # [:foo, :before], :foo, [:foo, :after](Nestable and stackable)
Method Combination Example (2)
module SomeModule
def initialize:before(*args)
# initialize attributes related to SomeModule
end
...
end
class SomeClass
include SomeModule
...
end
obj = SomeClass.newMultilingualization
- Character Set Independent M17N
- No conversion required
- Unicode is not forced
- Basic implementation is done
- But We Still Need Code Conversion API
- … and some concerns left
- e.g. string literals in extensions
M17N Example
STDIN.encoding = "EUC-JP;UTF-8"
likne = STDIN.gets
p line.encoding # => "UTF-8"
print line.encode("Shift_JIS")Other Wild Ideas
- allow splat (*) in the middle of arguments
- split Module and Class (no inheritance)
- $var as thread-local variable
- BasicObject on top of Object
- caller_binding
- instance_exec
Thank you
Slides will be avaliable at http://www.rubyist.net/~matz/slides/rc2005/ Any questions?
Q: can you explain instance_exec?
A:
instance_exec(1,2,3) { |a,b,c| … }
Sometimes we do want to pass a value to an exec block, because sometimes a block is given from outside. That’s the reason we need instance_exec.
Q: Could we use an equivalent to this which doesn’t change self?
A: … You can say self.instance_eval explicitly.
Q: How do you do instance_exec() today?
A: In the Ruby list someone has defined a method with a random name, then it’s called, then the method name is removed.
Q: When will it be ready?
A: When its ready.
Thank you for enduring the long talk.
Bye now.


Thanks for writing this down!
Original slides now available at http://www.rubyist.net/~matz/slides/rc2005/
in “Keyword Arguments (3)” everywhere you write *keys, while there should’ve been written **keys. At least that is what is on the slides referenced in comment 2. (it didn’t make sense to me the way it is displayed here on your blog so i searched it up).
but hey, i understand it being displayed wrong. had some problems to writing it with the number of * signs i wanted in this comment. that damned * makes words look bold, making it hard to just use it as text..