genügend gute gründe, wieso ruby besser als php ist

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

Upload: daniel-spangenberg

Post on 19-Jan-2015

1.374 views

Category:

Technology


6 download

DESCRIPTION

 

TRANSCRIPT

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

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

Daniel Spangenberg

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

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

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

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

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

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

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

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

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

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

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

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

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

Ruby Community

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

Ruby on Rails

• MVC

• ActiveRecord

• CRUD

• Testing

• RSpec

• Cucumber

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

Verloren?Hosting

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

kein Problem!Hosting

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

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

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

Wer nutzt Ruby?

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

Vielen Dank für Ihre Aufmerksamkeit

Daniel [email protected]@gmail.com