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 (ScanDevConf 2010)

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 (ScanDevConf 2010) (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

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
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
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
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
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

Ruby for C#-ers (ScanDevConf 2010)

  • 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