SlideShare une entreprise Scribd logo
1  sur  27
Ruby for C#-ers
       Thomas Lundström, Softhouse

Scandinavian Developer Conference, Göteborg
               March 17, 2010
Agenda
• What is Ruby?
• How does the
  language work?
• IronRuby specifics
• Where to apply
  IronRuby?
                      http://www.flickr.com/photos/puntodevista/84796578/
Agenda
• What is Ruby?
• How does the
  language work?
• IronRuby specifics
• Where to apply
  IronRuby?
                      http://www.flickr.com/photos/puntodevista/84796578/
What is Ruby?               Ruby was created in the 90’s by Matz, Yukihiro
                            Matsumoto

                            For those of you who haven’t touched any ruby code
                            at all:

                            Pure object-oriented (everything’s an object)

                            Interpreted, Dynamic


                            Runs in different VM:s
                                MRI
                                JRuby
                                MacRuby
                                MagLev
                                IronRuby

                            No real specification, defined by MRI
                            But: RubySpec: http:/ /blog.rubybestpractices.com/
                            posts/gregory/006-brian-ford-rubyspec.html is
                            coming along




                            TODO: fyll på här




http://www.wordle.net/show/wrdl/1665715/What_is_Ruby%3F
What is Ruby?                               Ruby was created in the 90’s by Matz, Yukihiro
                                            Matsumoto

                                            For those of you who haven’t touched any ruby code
                                            at all:

                                            Pure object-oriented (everything’s an object)

                                            Interpreted, Dynamic


                                            Runs in different VM:s
                                                MRI
                                                JRuby
                                                MacRuby
                                                MagLev
                                                IronRuby

                                            No real specification, defined by MRI
                                            But: RubySpec: http:/ /blog.rubybestpractices.com/
                                            posts/gregory/006-brian-ford-rubyspec.html is
                                            coming along




http://www.wordle.net/show/wrdl/1665715/What_is_Ruby%3F
MRI is Open Source



        What is Ruby?
                              All other VM:s OSS as well

                              Gems
                              * Pre-packaged open source components
                                   - For Java devs, similar to mvn (on steroids)
                                   - infrastructure (e.g. aws gems)
                                   - domain logic (e.g. aasm, state machine impl)
                                   - resolves dependencies
                                   - gem install <gem-name>
                                   - Incredibly easy to share and use other developers’
                                   code

                              irb - a REPL (Read, Eval, Print, Loop)

                              In a transition, 1.8 to 1.9



• Open Source
                              1.9 main feature: Multilingualization support




• Comes with a REPL
• Transition 1.8 to 1.9 (Multilingualization)
Agenda
• What is Ruby?
• How does the
  language work?
• IronRuby specifics
• Where to apply
  IronRuby?
                      http://www.flickr.com/photos/puntodevista/84796578/
Hello world   Demo: “ir.exe 001_HelloWorld.rb”

                       Take-away:
                       1. You don’t have to use

                       public void main(string [] args) {
                            //code
                       }

                       2. You don’t have to use parenthesizes if the interpreter understands
                       your code
                       puts(“Hello World”)




• puts “Hello World”
Control structure
                             if condition
                                   do_stuff
                             end

                             do_stuff if condition




• if/else/elsif
                             do_stuff unless condition




• unless
• Switching places on if/unless and result
Everything’s an Object
                  no need for boxing/unboxing
                  everything is nullable (nil’able)

                  a=3
                  puts a.class
                  a = nil
                  puts a.class
                  puts a.class.ancestors




• Even numbers!
Blocks
                               Compared to Lambdas in C#:
                               * no add-on
                               * most API:s support blocks
                               * The culture is to use blocks/lambdas whenever
                               possible
                               * (It’s getting better in .NET land, though)

                               a.each do |item|
                                do_stuff if (item%2 == 1)
                               end




• API:s use blocks as a first-class citizen
Loops
                              for i in 1..10 do
                              can be replaced with
                              (1..10).each do |i|




• Not used as much as in C#
Classes and methods
                              class MyClass
                              def method(param=1)
                              puts param
                              end
                              end

                              c = MyClass.new
                              c.method # => 1
                              c.method(2) # => 2


• No curlies
• Default method parameters
• All classes are open for modification
Mixins         Mixins can be used to implement
                              Reenskaug’s/Coplien’s DCI

                              module MyMod
                              def mod_method
                              puts "from module"
                              end
                              end

                              c.extend MyMod
                              c.mod_method # => “from module”

                              class OtherClass
                              include MyMod
                              end

                              o = OtherClass.new
                              o.mod_method


• Adds behaviour to classes
Metaprogramming

                         Super-simple to implement an internal DSL by using
                         meta programming

                         Rails use this a lot (:has_many etc)

                         Demo: Show the SubscriptionDeals DSL


• Used to create internal DSL:s
Agenda
• What is Ruby?
• How does the
  language work?
• IronRuby specifics
• Where to apply
  IronRuby?
                      http://www.flickr.com/photos/puntodevista/84796578/
DLR

Ruby
       DLR is a layer that makes it
       possible to run dynamic,
       interpreted languages

       IronRuby runs in interpreted mode
DLR    at first, but later it’s JIT’ed




CLR
Calling Ruby from C#

• Separate AppDomain           If you want to run Ruby from your



• ScriptRuntime (in same AppDomain)
                               own apps

                               3 different ways of hosting the DLR
                               (and ruby code) from your own C#
                               code


• ScriptScope                  The higher in the list, the more isolated
                               (and heavyweight)
Calling C# from Ruby

                       Add reference = require a dll

                       Search rules:
                           The current folder
                           IronRuby bin folder
                           GAC


• Very similar to C#   require ‘System.Windows.Forms’ = add reference
                       include System::Windows::Forms = using ...
Putting it all together
• Hosting an IronRuby DSL from C#
         Subscription.App (C#)


              DSL (Ruby)


          Domain Model (C#)
Agenda
• What is Ruby?
• How does the
  language work?
• IronRuby specifics
• Where to apply
  IronRuby?
                      http://www.flickr.com/photos/puntodevista/84796578/
Web
                            Ruby on Rails
                            - the big reason ruby is so popular

                            For light-weight web solutions (some json etc): Sinatra




http://rubyonrails.org/                       http://www.sinatrarb.com
DSL:s
                            Using ruby in a subset of
                            the product

                            -if reqs often change and
                            we can’t wait for a re-
                            deploy e.g. rules engine
                            for a stock-trading app




• Internal DSL:s + Ruby = a treat
Testing


          RSpec for unit-level tests
          Cucumber for acceptance tests
          Some of you may have already seen
          cucumber
Build environment
            Rake is a DSL for dependency and build
            management

            There are a number of toolkits for building
            C# solutions in Rake, e.g. Albacore

            For an introduction, see Martin Fowler’s
            article about rake, http://
            martinfowler.com/articles/rake.html
IronRuby drawbacks    i.e. don’t use IronRuby for high-performant systems




• Performance
 • Throughput
 • Start-up (latency)
Thanks!

• Thomas Lundström, Softhouse
• thomas.lundstrom@softhouse.se
• Twitter: @thomaslundstrom
• http://blog.thomaslundstrom.com

Contenu connexe

Tendances

JRuby in Java Projects
JRuby in Java ProjectsJRuby in Java Projects
JRuby in Java Projectsjazzman1980
 
Ruby an overall approach
Ruby an overall approachRuby an overall approach
Ruby an overall approachFelipe Schmitt
 
Annotations in PHP: They Exist
Annotations in PHP: They ExistAnnotations in PHP: They Exist
Annotations in PHP: They ExistRafael Dohms
 
CommonJS Everywhere (Wakanday 2011)
CommonJS Everywhere (Wakanday 2011)CommonJS Everywhere (Wakanday 2011)
CommonJS Everywhere (Wakanday 2011)cadorn
 
What is new and cool j2se & java
What is new and cool j2se & javaWhat is new and cool j2se & java
What is new and cool j2se & javaEugene Bogaart
 
Open Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMTom Lee
 
Java and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platformsIlio Catallo
 
Distributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIDistributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIelliando dias
 
Core java lessons
Core java lessonsCore java lessons
Core java lessonsvivek shah
 
Invokedynamic in 45 Minutes
Invokedynamic in 45 MinutesInvokedynamic in 45 Minutes
Invokedynamic in 45 MinutesCharles Nutter
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Rubykim.mens
 
New c sharp4_features_part_vi
New c sharp4_features_part_viNew c sharp4_features_part_vi
New c sharp4_features_part_viNico Ludwig
 
Page List & Sample Material (Repaired)
Page List & Sample Material (Repaired)Page List & Sample Material (Repaired)
Page List & Sample Material (Repaired)Muhammad Haseeb Shahid
 
Introduction to java
Introduction to java Introduction to java
Introduction to java Sandeep Rawat
 

Tendances (18)

Introduction to JAVA
Introduction to JAVAIntroduction to JAVA
Introduction to JAVA
 
JRuby in Java Projects
JRuby in Java ProjectsJRuby in Java Projects
JRuby in Java Projects
 
Ruby an overall approach
Ruby an overall approachRuby an overall approach
Ruby an overall approach
 
Annotations in PHP: They Exist
Annotations in PHP: They ExistAnnotations in PHP: They Exist
Annotations in PHP: They Exist
 
CommonJS Everywhere (Wakanday 2011)
CommonJS Everywhere (Wakanday 2011)CommonJS Everywhere (Wakanday 2011)
CommonJS Everywhere (Wakanday 2011)
 
Introducing Java 7
Introducing Java 7Introducing Java 7
Introducing Java 7
 
What is new and cool j2se & java
What is new and cool j2se & javaWhat is new and cool j2se & java
What is new and cool j2se & java
 
Open Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVM
 
Iq rails
Iq railsIq rails
Iq rails
 
Dvm
DvmDvm
Dvm
 
Java and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platforms
 
Distributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIDistributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMI
 
Core java lessons
Core java lessonsCore java lessons
Core java lessons
 
Invokedynamic in 45 Minutes
Invokedynamic in 45 MinutesInvokedynamic in 45 Minutes
Invokedynamic in 45 Minutes
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
New c sharp4_features_part_vi
New c sharp4_features_part_viNew c sharp4_features_part_vi
New c sharp4_features_part_vi
 
Page List & Sample Material (Repaired)
Page List & Sample Material (Repaired)Page List & Sample Material (Repaired)
Page List & Sample Material (Repaired)
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 

Similaire à Ruby for C#-ers Guide

Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mrubyHiroshi SHIBATA
 
MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?Joshua Ballanco
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012rivierarb
 
Top 10+ Things .NET Developers Should Know About Ruby
Top 10+ Things .NET Developers Should Know About RubyTop 10+ Things .NET Developers Should Know About Ruby
Top 10+ Things .NET Developers Should Know About RubyJeff Cohen
 
Ruby on Rails : First Mile
Ruby on Rails : First MileRuby on Rails : First Mile
Ruby on Rails : First MileGourab Mitra
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLBarry Jones
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRubyelliando dias
 
Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02sagaroceanic11
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRubyajuckel
 
MacRuby & HotCocoa
MacRuby & HotCocoaMacRuby & HotCocoa
MacRuby & HotCocoaThilo Utke
 
Devoxx%202008%20Tutorial
Devoxx%202008%20TutorialDevoxx%202008%20Tutorial
Devoxx%202008%20Tutorialtutorialsruby
 
Devoxx%202008%20Tutorial
Devoxx%202008%20TutorialDevoxx%202008%20Tutorial
Devoxx%202008%20Tutorialtutorialsruby
 

Similaire à Ruby for C#-ers Guide (20)

Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mruby
 
ruby-cocoa
ruby-cocoaruby-cocoa
ruby-cocoa
 
ruby-cocoa
ruby-cocoaruby-cocoa
ruby-cocoa
 
MacRuby
MacRubyMacRuby
MacRuby
 
MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
 
Top 10+ Things .NET Developers Should Know About Ruby
Top 10+ Things .NET Developers Should Know About RubyTop 10+ Things .NET Developers Should Know About Ruby
Top 10+ Things .NET Developers Should Know About Ruby
 
Ruby on Rails : First Mile
Ruby on Rails : First MileRuby on Rails : First Mile
Ruby on Rails : First Mile
 
IJTC%202009%20JRuby
IJTC%202009%20JRubyIJTC%202009%20JRuby
IJTC%202009%20JRuby
 
IJTC%202009%20JRuby
IJTC%202009%20JRubyIJTC%202009%20JRuby
IJTC%202009%20JRuby
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Why Ruby?
Why Ruby? Why Ruby?
Why Ruby?
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRuby
 
Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRuby
 
Ruby Metaprogramming 08
Ruby Metaprogramming 08Ruby Metaprogramming 08
Ruby Metaprogramming 08
 
MacRuby & HotCocoa
MacRuby & HotCocoaMacRuby & HotCocoa
MacRuby & HotCocoa
 
Devoxx%202008%20Tutorial
Devoxx%202008%20TutorialDevoxx%202008%20Tutorial
Devoxx%202008%20Tutorial
 
Devoxx%202008%20Tutorial
Devoxx%202008%20TutorialDevoxx%202008%20Tutorial
Devoxx%202008%20Tutorial
 
How DSL works on Ruby
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
 

Plus de Thomas Lundström

Using RequireJS for Modular JavaScript Code
Using RequireJS for Modular JavaScript CodeUsing RequireJS for Modular JavaScript Code
Using RequireJS for Modular JavaScript CodeThomas Lundström
 
Railsify your web development
Railsify your web developmentRailsify your web development
Railsify your web developmentThomas Lundström
 
Bdd for Web Applications at TelecomCity DevCon 2010
Bdd for Web Applications at TelecomCity DevCon 2010Bdd for Web Applications at TelecomCity DevCon 2010
Bdd for Web Applications at TelecomCity DevCon 2010Thomas Lundström
 
Bdd For Web Applications from Scandinavian Developer Conference 2010
Bdd For Web Applications from Scandinavian Developer Conference 2010Bdd For Web Applications from Scandinavian Developer Conference 2010
Bdd For Web Applications from Scandinavian Developer Conference 2010Thomas Lundström
 
BDD approaches for web development at Agile Testing Days 2009
BDD approaches for web development at Agile Testing Days 2009BDD approaches for web development at Agile Testing Days 2009
BDD approaches for web development at Agile Testing Days 2009Thomas Lundström
 

Plus de Thomas Lundström (6)

Using RequireJS for Modular JavaScript Code
Using RequireJS for Modular JavaScript CodeUsing RequireJS for Modular JavaScript Code
Using RequireJS for Modular JavaScript Code
 
Railsify your web development
Railsify your web developmentRailsify your web development
Railsify your web development
 
Bdd for Web Applications at TelecomCity DevCon 2010
Bdd for Web Applications at TelecomCity DevCon 2010Bdd for Web Applications at TelecomCity DevCon 2010
Bdd for Web Applications at TelecomCity DevCon 2010
 
Bdd For Web Applications from Scandinavian Developer Conference 2010
Bdd For Web Applications from Scandinavian Developer Conference 2010Bdd For Web Applications from Scandinavian Developer Conference 2010
Bdd For Web Applications from Scandinavian Developer Conference 2010
 
BDD approaches for web development at Agile Testing Days 2009
BDD approaches for web development at Agile Testing Days 2009BDD approaches for web development at Agile Testing Days 2009
BDD approaches for web development at Agile Testing Days 2009
 
Cucumber mot .NET-kod
Cucumber mot .NET-kodCucumber mot .NET-kod
Cucumber mot .NET-kod
 

Dernier

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Dernier (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

Ruby for C#-ers Guide

  • 1. Ruby for C#-ers Thomas Lundström, Softhouse Scandinavian Developer Conference, Göteborg March 17, 2010
  • 2. Agenda • What is Ruby? • How does the language work? • IronRuby specifics • Where to apply IronRuby? http://www.flickr.com/photos/puntodevista/84796578/
  • 3. Agenda • What is Ruby? • How does the language work? • IronRuby specifics • Where to apply IronRuby? http://www.flickr.com/photos/puntodevista/84796578/
  • 4. What is Ruby? Ruby was created in the 90’s by Matz, Yukihiro Matsumoto For those of you who haven’t touched any ruby code at all: Pure object-oriented (everything’s an object) Interpreted, Dynamic Runs in different VM:s MRI JRuby MacRuby MagLev IronRuby No real specification, defined by MRI But: RubySpec: http:/ /blog.rubybestpractices.com/ posts/gregory/006-brian-ford-rubyspec.html is coming along TODO: fyll på här http://www.wordle.net/show/wrdl/1665715/What_is_Ruby%3F
  • 5. What is Ruby? Ruby was created in the 90’s by Matz, Yukihiro Matsumoto For those of you who haven’t touched any ruby code at all: Pure object-oriented (everything’s an object) Interpreted, Dynamic Runs in different VM:s MRI JRuby MacRuby MagLev IronRuby No real specification, defined by MRI But: RubySpec: http:/ /blog.rubybestpractices.com/ posts/gregory/006-brian-ford-rubyspec.html is coming along http://www.wordle.net/show/wrdl/1665715/What_is_Ruby%3F
  • 6. MRI is Open Source What is Ruby? All other VM:s OSS as well Gems * Pre-packaged open source components - For Java devs, similar to mvn (on steroids) - infrastructure (e.g. aws gems) - domain logic (e.g. aasm, state machine impl) - resolves dependencies - gem install <gem-name> - Incredibly easy to share and use other developers’ code irb - a REPL (Read, Eval, Print, Loop) In a transition, 1.8 to 1.9 • Open Source 1.9 main feature: Multilingualization support • Comes with a REPL • Transition 1.8 to 1.9 (Multilingualization)
  • 7. Agenda • What is Ruby? • How does the language work? • IronRuby specifics • Where to apply IronRuby? http://www.flickr.com/photos/puntodevista/84796578/
  • 8. Hello world Demo: “ir.exe 001_HelloWorld.rb” Take-away: 1. You don’t have to use public void main(string [] args) { //code } 2. You don’t have to use parenthesizes if the interpreter understands your code puts(“Hello World”) • puts “Hello World”
  • 9. Control structure if condition do_stuff end do_stuff if condition • if/else/elsif do_stuff unless condition • unless • Switching places on if/unless and result
  • 10. Everything’s an Object no need for boxing/unboxing everything is nullable (nil’able) a=3 puts a.class a = nil puts a.class puts a.class.ancestors • Even numbers!
  • 11. Blocks Compared to Lambdas in C#: * no add-on * most API:s support blocks * The culture is to use blocks/lambdas whenever possible * (It’s getting better in .NET land, though) a.each do |item| do_stuff if (item%2 == 1) end • API:s use blocks as a first-class citizen
  • 12. Loops for i in 1..10 do can be replaced with (1..10).each do |i| • Not used as much as in C#
  • 13. Classes and methods class MyClass def method(param=1) puts param end end c = MyClass.new c.method # => 1 c.method(2) # => 2 • No curlies • Default method parameters • All classes are open for modification
  • 14. Mixins Mixins can be used to implement Reenskaug’s/Coplien’s DCI module MyMod def mod_method puts "from module" end end c.extend MyMod c.mod_method # => “from module” class OtherClass include MyMod end o = OtherClass.new o.mod_method • Adds behaviour to classes
  • 15. Metaprogramming Super-simple to implement an internal DSL by using meta programming Rails use this a lot (:has_many etc) Demo: Show the SubscriptionDeals DSL • Used to create internal DSL:s
  • 16. Agenda • What is Ruby? • How does the language work? • IronRuby specifics • Where to apply IronRuby? http://www.flickr.com/photos/puntodevista/84796578/
  • 17. DLR Ruby DLR is a layer that makes it possible to run dynamic, interpreted languages IronRuby runs in interpreted mode DLR at first, but later it’s JIT’ed CLR
  • 18. Calling Ruby from C# • Separate AppDomain If you want to run Ruby from your • ScriptRuntime (in same AppDomain) own apps 3 different ways of hosting the DLR (and ruby code) from your own C# code • ScriptScope The higher in the list, the more isolated (and heavyweight)
  • 19. Calling C# from Ruby Add reference = require a dll Search rules: The current folder IronRuby bin folder GAC • Very similar to C# require ‘System.Windows.Forms’ = add reference include System::Windows::Forms = using ...
  • 20. Putting it all together • Hosting an IronRuby DSL from C# Subscription.App (C#) DSL (Ruby) Domain Model (C#)
  • 21. Agenda • What is Ruby? • How does the language work? • IronRuby specifics • Where to apply IronRuby? http://www.flickr.com/photos/puntodevista/84796578/
  • 22. Web Ruby on Rails - the big reason ruby is so popular For light-weight web solutions (some json etc): Sinatra http://rubyonrails.org/ http://www.sinatrarb.com
  • 23. DSL:s Using ruby in a subset of the product -if reqs often change and we can’t wait for a re- deploy e.g. rules engine for a stock-trading app • Internal DSL:s + Ruby = a treat
  • 24. Testing RSpec for unit-level tests Cucumber for acceptance tests Some of you may have already seen cucumber
  • 25. Build environment Rake is a DSL for dependency and build management There are a number of toolkits for building C# solutions in Rake, e.g. Albacore For an introduction, see Martin Fowler’s article about rake, http:// martinfowler.com/articles/rake.html
  • 26. IronRuby drawbacks i.e. don’t use IronRuby for high-performant systems • Performance • Throughput • Start-up (latency)
  • 27. Thanks! • Thomas Lundström, Softhouse • thomas.lundstrom@softhouse.se • Twitter: @thomaslundstrom • http://blog.thomaslundstrom.com