SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 
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
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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
 

Kürzlich hochgeladen (20)

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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
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...
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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...
 

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