festival ICT 2013: Ruby, the 0.8 language you were looking for

238 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
238
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

festival ICT 2013: Ruby, the 0.8 language you were looking for

  1. 1. this is the 0.8 language you were looking for
  2. 2. class << self def who Maurizio De Magnis I’m a Developer, trying to improve * http://olistik.me @olistik def what def where
  3. 3. First things first let's sculpt this presentation
  4. 4. What you're NOT going to see today “C’mon, use Ruby so I can eat meat this week” “Pick me! Pick me!”
  5. 5. What I'm going to say is a personal remix of what I've experienced, heard and read. http://goo.gl/TPywyp
  6. 6. Will you see breakthrough concepts here? http://goo.gl/4FhtgR
  7. 7. No.
  8. 8. I'll just give you another point of view
  9. 9. ● Ruby is NOT a perfect language ● Ruby is NOT the best language for every scenario
  10. 10. "a language can’t be good for everyone and every purpose, but we can strive to make it good for 80% of what is needed in a programming language" The most important slide so far Yukihiro ‘Matz’ Matsumoto (creator of Ruby) http://goo.gl/0p7tBv
  11. 11. so do good/great programming languages (and frameworks)
  12. 12. http://www.ruby-lang.org/en/about/ "Ruby is a language of careful balance. Its creator, Yukihiro “Matz” Matsumoto, blended parts of his favorite languages (Perl, Smalltalk, Eiffel, Ada, and Lisp) to form a new language that balanced functional programming with imperative programming."
  13. 13. ● everyone has good ideas ● BUT not everyone perform well Let's talk about something that matters http://goo.gl/60awJp
  14. 14. How? perform well := adaptability to changes either in the early stages (prototype) or in the subsequent evolutions
  15. 15. Recipe for success people (skilled and motivated) processes (agile!) but also the tools
  16. 16. on the coding layer Let’s focus
  17. 17. coding is a creative process positive thoughts unleash creativity if coders are happy then creativity boosts
  18. 18. Provide them tools that actually improves the efficiency of their environment (also, pay them well enough so that they don't worry about the economic details) A good way to make coders happy
  19. 19. The code you have to actually type is the code you wish you had. Today’s definition for EPIC WIN
  20. 20. Expressiveness #1 The language you use influences your thoughts
  21. 21. Expressiveness #2 What about a language that looks like written english?
  22. 22. “In the 1970s, researchers found that developers tend to write roughly the same number of lines of code every day, regardless of what language they're working in.” Terseness #1 B. Boehm, Software Engineering Economics, Prentice-Hall, ISBN 0-138-22122-7, 1981.
  23. 23. Terseness #2 "the first 10 book's title, ordered alphabetically" (it’s actually shorter than the corresponding english sentence)
  24. 24. Immediate feedback I want to be able to “play” with the data: Don't limit my designing skills (testing new ideas) Don't limit my problem solving skills (debugging)
  25. 25. Immediate feedback - IRB .js: 1 .css: 1 .rb: 21 .erb: 1 .yml: 3 .ru: 1 .lock: 1 .log: 1 .html: 3 .ico: 1 .txt: 1 .rdoc: 1
  26. 26. Immediate feedback - Rails console
  27. 27. Immediate feedback - meet AREL
  28. 28. Immediate feedback - meet AREL #2 Ruby code that gets transparently translated into (usually) boring/verbose SQL statements. Regardless the DBMS you're using (MySQL, Postgres, SQLite, etc.) Why? Abstraction! "perform well := adaptability to changes"
  29. 29. “My code does something funky, let me inspect its context at runtime” Immediate feedback - MOAR
  30. 30. Immediate feedback - MOAR Better Errors
  31. 31. Immediate feedback - MOAR RailsPanel
  32. 32. The pitfall of most frameworks “Be the best at all the things!” It usually ends up for the framework to be less than average. Even worse: “Let's do it by configuring all the things!” (every time, from scratch) => a lot of time effort
  33. 33. Rails is an opinionated framework
  34. 34. Conventions over configurations A lot of assumptions based on what are the most common needs of web developers.
  35. 35. ● console ● standalone app server (but you can choose whatever you like) Fully isolated development environment
  36. 36. Code organization Follows the MVC pattern: The goal is to understand in almost zero time where a file is or should be located. app/ models/ views/ controllers/
  37. 37. Code organization #2 Tends to fight bad practices such as: ● single directory with hundreds of files ● few huge monolithic files
  38. 38. Data persistence: ActiveRecord class Author < ActiveRecord::Base end The code above reflects this database configuration: - authors id: integer
  39. 39. Data persistence: ActiveRecord #2 If the database table happens to contain additional fields like "name" and "age" the developer doesn't need to update any code in order to perform these: author = Author.take(name: 'PKD') author.age # => 55 author.age = 53 author.save
  40. 40. Data persistence: ActiveRecord #3 Even relations are easily mapped with little effort: class Author < ActiveRecord::Base has_many :books end class Book < ActiveRecord::Base belongs_to :author end - authors id: integer - books id: integer author_id: integer author.books.first author.books.destroy_all author.books << Book.create
  41. 41. Here are some of the tools that makes Ruby shine. The focus should not be placed into what they do, but how they have been architectured so that your effort consists only in declaring your needs. When you use Ruby, you get the whole ecosystem for free
  42. 42. $ irb > require 'mini_magick' > image = MiniMagick::Image.open("input.jpg") > image.resize "100x100" > image.write "output.jpg" $ gem install mini_magick
  43. 43. $ irb > require ‘nokogiri’ > require 'open-uri' > doc = Nokogiri::HTML(open("http://www.nytimes.com")) > puts doc. css('.story h3'). map {|story| "- #{story.text.strip}"} - Obama's Battle for Votes on Syria Strike Is Taut and Uphill - In Egypt, a Welcome for Syrian Refugees Turns Bitter - Facing Fury Over New Law, Stoli Says '€˜Russian? Not Really' - Two Men, 58 Years and Counting - Editorial: Banning a Pseudo-Therapy - Loose Ends: My Adventures in Their Clutches $ gem install nokogiri
  44. 44. "RSpec is testing tool for the Ruby programming language. Born under the banner of Behaviour-Driven Development, it is designed to make Test-Driven Development a productive and enjoyable experience" Testing with RSpec # spec/bowling_spec.rb require 'bowling' describe Bowling, "#score" do it "returns 0 for all gutter game" do bowling = Bowling.new 20.times { bowling.hit(0) } bowling.score.should eq(0) end end $ rspec bowling_spec.rb --format nested Bowling#score returns 0 for all gutter game Finished in 0.007534 seconds 1 example, 0 failures
  45. 45. Who uses Ruby? ● http://www.shopify.com/ ● http://www.yellowpages.com/ ● https://github.com/ ● https://www.heroku.com/ ● https://twitter.com ● http://www.hulu.com/ ● http://www.scribd.com/ ● http://www.slideshare.net/ ● http://www.soundcloud.com/ ● http://www.prada.com Ruby is used for both web and system programming Ruby is used by both startups and enterprise companies (Someone you might know)
  46. 46. This brief introduction is just to be considered as a teaser.
  47. 47. Have Fun & Happy Coding

×