Why Ruby? Why Rails? Reuven M. Lerner reuven@lerner.co.il Hi-Tech College June 27th, 2010
Welcome!
Remember Perl? • Strings • Networks • Databases • Very fast coding • (Relatively) fast execution • CPAN!
Perl had a big problem
So what? • Unreadable code = unmaintainable code • Unmaintainable code = eventual disaster
Web apps are complex • HTML • CSS • JavaScript • SQL • Ruby (or another language)
Web apps are complex The really hard part: • HTML Getting these technologies • CSS to work together, smoothly • JavaScript • SQL • Ruby (or another language)
Rails to the rescue! • Smooths the edges between these parts • Reduces the pain in writing apps • Encourages you to write maintainable code • Allows you to focus on your domain
It’s all about the data • Philip Greenspun • The data model is key • Provided a model (ACS) • Rails says: Create one!
ActiveRecord • Makes it easy to work with databases • Zero lines of code, for starters! • Lets you write a DSL (domain-specific language) that describes your data • Validations, callbacks, scopes
Other data stores • MongoDB • Memcached • Redis • Cassandra • Amazon S3 • You name it...
RESTful resources • Standard HTTP interface to actions • GET, POST, PUT, DELETE the way they were supposed to be used • Built into Rails, works automatically • Gives you lots automatically
Separation • MVC + H • Models, views, controllers + helpers • Push code to the model • Conventions — but they work • Read someone else’s code without crying • Read your own code without crying!
Environments • development, testing, production • Create your own (e.g., “staging”) • Each can load different libraries • Each has its own log levels
Console >> p = Person.find(1) => #<Person id: 1, email_address: "reuven@lerner.co.il", first_name: "reuven", last_name: "lerner", password: "foo", administrator: true, created_at: "2009-07-08 12:50:42", updated_at: "2010-06-10 10:51:04", avatar_file_name: "Reuven_headshot.jpg", avatar_content_type: "image/ jpeg", avatar_file_size: 1248486, avatar_updated_at: "2010-06-06 19:22:00"> >> p.update_attributes(:administrator => true) => true >> p.nodes.length => 6
Filters • Execute code before or after any controller actions before_filter :require_login, :only => [:edit, :update, :logout, :tags] • Authentication • Common variable settings • Logging
Rake • Sort of like “make” — but in Ruby • Tasks have access to objects • Automate all sorts of tasks • Migrating data • Creating sitemaps
Ever read this?
Software ICs • Reusable code libraries • Multiple libraries that adhere to a spec • Download and install • First suggested in 1986! • Cox put these ideas into practice • Ever hear of Objective-C?
Gems • Reusable libraries of Ruby code • As little as a constant • As big as a complete CMS • Download, install, and use! • Open source — free to use and change
How popular?
How popular?
Some gems • Paperclip (attachments) • Devise (authentication) • MongoMapper (MongoDB access) • will_paginate (pagination)
Plugins • Want or need to change Rails itself? • Write a plugin! • Or use one of the many out there • (some of which now come as gems)
Some plugins • acts_as_tree (hierarchical models) • html_test (check validity of views) • annotate_models (add column lists)
My brain is too small! • Yes, there’s a lot to learn • Most of it can wait a little bit • Start with what you know • Improve yourself and your code over time
Wait, isn’t Ruby slow? • Yes. For now. • JRuby, Gemstone, Ruby 1.9/2.0 • Is execution speed your biggest worry? • Development speed • Reliability • Maintainability
So, why Rails? • Common Web development tasks are easy • You write less code • The code that you do write is better • You can maintain your code more easily • Less pain dealing with many Web issues
Finally, because it’s fun “I tried to make people enjoy programming and concentrate on the fun and creative part of programming when they use Ruby.” — Matz
Join us! • Israel.rb (Google group) • Ruby, Rails courses right here! • Call me: 054-496-8405 • E-mail me: reuven@lerner.co.il • Interrupt me: reuvenlerner (Skype/AIM)

Why ruby and rails

  • 1.
    Why Ruby? WhyRails? Reuven M. Lerner reuven@lerner.co.il Hi-Tech College June 27th, 2010
  • 2.
  • 3.
    Remember Perl? • Strings •Networks • Databases • Very fast coding • (Relatively) fast execution • CPAN!
  • 4.
    Perl had abig problem
  • 5.
    So what? • Unreadablecode = unmaintainable code • Unmaintainable code = eventual disaster
  • 7.
    Web apps arecomplex • HTML • CSS • JavaScript • SQL • Ruby (or another language)
  • 8.
    Web apps arecomplex The really hard part: • HTML Getting these technologies • CSS to work together, smoothly • JavaScript • SQL • Ruby (or another language)
  • 9.
    Rails to therescue! • Smooths the edges between these parts • Reduces the pain in writing apps • Encourages you to write maintainable code • Allows you to focus on your domain
  • 10.
    It’s all aboutthe data • Philip Greenspun • The data model is key • Provided a model (ACS) • Rails says: Create one!
  • 11.
    ActiveRecord • Makes iteasy to work with databases • Zero lines of code, for starters! • Lets you write a DSL (domain-specific language) that describes your data • Validations, callbacks, scopes
  • 12.
    Other data stores •MongoDB • Memcached • Redis • Cassandra • Amazon S3 • You name it...
  • 13.
    RESTful resources • StandardHTTP interface to actions • GET, POST, PUT, DELETE the way they were supposed to be used • Built into Rails, works automatically • Gives you lots automatically
  • 14.
    Separation • MVC +H • Models, views, controllers + helpers • Push code to the model • Conventions — but they work • Read someone else’s code without crying • Read your own code without crying!
  • 15.
    Environments • development, testing,production • Create your own (e.g., “staging”) • Each can load different libraries • Each has its own log levels
  • 16.
    Console >> p =Person.find(1) => #<Person id: 1, email_address: "reuven@lerner.co.il", first_name: "reuven", last_name: "lerner", password: "foo", administrator: true, created_at: "2009-07-08 12:50:42", updated_at: "2010-06-10 10:51:04", avatar_file_name: "Reuven_headshot.jpg", avatar_content_type: "image/ jpeg", avatar_file_size: 1248486, avatar_updated_at: "2010-06-06 19:22:00"> >> p.update_attributes(:administrator => true) => true >> p.nodes.length => 6
  • 17.
    Filters • Execute codebefore or after any controller actions before_filter :require_login, :only => [:edit, :update, :logout, :tags] • Authentication • Common variable settings • Logging
  • 18.
    Rake • Sort oflike “make” — but in Ruby • Tasks have access to objects • Automate all sorts of tasks • Migrating data • Creating sitemaps
  • 19.
  • 20.
    Software ICs • Reusablecode libraries • Multiple libraries that adhere to a spec • Download and install • First suggested in 1986! • Cox put these ideas into practice • Ever hear of Objective-C?
  • 21.
    Gems • Reusable librariesof Ruby code • As little as a constant • As big as a complete CMS • Download, install, and use! • Open source — free to use and change
  • 22.
  • 23.
  • 24.
    Some gems • Paperclip(attachments) • Devise (authentication) • MongoMapper (MongoDB access) • will_paginate (pagination)
  • 25.
    Plugins • Want orneed to change Rails itself? • Write a plugin! • Or use one of the many out there • (some of which now come as gems)
  • 26.
    Some plugins • acts_as_tree(hierarchical models) • html_test (check validity of views) • annotate_models (add column lists)
  • 27.
    My brain istoo small! • Yes, there’s a lot to learn • Most of it can wait a little bit • Start with what you know • Improve yourself and your code over time
  • 28.
    Wait, isn’t Rubyslow? • Yes. For now. • JRuby, Gemstone, Ruby 1.9/2.0 • Is execution speed your biggest worry? • Development speed • Reliability • Maintainability
  • 29.
    So, why Rails? •Common Web development tasks are easy • You write less code • The code that you do write is better • You can maintain your code more easily • Less pain dealing with many Web issues
  • 30.
    Finally, because it’sfun “I tried to make people enjoy programming and concentrate on the fun and creative part of programming when they use Ruby.” — Matz
  • 31.
    Join us! • Israel.rb(Google group) • Ruby, Rails courses right here! • Call me: 054-496-8405 • E-mail me: reuven@lerner.co.il • Interrupt me: reuvenlerner (Skype/AIM)