genügend gute gründe, wieso ruby besser als php ist
DESCRIPTION
TRANSCRIPT
Genügend gute Gründe,wieso Ruby besser als PHP ist
Daniel Spangenberg
RubyGems || Pear && Pecl
• Konsistentere Paketverwaltung in Ruby
• Fast jeder Anwendungsfall existiert als fertiges Gem
• „gem install rails“
• Bundler && „bundle install“
0
7500
15000
22500
30000
20,476
654258
Total
RubyGems Pear Pecl
Syntax
• Leicht für Menschen zu lesen
• Optional
• Keine <?php ?>s
• Keine ;s
• Keine \ns
• Optionale ()s
puts "Hello World" <?php echo "Hello World\n"; ?>
Ruby PHP
Objektorientierung
• Alles ist ein Objekt
• Zahlen, Strings, alles...
• Objektorientierung von der ersten Sekunde
3.times do puts "Hello " + "daniel".capitalize end # Prints: # Hello Daniel # Hello Daniel # Hello Daniel
Ruby
Objektorientierte Syntax
• obj.attribute = method
• dangerous! und query? methoden
full = "daniel Spangenberg" names = full.split
until names.empty? names.first.capitalize! puts names.shift end # Prints: # Daniel # Spangenberg
<?php $full = "daniel spangenberg"; $names = explode(" ", $full); if (size($names) > 0) { $names[0] = ucwords($names[0]); echo array_shift($names) . "\n"; } # Prints: # Daniel # Spangenberg ?>
Ruby PHP
Klassen und viel mehr...
• Einfache Zugriffsmethoden
• Überschreiben der Ruby Methoden
class Greeter attr_accessor :who def initialize(greetring) @greetring = greeting @who = "World" end def to_s "#{@greetring} #{@who}!" end end hello = Greeter.new("Hello") hello.who = "Daiel" puts hello # Prints: # Hello Daniel
<?php class Greeter { function getWho() { $this->who; } function setWho($who) { $this->who = $who; } function __construct($greeting) { $this->greeting = $greeting; $this->who = "World"; } function __toString() { return $this->greeting . " " . $this->who; } } $hello = new Greeter("Hello"); $hello->setWho("Daniel"); echo $hello . "\n"; ?>
Ruby PHP
Blocks und „Core Type Monkey Patches“
describe MyClass do
it "adds two and two" do sum = MyClass.add(2, 2) sum.should == 4 end
end
Ruby
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
Verloren?Hosting
kein Problem!Hosting
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 Aufmerksamkeit
Daniel [email protected]@gmail.com