SlideShare une entreprise Scribd logo
1  sur  41
Children of Ruby
The different worlds of Elixir and Crystal
Simon St.Laurent
@simonstl
Content Manager, LinkedIn Learning
Where and who?
Where we are
• Portland is in the land of Chinook peoples, including the
Multnomah.
• I wrote most of this along a former trail between the Cayuga and
Onondaga territories of the Haudenosaunee.
Me: a meta-person
• I only write “real code” occasionally, with my last big project in 2012.
• I have spent lots of time in too many languages:
• Usually this is confusing, but sometimes – like today! – it’s helpful.
• ZX81 BASIC
• Applesoft BASIC
• Assembler
• Spreadsheets
• HyperCard
• C
• HTML
• Asymetrix Toolbook
• JavaScript
• CSS
• VBScript, VBA
• XML, XSLT, X*
• SQL
• Java
• Ruby
• Erlang
• Elixir
• Crystal
Educating (I hope)
Most recently
Who else is here?
Ruby is amazing.
Ruby’s priorities
“I want to make Ruby users free. I want to give
them the freedom to choose.”
– Matz, at https://www.artima.com/intv/ruby3.html
“Ruby is designed to make programmers happy.”
– Matz, in The Ruby Programming Language.
Ruby achieved its mission
“I initially fell in love with Ruby because other people’s code was
just easier to read than anything else I’d previously encountered.
You needed to learn what how blocks work and what |foo| means,
then it all just fell into place. Then when, based on that, you
figured out Enumerable, you might have had heart palpitations.”
- Tim Bray
(https://www.tbray.org/ongoing/When/201x/2019/06/12/Go-Creeping-In)
But note the title of that piece “Go Creeping In.”
Why fork?
The Quiet Forks of 2011-2
• No one noticed at the time.
• Rails applications had pushed performance and reliability.
• “Idiomatic Ruby” had mostly stabilized.
• Ruby had avoided the Python 2.x to 3.x drama.
Why Elixir?
“I was doing a lot of work with Ruby, and making Rails thread-safe.
That was my personal pain point, my personal war. I knew the shift
was coming along, we wanted to use all the cores on my machine... it
took us too long to make it thread-safe, literally years...
My original reaction was "there must be a solution to this problem."
Once you go, it's hard to come back. The things that those languages,
Clojure and Erlang, give you...”
- José Valim, May 2016.
https://soundcloud.com/oreilly-radar/jose-valim-interviewed-by-simon-st-laurent
Why Crystal?
“Fast as C, slick as Ruby.”
“Crystal doesn’t allow you to have null pointer exceptions.”
Compilation (with LLVM) yields safety and performance.
Developer happiness and productivity as primary goals.
Two newcomers
• José Valim started Elixir in
2012.
• Project supported by
Platformatec and a growing
community.
• Ary Borenszweig, Juan
Wajnerman, and Brian Cardiff
started Crystal in 2011.
• Project supported by Manas
Technology Solutions and a
growing community.
https://crystal-lang.org/https://elixir-lang.org/
Current status
• 1.0 released in 2014
• 1.9 released this month
• Self-hosting in 2013, first
official release in 2014.
• 0.29.0 released in June.
What’s next
“As mentioned earlier, releases
was the last planned feature for
Elixir. We don’t have any major
user-facing feature in the
works nor planned.”
Major projects yet to come:
• Complete concurrency
• Windows support.
Show me the code?
Elixir tries to be friendlier Erlang
Erlang
-module(count).
-export([countdown/1]).
countdown(From) when From > 0 ->
io:format("~w!~n", [From]),
countdown(From-1);
countdown(From) ->
io:format("blastoff!~n").
Elixir
defmodule Count do
def countdown(from) when from > 0 do
IO.inspect(from)
countdown(from-1)
end
def countdown(from) do
IO.puts("blastoff!")
end
end
Crystal tries to be friendlier C
C (header file elsewhere!)
#include <stdio.h>
void countdown(int count) {
for (int i = count; i > 0; i--) {
printf("%dn",i);
}
printf("Blastoff! n");
}
void main() {
countdown(5);
}
Crystal
def countdown (count)
while (count) > 0
puts count
count -= 1
end
puts("Blastoff!")
end
puts countdown(5)
Sometimes all three can (almost) line up
def fall_velocity(planemo, distance)
gravity = case planemo
when :earth then 9.8
when :moon then 1.6
when :mars
3.71
end
velocity = Math.sqrt(2 * gravity
* distance)
if
velocity == 0 then "stable“
elsif velocity < 5 then "slow“
elsif velocity >= 5 and
velocity < 10
"moving“
elsif velocity >= 10 and
velocity < 20
"fast“
elsif velocity >= 20
"speedy“
end
end
def fall_velocity(planemo : Symbol,
distance : Int32)
gravity = case planemo
when :earth then 9.8
when :moon then 1.6
when :mars then 3.71
else 0
end
velocity = Math.sqrt(2 * gravity *
distance)
if
velocity == 0
"stable"
elsif velocity < 5
"slow"
elsif velocity >= 5 && velocity < 10
"moving"
elsif velocity >= 10 && velocity < 20
"fast"
elsif velocity >= 20
"speedy"
end
end
Ruby Crystal Elixir
def fall_velocity(planemo, distance)
when distance >= 0 do
gravity = case planemo do
:earth -> 9.8
:moon -> 1.6
:mars -> 3.71
end
velocity = :math.sqrt(2 * gravity *
distance)
cond do
velocity == 0 -> "stable"
velocity < 5 -> "slow"
velocity >= 5 and velocity < 10 -
> "moving"
velocity >= 10 and velocity < 20
-> "fast"
velocity >= 20 -> "speedy"
end
end
What changed?
Both of these children
• Add an explicit compilation step.
• BEAM for Elixir
• LLVM for Crystal.
• Trim Ruby syntax to a smaller set, with fewer choices.
• Have Ruby-like ecosystems, with parallel tools for Rails, Sinatra,
testing frameworks, and more.
• Retain Ruby’s emphasis on programmer fun and productivity.
Types are the same but different
Numbers
Boolean
Strings
Hashes
Arrays
Symbols
Closures
Ranges
Objects
integer
floats
booleans
strings
maps
lists
tuples
atoms
anonymous functions
port
Reference
PID
Ruby Elixir Crystal
Integers (8-64, signed & unsigned)
Floats (32 or 64)
Bool
String
Char
Hash
Array
Tuple
NamedTuple
Symbol
Proc
Range
Object
Regex
Command (runs in a subshell)
Nil
Ruby and Crystal and OOP
• “Classical” inheritance-based object approaches.
• A megadose of additional flexibility.
• “Everything is an object.” (Almost.)
• Everything has methods and properties directly available.
Ruby and Crystal support functional
• Ruby:
my_fn = ->(n, m) { n + m }
my_fn.call(4, 3) # => 7
• Crystal:
my_fn = -> (n : Int32, m : Int32) { n + m }
my_fn.call(43, 108) # => 151
Elixir is a more drastic shift
• Yes:
my_fn = fn (n, m) -> n + m end
my_fn.(44, 108) # => 152
• But: no objects, no methods, no properties. (Yes, modules.)
• Everything that does something is a function.
Elixir’s pipe operator
Drop.fall_velocity(meters) |> Convert.mps_to_mph
• Elixir added this syntax sugar early.
• Ruby 2.7 added something like it, but… tricky
• Crystal: “Adding Elixir's pipe operator (|>): in OOP languages we
have methods and self. See #1388…. Please don't insist on these
things because they will never, ever happen.”
Messaging models
• Sending messages is more flexible than calling functions.
• Elixir processes communicate by sending messages to each
other at named endpoints. OTP cranks up that model.
• Crystal uses (green) fibers with channels for communications
between them, in a Communicating Sequential Processes model.
• Difficult to compare, because Crystal isn’t done.
Macros and metaprogramming
• Metaprogramming is a huge part of Ruby’s appeal.
• Both Crystal and Elixir step away from method_missing.
• Crystal still supports monkeypatching, adding new methods to
classes and modules.
• Both Crystal and Elixir offer macros, with warning labels.
What’s in it for me?
Elixir’s large promises
• Dave Thomas: “Programming should be about transforming data.”
• Processes (functions) grow and die lightly.
• OTP supervisors, workers, and a distributed node model.
• Phoenix layers on top of OTP, but feels like Rails.
Crystal’s large promises
• Errors at compile time, not at runtime.
• Compiler disciplines code while keeping it familiar.
• Type inference protects you without cluttering code.
• Compilation gives you the performance you always wanted.
Resilience
Crystal
• Nil won’t break things
• Types ensure reliability
Elixir
• Let it crash
• OTP supervisors and workers
• Update code on the fly
Performance
Crystal
• Tight compilation
• Running close to the metal
• Riding on LLVM
Elixir
• Parallel processing as normal
• Lightweight functions
• Riding on BEAM
So… which one?
Why choose Ruby?
• Mega-metaprogramming
• Vast libraries
• Broad talent pool
Why choose Elixir?
• Parallelism
• Distributed applications
• Uptime
Why choose Crystal?
• Performance on complex tasks
• Runtime reliability
• Application packaging
Please Use It For Good
I’ll let you determine what “good” means, but think
about it.
Please try to use Elixir and Crystal’s powers for
projects that make the world a better place, or at
least not a worse place.
Children of Ruby
The different worlds of Elixir and Crystal
Simon St.Laurent
@simonstl
Content Manager, LinkedIn Learning

Contenu connexe

Tendances

From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scalatod esking
 
Introduction to Kotlin JVM language
Introduction to Kotlin JVM languageIntroduction to Kotlin JVM language
Introduction to Kotlin JVM languageAndrius Klimavicius
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformEastBanc Tachnologies
 
Java 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala StoryJava 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala StoryTomer Gabel
 
Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010ssoroka
 
Node.js Patterns and Opinions
Node.js Patterns and OpinionsNode.js Patterns and Opinions
Node.js Patterns and OpinionsIsaacSchlueter
 
Developing Android applications with Ceylon
Developing Android applications with Ceylon Developing Android applications with Ceylon
Developing Android applications with Ceylon Enrique Zamudio López
 
JavaScript: Creative Coding for Browsers
JavaScript: Creative Coding for BrowsersJavaScript: Creative Coding for Browsers
JavaScript: Creative Coding for Browsersnoweverywhere
 
Java to Scala: Why & How
Java to Scala: Why & HowJava to Scala: Why & How
Java to Scala: Why & HowGraham Tackley
 
TypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without AnnotationsTypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without Annotationsmametter
 
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to ScalaLSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to ScalaGraham Tackley
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumNgoc Dao
 
A Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and UnderstandingA Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and Understandingmametter
 
WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)Igor Khotin
 
Introduction to Scala language
Introduction to Scala languageIntroduction to Scala language
Introduction to Scala languageAaqib Pervaiz
 
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...Thoughtworks
 
Jslab rssh: JS as language platform
Jslab rssh:  JS as language platformJslab rssh:  JS as language platform
Jslab rssh: JS as language platformRuslan Shevchenko
 

Tendances (20)

From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scala
 
Introduction to Kotlin JVM language
Introduction to Kotlin JVM languageIntroduction to Kotlin JVM language
Introduction to Kotlin JVM language
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
 
Java 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala StoryJava 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala Story
 
Coding in kotlin
Coding in kotlinCoding in kotlin
Coding in kotlin
 
Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010
 
Intro to kotlin
Intro to kotlinIntro to kotlin
Intro to kotlin
 
Node.js Patterns and Opinions
Node.js Patterns and OpinionsNode.js Patterns and Opinions
Node.js Patterns and Opinions
 
Developing Android applications with Ceylon
Developing Android applications with Ceylon Developing Android applications with Ceylon
Developing Android applications with Ceylon
 
JavaScript: Creative Coding for Browsers
JavaScript: Creative Coding for BrowsersJavaScript: Creative Coding for Browsers
JavaScript: Creative Coding for Browsers
 
Java to Scala: Why & How
Java to Scala: Why & HowJava to Scala: Why & How
Java to Scala: Why & How
 
TypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without AnnotationsTypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without Annotations
 
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to ScalaLSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
A Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and UnderstandingA Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and Understanding
 
Java to scala
Java to scalaJava to scala
Java to scala
 
WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)
 
Introduction to Scala language
Introduction to Scala languageIntroduction to Scala language
Introduction to Scala language
 
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
 
Jslab rssh: JS as language platform
Jslab rssh:  JS as language platformJslab rssh:  JS as language platform
Jslab rssh: JS as language platform
 

Similaire à Children of Ruby

Charles nutter star techconf 2011 - jvm languages
Charles nutter   star techconf 2011 - jvm languagesCharles nutter   star techconf 2011 - jvm languages
Charles nutter star techconf 2011 - jvm languagesStarTech Conference
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
Not Everything is an Object - Rocksolid Tour 2013
Not Everything is an Object  - Rocksolid Tour 2013Not Everything is an Object  - Rocksolid Tour 2013
Not Everything is an Object - Rocksolid Tour 2013Gary Short
 
#MBLTdev: Уроки, которые мы выучили, создавая Realm
#MBLTdev: Уроки, которые мы выучили, создавая Realm#MBLTdev: Уроки, которые мы выучили, создавая Realm
#MBLTdev: Уроки, которые мы выучили, создавая Realme-Legion
 
Building microservices with Kotlin
Building microservices with KotlinBuilding microservices with Kotlin
Building microservices with KotlinHaim Yadid
 
Trends in programming languages
Trends in programming languagesTrends in programming languages
Trends in programming languagesAntya Dev
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Metosin Oy
 
The Future of Node - @rvagg - NodeConf Christchurch 2015
The Future of Node - @rvagg - NodeConf Christchurch 2015The Future of Node - @rvagg - NodeConf Christchurch 2015
The Future of Node - @rvagg - NodeConf Christchurch 2015rvagg
 
The Transparent Web: Bridging the Chasm in Web Development
The Transparent Web: Bridging the Chasm in Web DevelopmentThe Transparent Web: Bridging the Chasm in Web Development
The Transparent Web: Bridging the Chasm in Web Developmenttwopoint718
 
Rapid Application Development using Ruby on Rails
Rapid Application Development using Ruby on RailsRapid Application Development using Ruby on Rails
Rapid Application Development using Ruby on RailsSimobo
 
Clojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp ProgrammersClojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp Programmerselliando dias
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Henry S
 
Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016
Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016
Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016Codemotion
 
West Coast DevCon 2014: Programming in UE4 - A Quick Orientation for Coders
West Coast DevCon 2014: Programming in UE4 - A Quick Orientation for CodersWest Coast DevCon 2014: Programming in UE4 - A Quick Orientation for Coders
West Coast DevCon 2014: Programming in UE4 - A Quick Orientation for CodersGerke Max Preussner
 
Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014Charles Nutter
 

Similaire à Children of Ruby (20)

Charles nutter star techconf 2011 - jvm languages
Charles nutter   star techconf 2011 - jvm languagesCharles nutter   star techconf 2011 - jvm languages
Charles nutter star techconf 2011 - jvm languages
 
IJTC%202009%20JRuby
IJTC%202009%20JRubyIJTC%202009%20JRuby
IJTC%202009%20JRuby
 
IJTC%202009%20JRuby
IJTC%202009%20JRubyIJTC%202009%20JRuby
IJTC%202009%20JRuby
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Scala Introduction
Scala IntroductionScala Introduction
Scala Introduction
 
Not Everything is an Object - Rocksolid Tour 2013
Not Everything is an Object  - Rocksolid Tour 2013Not Everything is an Object  - Rocksolid Tour 2013
Not Everything is an Object - Rocksolid Tour 2013
 
#MBLTdev: Уроки, которые мы выучили, создавая Realm
#MBLTdev: Уроки, которые мы выучили, создавая Realm#MBLTdev: Уроки, которые мы выучили, создавая Realm
#MBLTdev: Уроки, которые мы выучили, создавая Realm
 
Building microservices with Kotlin
Building microservices with KotlinBuilding microservices with Kotlin
Building microservices with Kotlin
 
Trends in programming languages
Trends in programming languagesTrends in programming languages
Trends in programming languages
 
Why Ruby?
Why Ruby? Why Ruby?
Why Ruby?
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
 
The Future of Node - @rvagg - NodeConf Christchurch 2015
The Future of Node - @rvagg - NodeConf Christchurch 2015The Future of Node - @rvagg - NodeConf Christchurch 2015
The Future of Node - @rvagg - NodeConf Christchurch 2015
 
The Transparent Web: Bridging the Chasm in Web Development
The Transparent Web: Bridging the Chasm in Web DevelopmentThe Transparent Web: Bridging the Chasm in Web Development
The Transparent Web: Bridging the Chasm in Web Development
 
Why ruby and rails
Why ruby and railsWhy ruby and rails
Why ruby and rails
 
Rapid Application Development using Ruby on Rails
Rapid Application Development using Ruby on RailsRapid Application Development using Ruby on Rails
Rapid Application Development using Ruby on Rails
 
Clojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp ProgrammersClojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp Programmers
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
 
Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016
Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016
Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016
 
West Coast DevCon 2014: Programming in UE4 - A Quick Orientation for Coders
West Coast DevCon 2014: Programming in UE4 - A Quick Orientation for CodersWest Coast DevCon 2014: Programming in UE4 - A Quick Orientation for Coders
West Coast DevCon 2014: Programming in UE4 - A Quick Orientation for Coders
 
Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014
 

Dernier

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Dernier (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Children of Ruby

  • 1. Children of Ruby The different worlds of Elixir and Crystal Simon St.Laurent @simonstl Content Manager, LinkedIn Learning
  • 3. Where we are • Portland is in the land of Chinook peoples, including the Multnomah. • I wrote most of this along a former trail between the Cayuga and Onondaga territories of the Haudenosaunee.
  • 4. Me: a meta-person • I only write “real code” occasionally, with my last big project in 2012. • I have spent lots of time in too many languages: • Usually this is confusing, but sometimes – like today! – it’s helpful. • ZX81 BASIC • Applesoft BASIC • Assembler • Spreadsheets • HyperCard • C • HTML • Asymetrix Toolbook • JavaScript • CSS • VBScript, VBA • XML, XSLT, X* • SQL • Java • Ruby • Erlang • Elixir • Crystal
  • 7. Who else is here?
  • 9. Ruby’s priorities “I want to make Ruby users free. I want to give them the freedom to choose.” – Matz, at https://www.artima.com/intv/ruby3.html “Ruby is designed to make programmers happy.” – Matz, in The Ruby Programming Language.
  • 10. Ruby achieved its mission “I initially fell in love with Ruby because other people’s code was just easier to read than anything else I’d previously encountered. You needed to learn what how blocks work and what |foo| means, then it all just fell into place. Then when, based on that, you figured out Enumerable, you might have had heart palpitations.” - Tim Bray (https://www.tbray.org/ongoing/When/201x/2019/06/12/Go-Creeping-In) But note the title of that piece “Go Creeping In.”
  • 12. The Quiet Forks of 2011-2 • No one noticed at the time. • Rails applications had pushed performance and reliability. • “Idiomatic Ruby” had mostly stabilized. • Ruby had avoided the Python 2.x to 3.x drama.
  • 13. Why Elixir? “I was doing a lot of work with Ruby, and making Rails thread-safe. That was my personal pain point, my personal war. I knew the shift was coming along, we wanted to use all the cores on my machine... it took us too long to make it thread-safe, literally years... My original reaction was "there must be a solution to this problem." Once you go, it's hard to come back. The things that those languages, Clojure and Erlang, give you...” - José Valim, May 2016. https://soundcloud.com/oreilly-radar/jose-valim-interviewed-by-simon-st-laurent
  • 14. Why Crystal? “Fast as C, slick as Ruby.” “Crystal doesn’t allow you to have null pointer exceptions.” Compilation (with LLVM) yields safety and performance. Developer happiness and productivity as primary goals.
  • 15. Two newcomers • José Valim started Elixir in 2012. • Project supported by Platformatec and a growing community. • Ary Borenszweig, Juan Wajnerman, and Brian Cardiff started Crystal in 2011. • Project supported by Manas Technology Solutions and a growing community. https://crystal-lang.org/https://elixir-lang.org/
  • 16. Current status • 1.0 released in 2014 • 1.9 released this month • Self-hosting in 2013, first official release in 2014. • 0.29.0 released in June.
  • 17. What’s next “As mentioned earlier, releases was the last planned feature for Elixir. We don’t have any major user-facing feature in the works nor planned.” Major projects yet to come: • Complete concurrency • Windows support.
  • 18. Show me the code?
  • 19. Elixir tries to be friendlier Erlang Erlang -module(count). -export([countdown/1]). countdown(From) when From > 0 -> io:format("~w!~n", [From]), countdown(From-1); countdown(From) -> io:format("blastoff!~n"). Elixir defmodule Count do def countdown(from) when from > 0 do IO.inspect(from) countdown(from-1) end def countdown(from) do IO.puts("blastoff!") end end
  • 20. Crystal tries to be friendlier C C (header file elsewhere!) #include <stdio.h> void countdown(int count) { for (int i = count; i > 0; i--) { printf("%dn",i); } printf("Blastoff! n"); } void main() { countdown(5); } Crystal def countdown (count) while (count) > 0 puts count count -= 1 end puts("Blastoff!") end puts countdown(5)
  • 21. Sometimes all three can (almost) line up def fall_velocity(planemo, distance) gravity = case planemo when :earth then 9.8 when :moon then 1.6 when :mars 3.71 end velocity = Math.sqrt(2 * gravity * distance) if velocity == 0 then "stable“ elsif velocity < 5 then "slow“ elsif velocity >= 5 and velocity < 10 "moving“ elsif velocity >= 10 and velocity < 20 "fast“ elsif velocity >= 20 "speedy“ end end def fall_velocity(planemo : Symbol, distance : Int32) gravity = case planemo when :earth then 9.8 when :moon then 1.6 when :mars then 3.71 else 0 end velocity = Math.sqrt(2 * gravity * distance) if velocity == 0 "stable" elsif velocity < 5 "slow" elsif velocity >= 5 && velocity < 10 "moving" elsif velocity >= 10 && velocity < 20 "fast" elsif velocity >= 20 "speedy" end end Ruby Crystal Elixir def fall_velocity(planemo, distance) when distance >= 0 do gravity = case planemo do :earth -> 9.8 :moon -> 1.6 :mars -> 3.71 end velocity = :math.sqrt(2 * gravity * distance) cond do velocity == 0 -> "stable" velocity < 5 -> "slow" velocity >= 5 and velocity < 10 - > "moving" velocity >= 10 and velocity < 20 -> "fast" velocity >= 20 -> "speedy" end end
  • 23. Both of these children • Add an explicit compilation step. • BEAM for Elixir • LLVM for Crystal. • Trim Ruby syntax to a smaller set, with fewer choices. • Have Ruby-like ecosystems, with parallel tools for Rails, Sinatra, testing frameworks, and more. • Retain Ruby’s emphasis on programmer fun and productivity.
  • 24. Types are the same but different Numbers Boolean Strings Hashes Arrays Symbols Closures Ranges Objects integer floats booleans strings maps lists tuples atoms anonymous functions port Reference PID Ruby Elixir Crystal Integers (8-64, signed & unsigned) Floats (32 or 64) Bool String Char Hash Array Tuple NamedTuple Symbol Proc Range Object Regex Command (runs in a subshell) Nil
  • 25. Ruby and Crystal and OOP • “Classical” inheritance-based object approaches. • A megadose of additional flexibility. • “Everything is an object.” (Almost.) • Everything has methods and properties directly available.
  • 26. Ruby and Crystal support functional • Ruby: my_fn = ->(n, m) { n + m } my_fn.call(4, 3) # => 7 • Crystal: my_fn = -> (n : Int32, m : Int32) { n + m } my_fn.call(43, 108) # => 151
  • 27. Elixir is a more drastic shift • Yes: my_fn = fn (n, m) -> n + m end my_fn.(44, 108) # => 152 • But: no objects, no methods, no properties. (Yes, modules.) • Everything that does something is a function.
  • 28. Elixir’s pipe operator Drop.fall_velocity(meters) |> Convert.mps_to_mph • Elixir added this syntax sugar early. • Ruby 2.7 added something like it, but… tricky • Crystal: “Adding Elixir's pipe operator (|>): in OOP languages we have methods and self. See #1388…. Please don't insist on these things because they will never, ever happen.”
  • 29. Messaging models • Sending messages is more flexible than calling functions. • Elixir processes communicate by sending messages to each other at named endpoints. OTP cranks up that model. • Crystal uses (green) fibers with channels for communications between them, in a Communicating Sequential Processes model. • Difficult to compare, because Crystal isn’t done.
  • 30. Macros and metaprogramming • Metaprogramming is a huge part of Ruby’s appeal. • Both Crystal and Elixir step away from method_missing. • Crystal still supports monkeypatching, adding new methods to classes and modules. • Both Crystal and Elixir offer macros, with warning labels.
  • 31. What’s in it for me?
  • 32. Elixir’s large promises • Dave Thomas: “Programming should be about transforming data.” • Processes (functions) grow and die lightly. • OTP supervisors, workers, and a distributed node model. • Phoenix layers on top of OTP, but feels like Rails.
  • 33. Crystal’s large promises • Errors at compile time, not at runtime. • Compiler disciplines code while keeping it familiar. • Type inference protects you without cluttering code. • Compilation gives you the performance you always wanted.
  • 34. Resilience Crystal • Nil won’t break things • Types ensure reliability Elixir • Let it crash • OTP supervisors and workers • Update code on the fly
  • 35. Performance Crystal • Tight compilation • Running close to the metal • Riding on LLVM Elixir • Parallel processing as normal • Lightweight functions • Riding on BEAM
  • 37. Why choose Ruby? • Mega-metaprogramming • Vast libraries • Broad talent pool
  • 38. Why choose Elixir? • Parallelism • Distributed applications • Uptime
  • 39. Why choose Crystal? • Performance on complex tasks • Runtime reliability • Application packaging
  • 40. Please Use It For Good I’ll let you determine what “good” means, but think about it. Please try to use Elixir and Crystal’s powers for projects that make the world a better place, or at least not a worse place.
  • 41. Children of Ruby The different worlds of Elixir and Crystal Simon St.Laurent @simonstl Content Manager, LinkedIn Learning

Notes de l'éditeur

  1. I’m also primarily a Web person.
  2. You should be suspicious of me for covering this much territory.
  3. Rubyists? People who have used Elixir? All the time? Crystal? All the time? Web-focused? Love dynamic languages? Like your types strong and static?
  4. while porting the Crystal parser from Ruby to Crystal, Crystal refused to compile because of a possible null pointer exception. And it was correct. So in a way, Crystal found a bug in itself :-)
  5. 1.10 next for Elixir, point releases roughly every six months.
  6. All three languages are generally readable by someone who knows any one of them.
  7. MINASWAN continues in both places. Also, like Ruby, origins outside the US and Europe – both have Latin American roots. gems, shards, hex Rails / Amber / Phoenix
  8. Elixir supports tools for additional type annotations. Crystal’s list is abbreviated by not giving all the Int and Float types their own lines.
  9. Both languages have monkey patching, but Crystal uses method overloading rather than method shadowing.
  10. Ruby has been a school for functional programming for decades, bridging object-oriented expectations with functional capabilities. Crystal continues that tradition with a similar mix. These are the simplest approaches – you can also capture blocks, etc. Both Crystal and Ruby also support multiple mechanisms for defining lambdas and procs. Crystal removes lambda vs. proc distinction Neither, though, reliably supports tail call optimization.
  11. Note guards and pattern matching as superpowered function signatures. Ruby syntax makes Erlang message-passing foundations more digestible.
  12. Pipes only apply to the first argument of a function, so you’ll need to structure your functions to play nicely with pipes if you want to use this extensively.
  13. Be grateful that none of these use shared memory, an especially common temptation in C-related languages. No locks, either! CSP means that channels are set up between specific fibers rather than a general message-passing clearing house, and also requires receivers to be listening. Probably more solid in single system environments, but hard to share across nodes.
  14. SO WHERE DOES THIS TAKE US?
  15. The biggest problem with OTP is that it sounds like impossible ridiculous magic when you describe it to someone who hasn’t worked with it before. “Open Telecom Platform whatever!” is a common response. Give Nerves for IoT a shout-out.
  16. The biggest problem with OTP is that it sounds like impossible ridiculous magic when you describe it to someone who hasn’t worked with it before. “Open Telecom Platform whatever!” is a common response.
  17. Or just because you like its mix of functional approach and practical deployability.
  18. Or just because you like its mix of functional approach and practical deployability.
  19. Also simple familiarity – doesn’t just look like Ruby, but mostly behaves like it.
  20. MINASWAN continues in both places. Also, like Ruby, origins outside the US and Europe – both have Latin American roots.