118
A Ruby-like language for the Erlang VM http://github.com/tarcieri/reia

A Ruby-like language for the Erlang VM

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: A Ruby-like language for the Erlang VM

A Ruby-like language for the Erlang VMhttp://github.com/tarcieri/reia

Page 2: A Ruby-like language for the Erlang VM

Rhymes with Leia...

Page 3: A Ruby-like language for the Erlang VM

...not diarrhea

Page 4: A Ruby-like language for the Erlang VM

What does it mean?

Page 5: A Ruby-like language for the Erlang VM

What does it mean?

•Not named after Princess Leia

Page 6: A Ruby-like language for the Erlang VM

What does it mean?

•Not named after Princess Leia

•An acronym?

Page 7: A Ruby-like language for the Erlang VM

What does it mean?

•Not named after Princess Leia

•An acronym?

•Ruby Erlang something something?

Page 8: A Ruby-like language for the Erlang VM

What does it mean?

•Not named after Princess Leia

•An acronym?

•Ruby Erlang something something?

•It doesn’t mean anything

Page 9: A Ruby-like language for the Erlang VM

What does it mean?

•Not named after Princess Leia

•An acronym?

•Ruby Erlang something something?

•It doesn’t mean anything

•I made it up

Page 10: A Ruby-like language for the Erlang VM

State of Reia

Page 11: A Ruby-like language for the Erlang VM

State of Reia

•One year old (as of May 11th)

Page 12: A Ruby-like language for the Erlang VM

State of Reia

•One year old (as of May 11th)

•Prototype

Page 13: A Ruby-like language for the Erlang VM

State of Reia

•One year old (as of May 11th)

•Prototype

•Nearing alpha-stage

Page 14: A Ruby-like language for the Erlang VM

State of Reia

•One year old (as of May 11th)

•Prototype

•Nearing alpha-stage

•Ready for eager early adopters

Page 15: A Ruby-like language for the Erlang VM

Ruby features you may miss...

Page 16: A Ruby-like language for the Erlang VM

Ruby features you may miss...

•Modifiable core

Page 17: A Ruby-like language for the Erlang VM

Ruby features you may miss...

•Modifiable core

•Monkeypatching

Page 18: A Ruby-like language for the Erlang VM

Ruby features you may miss...

•Modifiable core

•Monkeypatching

•Mutable state

Page 19: A Ruby-like language for the Erlang VM

Ruby features you may miss...

•Modifiable core

•Monkeypatching

•Mutable state

•Everything is an object

Page 20: A Ruby-like language for the Erlang VM

Ruby features you may miss...

•Modifiable core

•Monkeypatching

•Mutable state

•Everything is an object

•Perlisms

Page 21: A Ruby-like language for the Erlang VM

What you get instead

Page 22: A Ruby-like language for the Erlang VM

What you get instead

•Erlang-style concurrency

Page 23: A Ruby-like language for the Erlang VM

What you get instead

•Erlang-style concurrency

•Excellent I/O support

Page 24: A Ruby-like language for the Erlang VM

What you get instead

•Erlang-style concurrency

•Excellent I/O support

•Sane “live update” code swapping

Page 25: A Ruby-like language for the Erlang VM

What you get instead

•Erlang-style concurrency

•Excellent I/O support

•Sane “live update” code swapping

•Pattern matching

Page 26: A Ruby-like language for the Erlang VM

What you get instead

•Erlang-style concurrency

•Excellent I/O support

•Sane “live update” code swapping

•Pattern matching

•List comprehensions

Page 27: A Ruby-like language for the Erlang VM

What you get instead

•Erlang-style concurrency

•Excellent I/O support

•Sane “live update” code swapping

•Pattern matching

•List comprehensions

•Binaries

Page 28: A Ruby-like language for the Erlang VM

Syntax Tour

Page 29: A Ruby-like language for the Erlang VM

No longer indent sensitive!!!

Page 30: A Ruby-like language for the Erlang VM

Syntax example# The Greeter classclass Greeter def initialize(name) @name = name.capitalize() end def salute "Hello #{@name}!".puts() endend

# Create a new objectg = Greeter("world")g.salute()g.kill()

Page 31: A Ruby-like language for the Erlang VM

ListsReia[1,2,3]

[1,2,3,*rest]

Erlang[1,2,3]

[1,2,3|Rest]

Page 32: A Ruby-like language for the Erlang VM

TuplesReia(1,2,3)(1,)()

Erlang{1,2,3}

Page 33: A Ruby-like language for the Erlang VM

AtomsReia:foobar

Erlangfoobar

Page 34: A Ruby-like language for the Erlang VM

Maps (i.e. Dicts)Reia

{:foo=>1,:bar=>2,:baz=>3}

Erlang{dict,3,16,16,8,80,48,...}

Page 35: A Ruby-like language for the Erlang VM

StringsReia

“Hello, #{name}”‘Hello, Robert’

Erlang“Hello, Joe”

Page 36: A Ruby-like language for the Erlang VM

Binaries(Same as Erlang)

<<1,2,3>><<“Foobar”>>

Page 37: A Ruby-like language for the Erlang VM

Regular ExpressionsReia

/fo{2}b[a-z]r/

ErlangN/A

Page 38: A Ruby-like language for the Erlang VM

RangesReia1..10

Erlanglists:seq(1,10) % kinda

Page 39: A Ruby-like language for the Erlang VM

Pattern MatchingReia

(a,b,c)=(1,2,3)

Erlang{A,B,C}={1,2,3}

Page 40: A Ruby-like language for the Erlang VM

BlocksBrace form

[1,2,3].map { |n| n * 2 }

Do/End FormMnesia.transaction do Mnesia.read(:user, id)end

Page 41: A Ruby-like language for the Erlang VM

FunsReia

fn = fun(n) { n + 2 }fn(2)

ErlangFun = fun(N) -> N + 2 end,

Fun(2).

Page 42: A Ruby-like language for the Erlang VM

Function CallsReia

Foobar.baz()

Erlang‘Foobar’:baz().

Page 43: A Ruby-like language for the Erlang VM

Function ReferencesReia

fn = Foo.bazBaz.qux(&fn)

ErlangFn = fun foo:baz/0,

baz:qux(Fn).

Page 44: A Ruby-like language for the Erlang VM

ProcessesReia

pid = Process.spawn(&myfunc)pid ! message

ErlangPid = proc_lib:spawn(fun myfunc/0),

Pid ! Message.

Page 45: A Ruby-like language for the Erlang VM

List ComprehensionsReia

[n * 2 | n in 0..10]

Erlang[N * 2 || N <- lists:seq(0, 10)]

Page 46: A Ruby-like language for the Erlang VM

Object System

Page 47: A Ruby-like language for the Erlang VM

What is OOP?

Page 48: A Ruby-like language for the Erlang VM

What is OOP?

•Messaging

Page 49: A Ruby-like language for the Erlang VM

What is OOP?

•Messaging

•Hidden state

Page 50: A Ruby-like language for the Erlang VM

What is OOP?

•Messaging

•Hidden state

•Polymorphism/inheritance

Page 51: A Ruby-like language for the Erlang VM

Messaging“I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages (so messaging came at the very beginning -- it took a while to see how to do messaging in a programming language efficiently

enough to be useful).”

― Alan Kay, creator of Smalltalk

Page 52: A Ruby-like language for the Erlang VM

Imperative OOP

Page 53: A Ruby-like language for the Erlang VM

Kool-Aid

Page 54: A Ruby-like language for the Erlang VM

•Object

Kool-Aid

Page 55: A Ruby-like language for the Erlang VM

•Object

•Send message

Kool-Aid

Page 56: A Ruby-like language for the Erlang VM

•Object

•Send message

•Invoke method

Kool-Aid

Page 57: A Ruby-like language for the Erlang VM

•Object

•Send message

•Invoke method

Kool-Aid

Page 58: A Ruby-like language for the Erlang VM

•Object

•Send message

•Invoke method

Kool-Aid Reality

Page 59: A Ruby-like language for the Erlang VM

•Object

•Send message

•Invoke method

Kool-Aid

•State

Reality

Page 60: A Ruby-like language for the Erlang VM

•Object

•Send message

•Invoke method

Kool-Aid

•State

•Call function

Reality

Page 61: A Ruby-like language for the Erlang VM

•Object

•Send message

•Invoke method

Kool-Aid

•State

•Call function

•Mutate state

Reality

Page 62: A Ruby-like language for the Erlang VM

•Object

•Send message

•Invoke method

Kool-Aid

•State

•Call function

•Mutate state

Reality

FAIL

Page 63: A Ruby-like language for the Erlang VM

C++ Style OOP

“I made up the term object-oriented, and I can tell you I did not have C++ in mind. ”

― Alan Kay, creator of Smalltalk

Page 64: A Ruby-like language for the Erlang VM

Journey to ReiaSmalltalk

Page 65: A Ruby-like language for the Erlang VM

Journey to ReiaSmalltalk

Actor Model

Page 66: A Ruby-like language for the Erlang VM

Journey to ReiaSmalltalk

Actor Model

Erlang

Page 67: A Ruby-like language for the Erlang VM

Journey to ReiaSmalltalk

Actor Model

Erlang

Ruby

Page 68: A Ruby-like language for the Erlang VM

Journey to ReiaSmalltalk

Actor Model

Erlang

Ruby

Reia

Page 69: A Ruby-like language for the Erlang VM

Reia objects areconcurrent

Page 70: A Ruby-like language for the Erlang VM

Reia objects really communicate with

messages

Page 71: A Ruby-like language for the Erlang VM

Objects aren’t a one-size-fits-all

solution

Page 72: A Ruby-like language for the Erlang VM

Messaging

“95% of the time standard synchronous RPCs will work - but not all the time, that's why it's nice to be able to open up things and muck around at the

message passing level.”

― Joe Armstrong, creator of Erlang

Page 73: A Ruby-like language for the Erlang VM

Defining Classesclass Adder def initialize(n) @n = n end def plus(x) @n + x endend

Page 74: A Ruby-like language for the Erlang VM

Instantiating Classes

Adder.spawn(2)Adder.spawn_link(2)

Adder(2)

>> a = Adder(2)=> #<Adder:0.214.0>

Page 75: A Ruby-like language for the Erlang VM

Invoking MethodsSynchronous (RPC)

a.plus(2)

Asynchronous (Cast)a<-plus(2)

Page 76: A Ruby-like language for the Erlang VM

Inheritance & Polymorphism

Page 77: A Ruby-like language for the Erlang VM

Inheritance

“Coordinating activities involving multiple actors is very difficult. You can't observe anything without its

cooperation/coordination - making ad-hoc reporting or analysis impossible, instead forcing

every actor to participate in each protocol.”

― Rich Hickey, creator of Clojure

Page 78: A Ruby-like language for the Erlang VM

Inheritanceclass Animal def initialize(name) @name = name end def name @name endend

class Cat < Animal def talk 'Meow!' endend

class Dog < Animal def talk 'Woof! Woof!' endend

animals = [Cat('Missy'), Dog('Mr. Bojangles'), Dog('Lassie')]

animals.each do |animal| "#{animal.name()} the #{animal.class()} says: #{animal.talk()}".puts()end

Page 79: A Ruby-like language for the Erlang VM

What’s the catch?

Page 80: A Ruby-like language for the Erlang VM

Garbage Collection

Page 81: A Ruby-like language for the Erlang VM

Garbage Collection

•It doesn’t exist for objects

Page 82: A Ruby-like language for the Erlang VM

Garbage Collection

•It doesn’t exist for objects

•Use linking

Page 83: A Ruby-like language for the Erlang VM

Garbage Collection

•It doesn’t exist for objects

•Use linking

•Use explicit termination

Page 84: A Ruby-like language for the Erlang VM

Garbage Collection

•It doesn’t exist for objects

•Use linking

•Use explicit termination

•Use deterministic finalization strategies

Page 85: A Ruby-like language for the Erlang VM

Garbage Collection

•It doesn’t exist for objects

•Use linking

•Use explicit termination

•Use deterministic finalization strategies

•Use fewer objects

Page 86: A Ruby-like language for the Erlang VM

Circular Calls

Page 87: A Ruby-like language for the Erlang VM

Circular Calls

•Call loops cause deadlocks

Page 88: A Ruby-like language for the Erlang VM

Circular Calls

•Call loops cause deadlocks

•Magical workaround???

Page 89: A Ruby-like language for the Erlang VM

Circular Calls

•Call loops cause deadlocks

•Magical workaround???

•No

Page 90: A Ruby-like language for the Erlang VM

Circular Calls

•Call loops cause deadlocks

•Magical workaround???

•No

•But it can be detected

Page 91: A Ruby-like language for the Erlang VM

Destructive Assignment

Page 92: A Ruby-like language for the Erlang VM

State in Reia is immutable

Page 93: A Ruby-like language for the Erlang VM

Static Single AssignmentReia

a = a + 1

ErlangA1 = A0 + 1.

Page 94: A Ruby-like language for the Erlang VM

Rebind on UpdateReiam = {}

m[:foo] = 42

ErlangD0 = dict:new(),

D1 = dict:store(foo, 42, D0).

Page 95: A Ruby-like language for the Erlang VM

Ruby-style ImmutabilityPure

list.reverse()

“Dangerous”list.reverse!()

Page 96: A Ruby-like language for the Erlang VM

Matz on “Immutable Ruby”

“I have once dreamed of a such language, and had a conclusion that was not Ruby at least, although a

pretty interesting language.”

― Yukihiro “Matz” Matsumoto, Creator of Ruby

Page 97: A Ruby-like language for the Erlang VM

So what?

Page 98: A Ruby-like language for the Erlang VM

Ryan

http://github.com/pirj/ryanhttp://groups.google.com/group/ryan-framework

A Web Framework for ReiaBy Phil Pirozhkov

Page 99: A Ruby-like language for the Erlang VM

Ryan Demo

Page 100: A Ruby-like language for the Erlang VM

Ryan Controllerclass Mail < Controller def new selected = {}.insert(:new, :selected) total = Mailbox.total() values = {} if(@parameters[:error] != nil) to = @parameters[:to] message = @parameters[:message] error = @parameters[:error] values = {}.insert(:to, to).insert(:message, message).insert(:error, error).insert(:error_class, :error) end contents = view('mail/new', values) bindings = {}.insert(:contents, contents).insert(:total, total).insert(:selected, selected) render('home', bindings, []) end

Page 101: A Ruby-like language for the Erlang VM

Retem Template <div id=menu class=float> <a class={selected.home} icon=home href='/app/home'>home<span>general info</span></a> <a class={selected.new} icon=mail_new href='/app/mail/new'>new<span>create message</span></a> <a class={selected.unread} icon=mail_unread href='/app/mail/unread'>unread<span>{total.unread} new messages</span></a> <a class={selected.inbox} icon=mail_inbox href='/app/mail/inbox'>inbox<span>{total.inbox} messages</span></a> <a class={selected.sent} icon=mail_sent href='/app/mail/sent'>sent<span>{total.sent} messages</span></a> <a class={selected.spam} icon=mail_spam href='/app/mail/spam'>spam<span>{total.spam} messages</span></a> <a class={selected.trash} icon=mail_trash href='/app/mail/trash'>trash<span>{total.trash} messages</span></a> </div>

Page 102: A Ruby-like language for the Erlang VM

Future Features

Page 103: A Ruby-like language for the Erlang VM

Immutable Objects

Page 104: A Ruby-like language for the Erlang VM

Immutable Objects•Immutable objects don’t need to be

Erlang processes

Page 105: A Ruby-like language for the Erlang VM

Immutable Objects•Immutable objects don’t need to be

Erlang processes

•Immutable objects can be garbage collected

Page 106: A Ruby-like language for the Erlang VM

Immutable Objects•Immutable objects don’t need to be

Erlang processes

•Immutable objects can be garbage collected

•Almost everything could be an object

Page 107: A Ruby-like language for the Erlang VM

Immutable Objects•Immutable objects don’t need to be

Erlang processes

•Immutable objects can be garbage collected

•Almost everything could be an object

•Immutable objects could tap into “rebind on update”

Page 108: A Ruby-like language for the Erlang VM

Default ArgumentsDeclaration

def foo(bar, baz: 2, qux: 3)

Invocationfoo(1)

Page 109: A Ruby-like language for the Erlang VM

Keyword ArgumentsDeclaration

def foo(bar, baz: 2, qux: 3)

Invocationfoo(1, qux: 4, baz: 3)

Page 110: A Ruby-like language for the Erlang VM

“Splatted” ArgumentsDeclarationdef foo(*list)

Invocationfoo(:foo, :bar, :baz)

foo(*list)

Page 111: A Ruby-like language for the Erlang VM

Namespaces

Page 112: A Ruby-like language for the Erlang VM

Operator Overloading

Page 113: A Ruby-like language for the Erlang VM

instance_eval

Page 114: A Ruby-like language for the Erlang VM

Class Bodies

Page 115: A Ruby-like language for the Erlang VM

Metaclasses

Page 116: A Ruby-like language for the Erlang VM

DSLs

Page 117: A Ruby-like language for the Erlang VM

Reflection

Page 118: A Ruby-like language for the Erlang VM

Links

Github:http://github.com/tarcieri/reia

Main Site:http://reia-lang.org

Blog:http://unlimitednovelty.com

Twitter:http://twitter.com/bascule