SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Downloaden Sie, um offline zu lesen
Genügend gute Gründe,
wieso Ruby besser als PHP ist
Daniel Spangenberg
RubyGems || Pear && Pecl

 • Konsistentere Paketverwaltung     RubyGems        Pear   Pecl
   in Ruby
                                                                30000

 • Fast jeder Anwendungsfall
   existiert als fertiges Gem                                   22500


 • „gem install rails“
                                                            15000

 • Bundler && „bundle install“     20,476
                                                            7500


                                            654             0
                                                    258
                                            Total
Syntax

• Leicht für Menschen zu lesen     Ruby                   PHP
• Optional                       puts "Hello World"   <?php
                                                      echo "Hello Worldn";
                                                      ?>



  • Keine <?php ?>s


  • Keine ;s


  • Keine ns


  • Optionale ()s
Objektorientierung

• Alles ist ein Objekt                               Ruby
   • Zahlen, Strings, alles...                3.times do
                                                puts "Hello " +
                                                     "daniel".capitalize
                                              end


• Objektorientierung von der ersten Sekunde   # Prints:
                                              #   Hello Daniel
                                              #   Hello Daniel
                                              #   Hello Daniel
Objektorientierte Syntax

• obj.attribute = method          Ruby                              PHP
• dangerous! und query?    full = "daniel Spangenberg"
                           names = full.split
                                                         <?php
                                                         $full = "daniel spangenberg";

  methoden                 until names.empty?
                                                         $names = explode(" ", $full);

                             names.first.capitalize!     if (size($names) > 0) {
                             puts names.shift              $names[0] = ucwords($names[0]);
                           end                             echo array_shift($names) . "n";
                                                         }
                           # Prints:
                           #   Daniel                    # Prints:
                           #   Spangenberg               #   Daniel
                                                         #   Spangenberg
                                                         ?>
Klassen und viel mehr...

• Einfache Zugriffsmethoden          Ruby                                 PHP
• Überschreiben der           class Greeter
                                attr_accessor :who
                                                               <?php
                                                               class Greeter {

  Ruby Methoden                                                  function getWho() {
                                                                   $this->who;
                                def initialize(greetring)
                                                                 }
                                  @greetring = greeting
                                  @who       = "World"
                                                                 function setWho($who) {
                                end
                                                                   $this->who = $who;
                                                                 }
                                def to_s
                                  "#{@greetring} #{@who}!"
                                                                 function __construct($greeting) {
                                end
                                                                   $this->greeting = $greeting;
                              end
                                                                   $this->who      = "World";
                                                                 }
                              hello = Greeter.new("Hello")
                              hello.who = "Daiel"
                                                                 function __toString() {
                              puts hello
                                                                   return $this->greeting . " " .
                                                             $this->who;
                              # Prints:
                                                                 }
                              #   Hello Daniel
                                                               }

                                                               $hello = new Greeter("Hello");
                                                               $hello->setWho("Daniel");
                                                               echo $hello . "n";
                                                               ?>
Blocks und „Core Type Monkey Patches“

                            Ruby
               describe MyClass do

                 it "adds two and two" do
                   sum = MyClass.add(2, 2)
                   sum.should == 4
                 end

               end




               describe MyClass do

                 it "adds two and two" do
                   sum = MyClass.add(2, 2)
                   sum.should == 4
                 end

               end
Ruby Community
Ruby on Rails

• MVC


• ActiveRecord


• CRUD


• Testing


   • RSpec


   • Cucumber
Hosting   Verloren?
Hosting   kein Problem!
Anfänger Workflow

• rails new blog


• git init && git commit -a -m „Initial import“


• heroku create


• git push heroku && heroku rake db:migrate


• http://blog.heroku.com
Wer nutzt Ruby?
Vielen Dank für Ihre   Daniel Spangenberg
   Aufmerksamkeit      @neonlex
                       daniel.spangenberg@gmail.com

Genügend gute Gründe, wieso Ruby besser als PHP ist

  • 1. Genügend gute Gründe, wieso Ruby besser als PHP ist Daniel Spangenberg
  • 2. RubyGems || Pear && Pecl • Konsistentere Paketverwaltung RubyGems Pear Pecl in Ruby 30000 • Fast jeder Anwendungsfall existiert als fertiges Gem 22500 • „gem install rails“ 15000 • Bundler && „bundle install“ 20,476 7500 654 0 258 Total
  • 3. Syntax • Leicht für Menschen zu lesen Ruby PHP • Optional puts "Hello World" <?php echo "Hello Worldn"; ?> • Keine <?php ?>s • Keine ;s • Keine ns • Optionale ()s
  • 4. Objektorientierung • Alles ist ein Objekt Ruby • Zahlen, Strings, alles... 3.times do puts "Hello " + "daniel".capitalize end • Objektorientierung von der ersten Sekunde # Prints: # Hello Daniel # Hello Daniel # Hello Daniel
  • 5. Objektorientierte Syntax • obj.attribute = method Ruby PHP • dangerous! und query? full = "daniel Spangenberg" names = full.split <?php $full = "daniel spangenberg"; methoden until names.empty? $names = explode(" ", $full); names.first.capitalize! if (size($names) > 0) { puts names.shift $names[0] = ucwords($names[0]); end echo array_shift($names) . "n"; } # Prints: # Daniel # Prints: # Spangenberg # Daniel # Spangenberg ?>
  • 6. Klassen und viel mehr... • Einfache Zugriffsmethoden Ruby PHP • Überschreiben der class Greeter attr_accessor :who <?php class Greeter { Ruby Methoden function getWho() { $this->who; def initialize(greetring) } @greetring = greeting @who = "World" function setWho($who) { end $this->who = $who; } def to_s "#{@greetring} #{@who}!" function __construct($greeting) { end $this->greeting = $greeting; end $this->who = "World"; } hello = Greeter.new("Hello") hello.who = "Daiel" function __toString() { puts hello return $this->greeting . " " . $this->who; # Prints: } # Hello Daniel } $hello = new Greeter("Hello"); $hello->setWho("Daniel"); echo $hello . "n"; ?>
  • 7. Blocks und „Core Type Monkey Patches“ Ruby describe MyClass do it "adds two and two" do sum = MyClass.add(2, 2) sum.should == 4 end end describe MyClass do it "adds two and two" do sum = MyClass.add(2, 2) sum.should == 4 end end
  • 9. Ruby on Rails • MVC • ActiveRecord • CRUD • Testing • RSpec • Cucumber
  • 10. Hosting Verloren?
  • 11. Hosting kein Problem!
  • 12. Anfänger Workflow • rails new blog • git init && git commit -a -m „Initial import“ • heroku create • git push heroku && heroku rake db:migrate • http://blog.heroku.com
  • 14. Vielen Dank für Ihre Daniel Spangenberg Aufmerksamkeit @neonlex daniel.spangenberg@gmail.com