SlideShare ist ein Scribd-Unternehmen logo
1 von 60
Ruby for .NET
Developers


                       By Max Titov
                        maxtitov.me
          Ninja Software Operations
Objective: learn and compare
▶   What is Ruby?
▶   Ruby basics
▶   Ruby specialties
▶   Ruby ecosystem
▶   So why Ruby?
▶   How to get started?
What is Ruby?
Creator
"I wanted a scripting language that was
more powerful than Perl, and more object-
oriented than Python. That's why I decided
to design my own language.”

 Yukihiro (Matz) Matsumoto
Facts
▶   First “Hello World” in 1995 (.NET 2002, C#
    2001)
▶   Ruby is opensource
▶   Inspired by: Perl, Smalltalk, Lisp, Python …
▶   Philosophy: Designed for programmer
    productivity and fun.
Ruby Basics
First taste of Ruby code
class Apple
 NAME = "Apple"
 attr_accessor :size, :color

 def initialize size
  @size = size
 end

 def taste
  puts "Sweet #{@color} #{NAME} of size #{size}"
 end
end

apple = Apple.new 'big'
apple.color = 'red'
apple.taste # Sweet red Apple of size big
I know, feels like
Similarities
▶   Large standard library (Not so big as .NET
    Framework but feels enough)
▶   The are
    classes, methods, variables, properties.
▶   Access control modifiers
▶   Closures (Lambdas)
▶   Exceptions
▶   Garbage collector
Ruby is Dynamic
▶   No need to declare variables

var = "Ruby is Dynamic"
var.class #String
var = 1
var.class #Fixnum
Ruby is Strong Typed
▶   Like in .NET there is no type juggling.
    You need to convert between types.

a = "1"
b=2
a + b #TypeError: can`t convert Fixnum into String
a.to_i + b # 3
Everything is an Object
▶   All classes are drived from base class
    named Class
▶   Unlike .NET there is no structs
Everything is an Object
▶   So even primitive Types are an objects

10.times {puts "I am sexy and I know it!"}
# I am sexy and I know it!
# I am sexy and I know it!
# I am sexy and I know it!
# I am sexy and I know it!
# I am sexy and I know it!
# ....(10 times)....
Everything is an Object
▶   Operators are simply object methods.

class Fixnum < Integer
 def + numeric
  # sum code
 end
end
Ruby is Flexible
▶   Core Ruby code could be easy altered.

class Numeric
 def toSquare
  self * self
 end
end

2.toSquare # 4
Ruby is Concise
▶   Properties could be defined in old school way
class Person
 #getter
 def name
  @name
 end

 #setter
 def name= name
  @name = name
 end
end
Ruby is Concise
▶    Or in more convenient style

class Person
 #getter and setter, for several properties
 attr_accessor :name , :nickname

    #getter
    attr_reader :gender

 #setter
 attr_writer :age
end
Some questions to you
▶   Constants, start from capital or not?
▶   Field names, prefixed with underscore or
    not?
▶   How many coding guide lines is there
    actually?
    ▶   Microsoft Framework Design Guidelines
    ▶   IDesign C# coding standards
    ▶   Your company coding standard
    ▶   Your own coding standard. (Professional choice)
Ruby is Strict
▶   Autocracy took over the Ruby community.
Ruby is Strict
Ruby syntaxes mostly dictates naming
conventions:
  ▶   localVariable
  ▶   @instanceVariable
  ▶   @@classVariable
  ▶   $globalVariable
  ▶   Constant
  ▶   ClassName
  ▶   method_name
Ruby is Strict
▶   95% of ruby developers use same code
    style.
▶   Other 5% are a new comers, that will
    adept code conventions soon.
So in Ruby world you don’t feel like:




Forever alone in the world of naming
           conventions.
And Ruby Is Forgiving
▶   Parenthesis are optional
▶   No need in semicolon at the end of each
    line
Ruby
specialties
Duck typing
  What really makes object an object?
How can I recognize that object is a Duck?
Duck typing



Behavior
Duck typing
▶   Definition: When I see a bird that walks
    like a duck and swims like a duck and
    quacks like a duck, I call that bird a duck.
    (Wikipedia)
So, is it a duck?

Swim? Yes
Can Quack? Yes

Is it a duck?
Definitely!
And this?

Swim? Yes
Can Quack? Yes. Kind of
strange, but still it
make quack like sound

Is it a duck?
Looks like!
How, about this?

Swim? Badly, but yes.
Can Quack? Yeah, make
Plenty of sounds but, can
quack also.

Is it a duck?
Sort of weird duck, but still
yes!
Or, probably this?

Swim? Yep
Can quack? Can
make weird quack
sounds.

Is it duck?
Trying very hard
Duck Typing
▶   So, everything that could respond to
    several criteria's that makes us believe
    that object is a duck, can be recognized as
    a duck.
▶   But what that means from programmer
    perspective and how to implement it?
What is told you there is no
abstract classes and interfaces?
But there is Modules and Mixins!
▶   Modules define pieces of reusable code
    that couldn’t be instantiated.
▶   Modules provides a namespace
    functionality and prevent name clashes
Namespaces in Ruby
module System
 module Windows
  module Forms
   module MessageBox
           def MessageBox.Show message
       puts message
           end
   end
  end
 end
end

include System::Windows::Forms
MessageBox.Show 'Namespacing in ruby’
Modules and Mixins
▶   Modules could be “mixed in” to any class
    that satisfy conventions described in
    documentation (Should quack and swim
    like a duck).
▶   In .net Mixins using ReMix
    http://remix.codeplex.com/
Lets see how it works by
implementing Enumerable
In .NET we usually do this
▶   We need to implement two interfaces
    ▶   IEnumerable
    ▶   IEnumerator
In .NET we usually do this
class People : IEnumerable
{
     IEnumerator GetEnumerator()
     {
          return (IEnumerator) new PeopleEnumerator();
     }
}

public class PeopleEnumerator : IEnumerator
{
     public Person Current;
     public void Reset();
     public bool MoveNext();
}

public class Person
{
}
How it’s done in Ruby
▶   From Enumerable module documentation:
    The Enumerable mixin provides collection
    classes with several traversal and
    searching methods, and with the ability to
    sort. The client class must provide a
    method “each”, which yields successive
    members of the collection.
How it’s done in Ruby
class MyCollection
 include Enumerable
 def each
   #yields result
 end
end
That was easy!
But static typing and interfaces
         make me safe!




    Really?
In Ruby world developers used to
     write unit tests for this
Document and organize their code
             better
# The <code>Enumerable</code> mixin provides collection classes with
# several traversal and searching methods, and with the ability to
# sort. The class must provide a method <code>each</code>, which
# yields successive members of the collection. If
# <code>Enumerable#max</code>, <code>#min</code>, or
# <code>#sort</code> is used, the objects in the collection must also
# implement a meaningful <code><=></code> operator, as these methods
# rely on an ordering between members of the collection.
module Enumerable
   # enum.to_a      -> array
   # enum.entries -> array
      # Returns an array containing the items in <i>enum</i>.
   #
   # (1..7).to_a                  #=> [1, 2, 3, 4, 5, 6, 7]
   # { 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], #
                             ["c", 3]]
   def to_a()
      #This is a stub, used for indexing
   end
Closures in Ruby
▶   Closures in Ruby called Blocks
names = ["Max", "Alex", "Dima"].map do |name|
  name.downcase
end
puts names
# max
# alex
# dima
Ruby metaprogramming
▶   Metaprogramming is the writing of
    computer programs that write or
    manipulate other programs (or
    themselves) as their data, or that do part
    of the work at compile time that would
    otherwise be done at runtime. (Wikipedia)
▶   Keep programs DRY – Don’t repeat
    yourself.
Where is example?


In all cinemas of your town
       Next time “Ruby
    metaprogramming”
Ruby
Ecosystem
Frameworks
Ruby                    .NET
▶   Ruby on             ▶   ASP.NET
    Rails, Merb             MVC, FunuMVC
▶   Sinatra             ▶   Nancy
▶   Radiant, Mephisto   ▶   Umbraco, DotNetN
                            uke
Tools
Ruby                     .NET
▶   Any TextEditor       ▶   Visual
    (RubyMine IDE)           Studio, MonoDevel
                             op
▶   Rake
                         ▶   MSBuild, NAnt
▶   Gems
                         ▶   Dll’s
▶   Gems and Bundler     ▶   NuGet
▶   TestUnit, minitest   ▶   MSUnit, NUnit …
▶   Cucumber, RSpec,     ▶   NSpec, SpecFlow
     Shoulda
So Why
Ruby?
So Why Ruby?
▶   All hot stuff is here 
▶   Benefits of interpreted language
▶   Quick prototyping with Rails
▶   It’s fun and it’s going to make your better!
▶   And definitely it will sabotage what you
    believe in.
Feel more Rubier now? I hope so
              
Ruby tutorial 101
Interactive Ruby tutorial:
▶ http://tryruby.org/



Online course:
▶ http://www.coursera.org/course/saas/
Books
▶   Programming Ruby (Pick Axe book)
By Thomas D., Fowler C., Hunt A.

▶   Design Patterns In Ruby
By Russ Olsen

▶   Search Google for: Learn Ruby
Follow the ruby side
 we have cookies
        
Yep, we really do!
       
Questions?
    Ruby for .NET developers
           By Max Titov
Get presentation: www.maxtitov.me
 Get in touch: eolexe@gmail.com
          Twitter: eolexe

Weitere ähnliche Inhalte

Was ist angesagt?

Intro Ruby Classes Part I
Intro Ruby Classes Part IIntro Ruby Classes Part I
Intro Ruby Classes Part IJuan Leal
 
An Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersAn Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersKostas Saidis
 
Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorialknoppix
 
10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript TipsTroy Miles
 
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?daoswald
 
6 Modules Inheritance Gems
6 Modules Inheritance Gems6 Modules Inheritance Gems
6 Modules Inheritance Gemsliahhansen
 
On the path to become a jr. developer short version
On the path to become a jr. developer short versionOn the path to become a jr. developer short version
On the path to become a jr. developer short versionAntonelo Schoepf
 
Dart, Darrt, Darrrt
Dart, Darrt, DarrrtDart, Darrt, Darrrt
Dart, Darrt, DarrrtJana Moudrá
 
Ruby on Rails: a brief introduction
Ruby on Rails: a brief introductionRuby on Rails: a brief introduction
Ruby on Rails: a brief introductionLuigi De Russis
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRubyelliando dias
 

Was ist angesagt? (13)

Why Ruby?
Why Ruby? Why Ruby?
Why Ruby?
 
Intro Ruby Classes Part I
Intro Ruby Classes Part IIntro Ruby Classes Part I
Intro Ruby Classes Part I
 
Backend roadmap
Backend roadmapBackend roadmap
Backend roadmap
 
An Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersAn Introduction to Groovy for Java Developers
An Introduction to Groovy for Java Developers
 
Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorial
 
10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips
 
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
 
6 Modules Inheritance Gems
6 Modules Inheritance Gems6 Modules Inheritance Gems
6 Modules Inheritance Gems
 
On the path to become a jr. developer short version
On the path to become a jr. developer short versionOn the path to become a jr. developer short version
On the path to become a jr. developer short version
 
Oops
OopsOops
Oops
 
Dart, Darrt, Darrrt
Dart, Darrt, DarrrtDart, Darrt, Darrrt
Dart, Darrt, Darrrt
 
Ruby on Rails: a brief introduction
Ruby on Rails: a brief introductionRuby on Rails: a brief introduction
Ruby on Rails: a brief introduction
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRuby
 

Ähnlich wie Ruby for .NET developers

Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Codeeddiehaber
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2
name name2 n2name name2 n2
name name2 n2callroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.pptcallroom
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmersamiable_indian
 
Monkeybars in the Manor
Monkeybars in the ManorMonkeybars in the Manor
Monkeybars in the Manormartinbtt
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLBarry Jones
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# DevelopersCory Foy
 

Ähnlich wie Ruby for .NET developers (20)

Ruby
RubyRuby
Ruby
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Code
 
Ruby Hell Yeah
Ruby Hell YeahRuby Hell Yeah
Ruby Hell Yeah
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 
ppt9
ppt9ppt9
ppt9
 
Monkeybars in the Manor
Monkeybars in the ManorMonkeybars in the Manor
Monkeybars in the Manor
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# Developers
 

Kürzlich hochgeladen

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
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
 
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
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Kürzlich hochgeladen (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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
 
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
 
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?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Ruby for .NET developers

  • 1. Ruby for .NET Developers By Max Titov maxtitov.me Ninja Software Operations
  • 2. Objective: learn and compare ▶ What is Ruby? ▶ Ruby basics ▶ Ruby specialties ▶ Ruby ecosystem ▶ So why Ruby? ▶ How to get started?
  • 3.
  • 5. Creator "I wanted a scripting language that was more powerful than Perl, and more object- oriented than Python. That's why I decided to design my own language.” Yukihiro (Matz) Matsumoto
  • 6. Facts ▶ First “Hello World” in 1995 (.NET 2002, C# 2001) ▶ Ruby is opensource ▶ Inspired by: Perl, Smalltalk, Lisp, Python … ▶ Philosophy: Designed for programmer productivity and fun.
  • 8. First taste of Ruby code class Apple NAME = "Apple" attr_accessor :size, :color def initialize size @size = size end def taste puts "Sweet #{@color} #{NAME} of size #{size}" end end apple = Apple.new 'big' apple.color = 'red' apple.taste # Sweet red Apple of size big
  • 10. Similarities ▶ Large standard library (Not so big as .NET Framework but feels enough) ▶ The are classes, methods, variables, properties. ▶ Access control modifiers ▶ Closures (Lambdas) ▶ Exceptions ▶ Garbage collector
  • 11. Ruby is Dynamic ▶ No need to declare variables var = "Ruby is Dynamic" var.class #String var = 1 var.class #Fixnum
  • 12. Ruby is Strong Typed ▶ Like in .NET there is no type juggling. You need to convert between types. a = "1" b=2 a + b #TypeError: can`t convert Fixnum into String a.to_i + b # 3
  • 13. Everything is an Object ▶ All classes are drived from base class named Class ▶ Unlike .NET there is no structs
  • 14. Everything is an Object ▶ So even primitive Types are an objects 10.times {puts "I am sexy and I know it!"} # I am sexy and I know it! # I am sexy and I know it! # I am sexy and I know it! # I am sexy and I know it! # I am sexy and I know it! # ....(10 times)....
  • 15. Everything is an Object ▶ Operators are simply object methods. class Fixnum < Integer def + numeric # sum code end end
  • 16. Ruby is Flexible ▶ Core Ruby code could be easy altered. class Numeric def toSquare self * self end end 2.toSquare # 4
  • 17. Ruby is Concise ▶ Properties could be defined in old school way class Person #getter def name @name end #setter def name= name @name = name end end
  • 18. Ruby is Concise ▶ Or in more convenient style class Person #getter and setter, for several properties attr_accessor :name , :nickname #getter attr_reader :gender #setter attr_writer :age end
  • 19. Some questions to you ▶ Constants, start from capital or not? ▶ Field names, prefixed with underscore or not? ▶ How many coding guide lines is there actually? ▶ Microsoft Framework Design Guidelines ▶ IDesign C# coding standards ▶ Your company coding standard ▶ Your own coding standard. (Professional choice)
  • 20. Ruby is Strict ▶ Autocracy took over the Ruby community.
  • 21. Ruby is Strict Ruby syntaxes mostly dictates naming conventions: ▶ localVariable ▶ @instanceVariable ▶ @@classVariable ▶ $globalVariable ▶ Constant ▶ ClassName ▶ method_name
  • 22. Ruby is Strict ▶ 95% of ruby developers use same code style. ▶ Other 5% are a new comers, that will adept code conventions soon.
  • 23. So in Ruby world you don’t feel like: Forever alone in the world of naming conventions.
  • 24. And Ruby Is Forgiving ▶ Parenthesis are optional ▶ No need in semicolon at the end of each line
  • 26. Duck typing What really makes object an object? How can I recognize that object is a Duck?
  • 28. Duck typing ▶ Definition: When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck. (Wikipedia)
  • 29. So, is it a duck? Swim? Yes Can Quack? Yes Is it a duck? Definitely!
  • 30. And this? Swim? Yes Can Quack? Yes. Kind of strange, but still it make quack like sound Is it a duck? Looks like!
  • 31. How, about this? Swim? Badly, but yes. Can Quack? Yeah, make Plenty of sounds but, can quack also. Is it a duck? Sort of weird duck, but still yes!
  • 32. Or, probably this? Swim? Yep Can quack? Can make weird quack sounds. Is it duck? Trying very hard
  • 33. Duck Typing ▶ So, everything that could respond to several criteria's that makes us believe that object is a duck, can be recognized as a duck. ▶ But what that means from programmer perspective and how to implement it?
  • 34. What is told you there is no abstract classes and interfaces?
  • 35. But there is Modules and Mixins! ▶ Modules define pieces of reusable code that couldn’t be instantiated. ▶ Modules provides a namespace functionality and prevent name clashes
  • 36. Namespaces in Ruby module System module Windows module Forms module MessageBox def MessageBox.Show message puts message end end end end end include System::Windows::Forms MessageBox.Show 'Namespacing in ruby’
  • 37. Modules and Mixins ▶ Modules could be “mixed in” to any class that satisfy conventions described in documentation (Should quack and swim like a duck). ▶ In .net Mixins using ReMix http://remix.codeplex.com/
  • 38. Lets see how it works by implementing Enumerable
  • 39. In .NET we usually do this ▶ We need to implement two interfaces ▶ IEnumerable ▶ IEnumerator
  • 40. In .NET we usually do this class People : IEnumerable { IEnumerator GetEnumerator() { return (IEnumerator) new PeopleEnumerator(); } } public class PeopleEnumerator : IEnumerator { public Person Current; public void Reset(); public bool MoveNext(); } public class Person { }
  • 41. How it’s done in Ruby ▶ From Enumerable module documentation: The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The client class must provide a method “each”, which yields successive members of the collection.
  • 42. How it’s done in Ruby class MyCollection include Enumerable def each #yields result end end
  • 44. But static typing and interfaces make me safe! Really?
  • 45. In Ruby world developers used to write unit tests for this
  • 46. Document and organize their code better # The <code>Enumerable</code> mixin provides collection classes with # several traversal and searching methods, and with the ability to # sort. The class must provide a method <code>each</code>, which # yields successive members of the collection. If # <code>Enumerable#max</code>, <code>#min</code>, or # <code>#sort</code> is used, the objects in the collection must also # implement a meaningful <code><=></code> operator, as these methods # rely on an ordering between members of the collection. module Enumerable # enum.to_a -> array # enum.entries -> array # Returns an array containing the items in <i>enum</i>. # # (1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7] # { 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], # ["c", 3]] def to_a() #This is a stub, used for indexing end
  • 47. Closures in Ruby ▶ Closures in Ruby called Blocks names = ["Max", "Alex", "Dima"].map do |name| name.downcase end puts names # max # alex # dima
  • 48. Ruby metaprogramming ▶ Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data, or that do part of the work at compile time that would otherwise be done at runtime. (Wikipedia) ▶ Keep programs DRY – Don’t repeat yourself.
  • 49. Where is example? In all cinemas of your town Next time “Ruby metaprogramming”
  • 51. Frameworks Ruby .NET ▶ Ruby on ▶ ASP.NET Rails, Merb MVC, FunuMVC ▶ Sinatra ▶ Nancy ▶ Radiant, Mephisto ▶ Umbraco, DotNetN uke
  • 52. Tools Ruby .NET ▶ Any TextEditor ▶ Visual (RubyMine IDE) Studio, MonoDevel op ▶ Rake ▶ MSBuild, NAnt ▶ Gems ▶ Dll’s ▶ Gems and Bundler ▶ NuGet ▶ TestUnit, minitest ▶ MSUnit, NUnit … ▶ Cucumber, RSpec, ▶ NSpec, SpecFlow Shoulda
  • 54. So Why Ruby? ▶ All hot stuff is here  ▶ Benefits of interpreted language ▶ Quick prototyping with Rails ▶ It’s fun and it’s going to make your better! ▶ And definitely it will sabotage what you believe in.
  • 55. Feel more Rubier now? I hope so 
  • 56. Ruby tutorial 101 Interactive Ruby tutorial: ▶ http://tryruby.org/ Online course: ▶ http://www.coursera.org/course/saas/
  • 57. Books ▶ Programming Ruby (Pick Axe book) By Thomas D., Fowler C., Hunt A. ▶ Design Patterns In Ruby By Russ Olsen ▶ Search Google for: Learn Ruby
  • 58. Follow the ruby side we have cookies 
  • 59. Yep, we really do! 
  • 60. Questions? Ruby for .NET developers By Max Titov Get presentation: www.maxtitov.me Get in touch: eolexe@gmail.com Twitter: eolexe