SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Downloaden Sie, um offline zu lesen
AMIR BARYLKO
                    IRON RUBY AND .NET
                      A MATCH MADE IN
                          HEAVEN
                              .NET USER GROUP
                                   SEP 2010




Amir Barylko - RoR Training                     MavenThought Inc. - June 2010
WHO AM I?

   •   Architect

   •   Developer

   •   Mentor

   •   Great cook

   •   The one who’s entertaining you for the next hour!



Amir Barylko - RoR Training                            MavenThought Inc. - June 2010
CONTACT AND MATERIALS

   •   Contact me: amir@barylko.com, @abarylko

   •   Download: http://www.orthocoders.com/presentations.




Amir Barylko - RoR Training                         MavenThought Inc. - June 2010
RUBY INTRO
                                     Dynamic languages
                                         Testing
                                           IRB
                                        Constructs




Amir Barylko - Iron Ruby and .NET                        MavenThought Inc. - Sep 2010
DYNAMIC LANGUAGES

         High level
         Dynamically typed
         Runtime over compile time
         Closures
         Reflection
         Platform independent

Amir Barylko - Iron Ruby and .NET     MavenThought Inc. - Sep 2010
.NET CLR


          Iron Ruby                    DLR           CLR




Amir Barylko - Iron Ruby and .NET              MavenThought Inc. - Sep 2010
DEVELOPERS TOOLBOX
   • Make       your toolbox grow!

   • The     right tool for the job

   • Not      a replacement

   • Combine          strengths

   • Problem         solving



Amir Barylko - Iron Ruby and .NET     MavenThought Inc. - Sep 2010
WELCOME TO RUBY

          Created in mid-90s by          Several implementations:
           “Matz” Matsumoto in Japan       MRI, YARB, JRuby
          Smalltalk, Perl influences      Totally free!!
          Dynamic typing
          Object Oriented
          Automatic memory
           management

Amir Barylko - Iron Ruby and .NET                           MavenThought Inc. - Sep 2010
RUBY FEATURES

          Everything is an expression      Operator overloading,
                                             flexible syntax
          Metaprogramming
                                            Powerful standard library
          Closures
          Garbage collection
          Exceptions



Amir Barylko - Iron Ruby and .NET                         MavenThought Inc. - Sep 2010
RUBY SUPPORT

          Hundreds of books              Lots of great web sites:
                                           basecamp, twitter, 43
          User conferences all over       things, hulu, scribd,
           the world                       slideshare, Justin.tv
          Active community (you can      Lots of web frameworks
           create a conf in your own       inspired by Ruby on Rails
           city and top Ruby coders
           will go there to teach
           others, invite them and
           see)

Amir Barylko - Iron Ruby and .NET                        MavenThought Inc. - Sep 2010
SET UP

          Download IronRuby installer
          Put the bin folder on the path
          That’s it!




Amir Barylko - Iron Ruby and .NET            MavenThought Inc. - Sep 2010
INTERACTIVE
                          IRON RUBY SHELL
      c:> ir.exe
                                      > x = 1.upto(5).to_a
      > puts “hello”                  => [1, 2, 3, 4, 5]
      hello
      => nil                          > x.join
                                      => "12345"
      > "Hello World! " * 2
      => "Hello World! Hello World!
      "

      > ((1 + 5) * 3) ** 2
      => 324




Amir Barylko - Iron Ruby and .NET                     MavenThought Inc. - Sep 2010
BASIC TYPES
       Numbers
         1.class => Fixnum
         1.1.class => Float
         (120**100).class => Bignum
         3.times {puts “he “}




Amir Barylko - Iron Ruby and .NET                 MavenThought Inc. - Sep 2010
BASIC TYPES II
   • Strings

     'he ' + 'he' => he he
     “That's right” => That's right
     'He said “hi”' => He said “hi”
     “He said “hi”” => He said “hi”
     “1 + 1 is #{1+1}” => 1 + 1 is 2
     "#{'Ho! '*3}Merry Christmas" =>Ho! Ho! Ho! Merry
     Christmas



Amir Barylko - Iron Ruby and .NET                    MavenThought Inc. - Sep 2010
BASIC TYPES III
      Arrays
       a = [1, 5.5, “nice!”]
       1 == a.first
       1 == a[0]
       nil == a[10]
       a[1] = 3.14
       a.each {|elem| puts elem}
       a.sort



Amir Barylko - Iron Ruby and .NET                     MavenThought Inc. - Sep 2010
BASIC TYPES IV
   • Hashes
     h = {“one” => 1, 1 => “one”}
     h[“one”] == 1
     h[1] == “one”
     h[“two”] == nil
     h.keys == [“one”, 1] (or is it [1, “one”] ?)
     h.values == [“one”, 1] (or is it [1, “one”] ?)
     h[“one”] = 1.0



Amir Barylko - Iron Ruby and .NET                MavenThought Inc. - Sep 2010
BASIC TYPES V
      Symbols: constant names. No need to declare, guaranteed
       uniqueness, fast comparison

   :apple == :apple
   :orange != :banana
   [:all, :those, :symbols]
   {:ca => “Canada”, :ar => “Argentina”, :es => “Spain”}




Amir Barylko - Iron Ruby and .NET                     MavenThought Inc. - Sep 2010
CONTROL STRUCTURES
          if
           if count < 20
             puts “need more”
           elsif count < 40
             puts “perfect”
           else
             puts “too many”
           end
          while
           while count < 100 && need_more
               buy(1)
           end
Amir Barylko - Iron Ruby and .NET           MavenThought Inc. - Sep 2010
CONTROL STRUCTURES II
       Statement modifiers
        buy while need_more?

        buy(5) if need_more?

        buy until left == 0

        buy unless left < 5




Amir Barylko - Iron Ruby and .NET   MavenThought Inc. - Sep 2010
CONTROL STRUCTURES III
   • Case
       case left
           when 0..5
             dont_buy_more
           when 6..10
             buy(1)
           when 10..100
             buy(5)
       end

Amir Barylko - Iron Ruby and .NET   MavenThought Inc. - Sep 2010
METHODS
       Simple
         def play(movie_path)
         ....
         end

       Default arguments
         def play(movie_path, auto_start = true, wrap = false)
         ....
         end




Amir Barylko - Iron Ruby and .NET                    MavenThought Inc. - Sep 2010
METHODS II
       Return value: the last expression evaluated, no need for
        explicit return
         def votes(voted, num_votes)
           voted && num_votes || nil
         end

       No need for parenthesis on call without arguments (same
        syntax to call a method and a field)
         buy() == buy
         movie.play() == movie.play

Amir Barylko - Iron Ruby and .NET                        MavenThought Inc. - Sep 2010
METHODS III
       No need also with arguments (but careful!! only if you know
        what you are doing)

         movie.play “Pulp fiction”, false, true




Amir Barylko - Iron Ruby and .NET                       MavenThought Inc. - Sep 2010
RUBY INTRO II
                                          Classes
                                           Mixin
                                        Enumerable




Amir Barylko - Iron Ruby and .NET                    MavenThought Inc. - Sep 2010
CLASSES & OBJECTS

       Initializer and instance variables
        class Movie
          def initialize(name)
            @name = name
          end

          def play
            puts %Q{Playing “#{@name}”. Enjoy!}
          end
        end

        m = Movie.new(“Pulp fiction”)
        m.play

        => Playing “Pulp fiction”. Enjoy!


Amir Barylko - Iron Ruby and .NET                 MavenThought Inc. - Sep 2010
CLASSES & OBJECTS II
       Attributes
    class Movie
      def initialize(name)
        @name = name
      end



                                                           }
        def name                    # attr_reader :name
          @name
        end                                                    # attr_accessor :name

        def name=(value)            # attr_writter :name
          @name = value
        end

    end

    m = Movie.new('Brazil').name = “Pulp fiction”



Amir Barylko - Iron Ruby and .NET                                    MavenThought Inc. - Sep 2010
CODE ORGANIZATION
        Code in files with .rb extension
        Require 'movie' will read movie.rb file and make its methods
         available to the current file
        Require 'media/movie' will read file from media dir relative
         to the current working dir
            $LOAD_PATH << 'media'
            require 'movie'




Amir Barylko - Iron Ruby and .NET                         MavenThought Inc. - Sep 2010
CODE ORGANIZATION II
       Relative to this file:
         require File.join(File.dirname(__FILE__), 'media/movie')




Amir Barylko - Iron Ruby and .NET                    MavenThought Inc. - Sep 2010
MIXINS
       What about module “instance methods”?
       One of the greatest Ruby features!
       You can define functions in Modules, and get them added to
        your classes.
            Great code reuse,
            Multiple inheritance alternative.
            Code organization


Amir Barylko - Iron Ruby and .NET                     MavenThought Inc. - Sep 2010
ENUMERABLE
       Enumerable mixin, from the standard library documentation:


           The Enumerable mixin provides collection
           classes with several traversal and
           searching methods, and with the ability to
           sort. The class must provide a method each,
           which yields successive members of the
           collection


Amir Barylko - Iron Ruby and .NET                    MavenThought Inc. - Sep 2010
ENUMERABLE II
       It provides useful methods such as:

            map

            to_a

            take_while

            count

            inject


Amir Barylko - Iron Ruby and .NET              MavenThought Inc. - Sep 2010
EXAMPLES
                                          rSpec
                                    Enumerable Mixin
                                     missing_method
                                          Sinatra
                                     BDD Cucumber
                                           DSL

Amir Barylko - Iron Ruby and .NET                      MavenThought Inc. - Sep 2010
RSPEC TESTING LIBRARY
     require File.dirname(__FILE__) + "/../main/MavenThought.MovieLibrary/bin/Debug/MavenThought.MovieLibrary.dll"
     require 'rubygems'
     require 'spec'
     include MavenThought::MovieLibrary

     describe Library do
     	

      it "should be created empty" do
     	

      	

    lib = Library.new
     	

      	

    lib.contents.should be_empty
     	

      end

     	

      it "should add an element" do
     	

      	

    lib = Library.new
     	

      	

    m = Movie.new 'Blazing Saddles'
     	

      	

    lib.add m
     	

      	

    lib.contents.should include(m)
     	

      	

    lib.contents.count.should == 1
     	

      end
     	

     end


Amir Barylko - Iron Ruby and .NET                                                               MavenThought Inc. - Sep 2010
EXTEND LIBRARY
                WITH METHOD MISSING
     require File.dirname(__FILE__) + "/../main/MavenThought.MovieLibrary/bin/Debug/MavenThought.MovieLibrary.dll"

     require 'rubygems'

     include MavenThought::MovieLibrary

     # Extend library to use method missing to add find_by
     class Library

     	

         def method_missing(m, *args)
     	

         	

    if m.id2name.include?( "find_by" )
     	

         	

    	

      field = m.id2name.sub /find_by_/, ""
     	

         	

    	

      contents.find_all( lambda{ |m| m.send(field) == args[0] } )
     	

         	

    else
     	

         	

    	

      super
     	

         	

    end
     	

         end
     	

     end


     l = Library.new

     l.add Movie.new('Blazing Saddles', System::DateTime.new(1972, 1, 1))
     l.add Movie.new('Spaceballs', System::DateTime.new(1984, 1, 1))




Amir Barylko - Iron Ruby and .NET                                                                                    MavenThought Inc. - Sep 2010
SIMPLE WEB WITH SINATRA
     require 'rubygems'
     require 'sinatra'
     require 'haml'
     require 'singleton'

     require File.dirname(__FILE__) + "/../main/MavenThought.MovieLibrary/bin/Debug/MavenThought.MovieLibrary.dll"
     include MavenThought::MovieLibrary

     class Library
         include Singleton
     end

     # index
     get '/' do
      @movies = Library.instance.contents
      haml :index
     end

     # create
     post '/' do
      m = Movie.new(params[:title])
      Library.instance.add m
      redirect '/'
     end



Amir Barylko - Iron Ruby and .NET                                                                               MavenThought Inc. - Sep 2010
BDD WITH CUCUMBER
     Feature: Addition
     	

    In order to make my library grow
     	

    As a registered user
     	

    I want to add movies to the library

     	

      Scenario: Add a movie
     	

      	

 Given I have an empty library
     	

      	

 When I add the following movies:
                            |   title                |   release_date   |
                            |   Blazing Saddles      |   Feb 7, 1974    |
                            |   Young Frankenstein   |   Dec 15, 1974   |
                            |   Spaceballs           |   Jun 24, 1987   |
     	

      	

   Then   The library should have 3 movies
     	

      	

   And    "Blazing Saddles" should be in the list with release date "Feb 7, 1974"
     	

      	

   And    "Young Frankenstein" should be in the list with release date "Dec 15, 1974"
     	

      	

   And    "Spaceballs" should be in the list with release date "Jun 24, 1987"


Amir Barylko - Iron Ruby and .NET                                                 MavenThought Inc. - Sep 2010
CUCUMBER STEPS
     require File.dirname(__FILE__) + "/../../main/MavenThought.MovieLibrary/bin/Debug/MavenThought.MovieLibrary.dll"

     include MavenThought::MovieLibrary

     Given /^I have an empty library$/ do
      @lib = Library.new
     end

     When /^I add the following movies:$/ do |table|
         table.hashes.each do |row|
           movie = Movie.new row[:title], System::DateTime.parse(row[:release_date])
     	

          @lib.add movie
         end
     end

     Then /^The library should have (.*) movies$/ do |count|
      @lib.contents.count.should == count.to_i
     end

     Then /^"([^"]*)" should be in the list with release date "([^"]*)"$/ do |title, release|
      @lib.contents.find( lambda { |m| m.title == title and m.release_date == System::DateTime.parse(release) } ).should_not be_nil
     end



Amir Barylko - Iron Ruby and .NET                                                                         MavenThought Inc. - Sep 2010
DSL I
                                             RAKE
   task :default => [:build]
   desc "Builds the project"
   task :build do
   	

   call_target msbuild_cmd, :build
   end

   desc "Rebuild the application by cleaning and then building"
   task :rebuild => [:clean, :build] do
   	

   #nothing to do....
   end

   desc "Runs all the tests"
   task :test => ["test:all"]



Amir Barylko - Iron Ruby and .NET                                 MavenThought Inc. - Sep 2010
DSL II
                      CRON - WHENEVER
    every 10.minutes do
       runner "MyModel.some_process"
       rake "my:rake:task"
       command "/usr/bin/my_great_command"
    end


    every 2.days, :at => '4:30am' do
       command "/usr/bin/my_great_command"
    end




Amir Barylko - Iron Ruby and .NET            MavenThought Inc. - Sep 2010
QUESTIONS?




  (Don’t be shy)
CONTACT AND MATERIALS

   •   Contact me: amir@barylko.com, @abarylko

   •   Download: http://www.orthocoders.com/presentations.




Amir Barylko - RoR Training                         MavenThought Inc. - June 2010
ONLINE RESOURCES
       IronRuby: http://ironruby.net/
       The Ruby Bible (a.k.a. Pickaxe) http://ruby-doc.org/docs/ProgrammingRuby/
       Ruby language site: http://www.ruby-lang.org
    




Amir Barylko - Iron Ruby and .NET                                  MavenThought Inc. - Sep 2010

Weitere ähnliche Inhalte

Ähnlich wie Iron Ruby and .NET - A Match Made in Heaven

Page-objects-pattern
Page-objects-patternPage-objects-pattern
Page-objects-patternAmir Barylko
 
Talk: The Present and Future of Pharo
Talk: The Present and Future of PharoTalk: The Present and Future of Pharo
Talk: The Present and Future of PharoMarcus Denker
 
Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14CHOOSE
 
Games for the Masses (Jax)
Games for the Masses (Jax)Games for the Masses (Jax)
Games for the Masses (Jax)Wooga
 
Mirah & Dubious Talk Ruby|Web 2010
Mirah & Dubious Talk Ruby|Web 2010Mirah & Dubious Talk Ruby|Web 2010
Mirah & Dubious Talk Ruby|Web 2010baroquebobcat
 
RubyMotion Introduction
RubyMotion IntroductionRubyMotion Introduction
RubyMotion IntroductionLori Olson
 
Apache Sling - The whys and the hows
Apache Sling - The whys and the howsApache Sling - The whys and the hows
Apache Sling - The whys and the howsRobert Munteanu
 
Ruby'izing iOS development
Ruby'izing iOS developmentRuby'izing iOS development
Ruby'izing iOS developmenttoamitkumar
 
Open source libraries and tools
Open source libraries and toolsOpen source libraries and tools
Open source libraries and toolsAmir Barylko
 
Rich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; CoffeescriptRich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; CoffeescriptAmir Barylko
 
Kotlin what_you_need_to_know-converted event 4 with nigerians
Kotlin  what_you_need_to_know-converted event 4 with nigeriansKotlin  what_you_need_to_know-converted event 4 with nigerians
Kotlin what_you_need_to_know-converted event 4 with nigeriansjunaidhasan17
 
So R Debugging
So R DebuggingSo R Debugging
So R Debuggingwear
 
SDEC10-Bdd-quality-driven
SDEC10-Bdd-quality-drivenSDEC10-Bdd-quality-driven
SDEC10-Bdd-quality-drivenAmir Barylko
 
IronRuby for the Rubyist
IronRuby for the RubyistIronRuby for the Rubyist
IronRuby for the RubyistWill Green
 
2011 codestrong-abstracting-databases-access-in-titanium-mobile
2011 codestrong-abstracting-databases-access-in-titanium-mobile2011 codestrong-abstracting-databases-access-in-titanium-mobile
2011 codestrong-abstracting-databases-access-in-titanium-mobileAxway Appcelerator
 
Abstracting databases access in Titanium Mobile
Abstracting databases access in Titanium MobileAbstracting databases access in Titanium Mobile
Abstracting databases access in Titanium MobileXavier Lacot
 
The Guardian Open Platform Content API: Implementation
The Guardian Open Platform Content API: ImplementationThe Guardian Open Platform Content API: Implementation
The Guardian Open Platform Content API: ImplementationThe Guardian Open Platform
 

Ähnlich wie Iron Ruby and .NET - A Match Made in Heaven (20)

Page-objects-pattern
Page-objects-patternPage-objects-pattern
Page-objects-pattern
 
Talk: The Present and Future of Pharo
Talk: The Present and Future of PharoTalk: The Present and Future of Pharo
Talk: The Present and Future of Pharo
 
Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14
 
Games for the Masses (Jax)
Games for the Masses (Jax)Games for the Masses (Jax)
Games for the Masses (Jax)
 
Mirah & Dubious Talk Ruby|Web 2010
Mirah & Dubious Talk Ruby|Web 2010Mirah & Dubious Talk Ruby|Web 2010
Mirah & Dubious Talk Ruby|Web 2010
 
RubyMotion Introduction
RubyMotion IntroductionRubyMotion Introduction
RubyMotion Introduction
 
Apache Sling - The whys and the hows
Apache Sling - The whys and the howsApache Sling - The whys and the hows
Apache Sling - The whys and the hows
 
Ruby'izing iOS development
Ruby'izing iOS developmentRuby'izing iOS development
Ruby'izing iOS development
 
Vagrant at LA Ruby
Vagrant at LA RubyVagrant at LA Ruby
Vagrant at LA Ruby
 
Open source libraries and tools
Open source libraries and toolsOpen source libraries and tools
Open source libraries and tools
 
Rich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; CoffeescriptRich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; Coffeescript
 
Kotlin what_you_need_to_know-converted event 4 with nigerians
Kotlin  what_you_need_to_know-converted event 4 with nigeriansKotlin  what_you_need_to_know-converted event 4 with nigerians
Kotlin what_you_need_to_know-converted event 4 with nigerians
 
Exceptable
ExceptableExceptable
Exceptable
 
So R Debugging
So R DebuggingSo R Debugging
So R Debugging
 
SDEC10-Bdd-quality-driven
SDEC10-Bdd-quality-drivenSDEC10-Bdd-quality-driven
SDEC10-Bdd-quality-driven
 
IronRuby for the Rubyist
IronRuby for the RubyistIronRuby for the Rubyist
IronRuby for the Rubyist
 
Ruby - The Hard Bits
Ruby - The Hard BitsRuby - The Hard Bits
Ruby - The Hard Bits
 
2011 codestrong-abstracting-databases-access-in-titanium-mobile
2011 codestrong-abstracting-databases-access-in-titanium-mobile2011 codestrong-abstracting-databases-access-in-titanium-mobile
2011 codestrong-abstracting-databases-access-in-titanium-mobile
 
Abstracting databases access in Titanium Mobile
Abstracting databases access in Titanium MobileAbstracting databases access in Titanium Mobile
Abstracting databases access in Titanium Mobile
 
The Guardian Open Platform Content API: Implementation
The Guardian Open Platform Content API: ImplementationThe Guardian Open Platform Content API: Implementation
The Guardian Open Platform Content API: Implementation
 

Mehr von Amir Barylko

Functional converter project
Functional converter projectFunctional converter project
Functional converter projectAmir Barylko
 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web developmentAmir Barylko
 
User stories deep dive
User stories deep diveUser stories deep dive
User stories deep diveAmir Barylko
 
Coderetreat hosting training
Coderetreat hosting trainingCoderetreat hosting training
Coderetreat hosting trainingAmir Barylko
 
There's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessThere's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessAmir Barylko
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6Amir Barylko
 
Who killed object oriented design?
Who killed object oriented design?Who killed object oriented design?
Who killed object oriented design?Amir Barylko
 
From coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideFrom coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideAmir Barylko
 
Communication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityCommunication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityAmir Barylko
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven DevelopmentAmir Barylko
 
Agile requirements
Agile requirementsAgile requirements
Agile requirementsAmir Barylko
 
Agile teams and responsibilities
Agile teams and responsibilitiesAgile teams and responsibilities
Agile teams and responsibilitiesAmir Barylko
 
Beutiful javascript with coffeescript
Beutiful javascript with coffeescriptBeutiful javascript with coffeescript
Beutiful javascript with coffeescriptAmir Barylko
 
Agile requirements
Agile requirementsAgile requirements
Agile requirementsAmir Barylko
 

Mehr von Amir Barylko (20)

Functional converter project
Functional converter projectFunctional converter project
Functional converter project
 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web development
 
Dot Net Core
Dot Net CoreDot Net Core
Dot Net Core
 
No estimates
No estimatesNo estimates
No estimates
 
User stories deep dive
User stories deep diveUser stories deep dive
User stories deep dive
 
Coderetreat hosting training
Coderetreat hosting trainingCoderetreat hosting training
Coderetreat hosting training
 
There's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessThere's no charge for (functional) awesomeness
There's no charge for (functional) awesomeness
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6
 
Productive teams
Productive teamsProductive teams
Productive teams
 
Who killed object oriented design?
Who killed object oriented design?Who killed object oriented design?
Who killed object oriented design?
 
From coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideFrom coach to owner - What I learned from the other side
From coach to owner - What I learned from the other side
 
Communication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityCommunication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivity
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven Development
 
Refactoring
RefactoringRefactoring
Refactoring
 
Agile requirements
Agile requirementsAgile requirements
Agile requirements
 
Agile teams and responsibilities
Agile teams and responsibilitiesAgile teams and responsibilities
Agile teams and responsibilities
 
Refactoring
RefactoringRefactoring
Refactoring
 
Beutiful javascript with coffeescript
Beutiful javascript with coffeescriptBeutiful javascript with coffeescript
Beutiful javascript with coffeescript
 
Sass & bootstrap
Sass & bootstrapSass & bootstrap
Sass & bootstrap
 
Agile requirements
Agile requirementsAgile requirements
Agile requirements
 

Kürzlich hochgeladen

"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
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
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
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
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
 

Kürzlich hochgeladen (20)

"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
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
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
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
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
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
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
 

Iron Ruby and .NET - A Match Made in Heaven

  • 1. AMIR BARYLKO IRON RUBY AND .NET A MATCH MADE IN HEAVEN .NET USER GROUP SEP 2010 Amir Barylko - RoR Training MavenThought Inc. - June 2010
  • 2. WHO AM I? • Architect • Developer • Mentor • Great cook • The one who’s entertaining you for the next hour! Amir Barylko - RoR Training MavenThought Inc. - June 2010
  • 3. CONTACT AND MATERIALS • Contact me: amir@barylko.com, @abarylko • Download: http://www.orthocoders.com/presentations. Amir Barylko - RoR Training MavenThought Inc. - June 2010
  • 4. RUBY INTRO Dynamic languages Testing IRB Constructs Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 5. DYNAMIC LANGUAGES  High level  Dynamically typed  Runtime over compile time  Closures  Reflection  Platform independent Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 6. .NET CLR Iron Ruby DLR CLR Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 7. DEVELOPERS TOOLBOX • Make your toolbox grow! • The right tool for the job • Not a replacement • Combine strengths • Problem solving Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 8. WELCOME TO RUBY  Created in mid-90s by  Several implementations: “Matz” Matsumoto in Japan MRI, YARB, JRuby  Smalltalk, Perl influences  Totally free!!  Dynamic typing  Object Oriented  Automatic memory management Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 9. RUBY FEATURES  Everything is an expression  Operator overloading, flexible syntax  Metaprogramming  Powerful standard library  Closures  Garbage collection  Exceptions Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 10. RUBY SUPPORT  Hundreds of books  Lots of great web sites: basecamp, twitter, 43  User conferences all over things, hulu, scribd, the world slideshare, Justin.tv  Active community (you can  Lots of web frameworks create a conf in your own inspired by Ruby on Rails city and top Ruby coders will go there to teach others, invite them and see) Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 11. SET UP  Download IronRuby installer  Put the bin folder on the path  That’s it! Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 12. INTERACTIVE IRON RUBY SHELL c:> ir.exe > x = 1.upto(5).to_a > puts “hello” => [1, 2, 3, 4, 5] hello => nil > x.join => "12345" > "Hello World! " * 2 => "Hello World! Hello World! " > ((1 + 5) * 3) ** 2 => 324 Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 13. BASIC TYPES  Numbers 1.class => Fixnum 1.1.class => Float (120**100).class => Bignum 3.times {puts “he “} Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 14. BASIC TYPES II • Strings 'he ' + 'he' => he he “That's right” => That's right 'He said “hi”' => He said “hi” “He said “hi”” => He said “hi” “1 + 1 is #{1+1}” => 1 + 1 is 2 "#{'Ho! '*3}Merry Christmas" =>Ho! Ho! Ho! Merry Christmas Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 15. BASIC TYPES III  Arrays a = [1, 5.5, “nice!”] 1 == a.first 1 == a[0] nil == a[10] a[1] = 3.14 a.each {|elem| puts elem} a.sort Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 16. BASIC TYPES IV • Hashes h = {“one” => 1, 1 => “one”} h[“one”] == 1 h[1] == “one” h[“two”] == nil h.keys == [“one”, 1] (or is it [1, “one”] ?) h.values == [“one”, 1] (or is it [1, “one”] ?) h[“one”] = 1.0 Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 17. BASIC TYPES V  Symbols: constant names. No need to declare, guaranteed uniqueness, fast comparison :apple == :apple :orange != :banana [:all, :those, :symbols] {:ca => “Canada”, :ar => “Argentina”, :es => “Spain”} Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 18. CONTROL STRUCTURES  if if count < 20 puts “need more” elsif count < 40 puts “perfect” else puts “too many” end  while while count < 100 && need_more buy(1) end Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 19. CONTROL STRUCTURES II  Statement modifiers buy while need_more? buy(5) if need_more? buy until left == 0 buy unless left < 5 Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 20. CONTROL STRUCTURES III • Case case left when 0..5 dont_buy_more when 6..10 buy(1) when 10..100 buy(5) end Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 21. METHODS  Simple def play(movie_path) .... end  Default arguments def play(movie_path, auto_start = true, wrap = false) .... end Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 22. METHODS II  Return value: the last expression evaluated, no need for explicit return def votes(voted, num_votes) voted && num_votes || nil end  No need for parenthesis on call without arguments (same syntax to call a method and a field) buy() == buy movie.play() == movie.play Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 23. METHODS III  No need also with arguments (but careful!! only if you know what you are doing) movie.play “Pulp fiction”, false, true Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 24. RUBY INTRO II Classes Mixin Enumerable Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 25. CLASSES & OBJECTS  Initializer and instance variables class Movie def initialize(name) @name = name end def play puts %Q{Playing “#{@name}”. Enjoy!} end end m = Movie.new(“Pulp fiction”) m.play => Playing “Pulp fiction”. Enjoy! Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 26. CLASSES & OBJECTS II  Attributes class Movie def initialize(name) @name = name end } def name # attr_reader :name @name end # attr_accessor :name def name=(value) # attr_writter :name @name = value end end m = Movie.new('Brazil').name = “Pulp fiction” Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 27. CODE ORGANIZATION  Code in files with .rb extension  Require 'movie' will read movie.rb file and make its methods available to the current file  Require 'media/movie' will read file from media dir relative to the current working dir $LOAD_PATH << 'media' require 'movie' Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 28. CODE ORGANIZATION II  Relative to this file: require File.join(File.dirname(__FILE__), 'media/movie') Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 29. MIXINS  What about module “instance methods”?  One of the greatest Ruby features!  You can define functions in Modules, and get them added to your classes.  Great code reuse,  Multiple inheritance alternative.  Code organization Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 30. ENUMERABLE  Enumerable mixin, from the standard library documentation: The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The class must provide a method each, which yields successive members of the collection Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 31. ENUMERABLE II  It provides useful methods such as:  map  to_a  take_while  count  inject Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 32. EXAMPLES rSpec Enumerable Mixin missing_method Sinatra BDD Cucumber DSL Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 33. RSPEC TESTING LIBRARY require File.dirname(__FILE__) + "/../main/MavenThought.MovieLibrary/bin/Debug/MavenThought.MovieLibrary.dll" require 'rubygems' require 'spec' include MavenThought::MovieLibrary describe Library do it "should be created empty" do lib = Library.new lib.contents.should be_empty end it "should add an element" do lib = Library.new m = Movie.new 'Blazing Saddles' lib.add m lib.contents.should include(m) lib.contents.count.should == 1 end end Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 34. EXTEND LIBRARY WITH METHOD MISSING require File.dirname(__FILE__) + "/../main/MavenThought.MovieLibrary/bin/Debug/MavenThought.MovieLibrary.dll" require 'rubygems' include MavenThought::MovieLibrary # Extend library to use method missing to add find_by class Library def method_missing(m, *args) if m.id2name.include?( "find_by" ) field = m.id2name.sub /find_by_/, "" contents.find_all( lambda{ |m| m.send(field) == args[0] } ) else super end end end l = Library.new l.add Movie.new('Blazing Saddles', System::DateTime.new(1972, 1, 1)) l.add Movie.new('Spaceballs', System::DateTime.new(1984, 1, 1)) Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 35. SIMPLE WEB WITH SINATRA require 'rubygems' require 'sinatra' require 'haml' require 'singleton' require File.dirname(__FILE__) + "/../main/MavenThought.MovieLibrary/bin/Debug/MavenThought.MovieLibrary.dll" include MavenThought::MovieLibrary class Library include Singleton end # index get '/' do @movies = Library.instance.contents haml :index end # create post '/' do m = Movie.new(params[:title]) Library.instance.add m redirect '/' end Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 36. BDD WITH CUCUMBER Feature: Addition In order to make my library grow As a registered user I want to add movies to the library Scenario: Add a movie Given I have an empty library When I add the following movies: | title | release_date | | Blazing Saddles | Feb 7, 1974 | | Young Frankenstein | Dec 15, 1974 | | Spaceballs | Jun 24, 1987 | Then The library should have 3 movies And "Blazing Saddles" should be in the list with release date "Feb 7, 1974" And "Young Frankenstein" should be in the list with release date "Dec 15, 1974" And "Spaceballs" should be in the list with release date "Jun 24, 1987" Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 37. CUCUMBER STEPS require File.dirname(__FILE__) + "/../../main/MavenThought.MovieLibrary/bin/Debug/MavenThought.MovieLibrary.dll" include MavenThought::MovieLibrary Given /^I have an empty library$/ do @lib = Library.new end When /^I add the following movies:$/ do |table| table.hashes.each do |row| movie = Movie.new row[:title], System::DateTime.parse(row[:release_date]) @lib.add movie end end Then /^The library should have (.*) movies$/ do |count| @lib.contents.count.should == count.to_i end Then /^"([^"]*)" should be in the list with release date "([^"]*)"$/ do |title, release| @lib.contents.find( lambda { |m| m.title == title and m.release_date == System::DateTime.parse(release) } ).should_not be_nil end Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 38. DSL I RAKE task :default => [:build] desc "Builds the project" task :build do call_target msbuild_cmd, :build end desc "Rebuild the application by cleaning and then building" task :rebuild => [:clean, :build] do #nothing to do.... end desc "Runs all the tests" task :test => ["test:all"] Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 39. DSL II CRON - WHENEVER every 10.minutes do runner "MyModel.some_process" rake "my:rake:task" command "/usr/bin/my_great_command" end every 2.days, :at => '4:30am' do command "/usr/bin/my_great_command" end Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010
  • 41. CONTACT AND MATERIALS • Contact me: amir@barylko.com, @abarylko • Download: http://www.orthocoders.com/presentations. Amir Barylko - RoR Training MavenThought Inc. - June 2010
  • 42. ONLINE RESOURCES  IronRuby: http://ironruby.net/  The Ruby Bible (a.k.a. Pickaxe) http://ruby-doc.org/docs/ProgrammingRuby/  Ruby language site: http://www.ruby-lang.org  Amir Barylko - Iron Ruby and .NET MavenThought Inc. - Sep 2010