Ruby for Java Developers
Upcoming SlideShare
Loading in...5
×
 

Ruby for Java Developers

on

  • 5,602 views

Ruby introduction specially for Java Developers.

Ruby introduction specially for Java Developers.

Statistics

Views

Total Views
5,602
Views on SlideShare
4,076
Embed Views
1,526

Actions

Likes
8
Downloads
57
Comments
3

6 Embeds 1,526

http://robert-reiz.com 1520
http://kred.com 2
https://twitter.com 1
http://pinterest.com 1
http://webcache.googleusercontent.com 1
http://www.pinterest.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • @rmetzler Just updated the slide.
    Are you sure you want to
    Your message goes here
    Processing…
  • @rmetzler True story. I will update the slides! Thanks for the hint.
    Are you sure you want to
    Your message goes here
    Processing…
  • slide 30:
    the amount of code might have been neccessary in earlier Ruby versions, but at least in Ruby 1.9.3 this one line is efficient:

    puts File.read 'text_file.txt'
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Ruby for Java Developers Ruby for Java Developers Presentation Transcript

  • Ruby for Java Developers ! Robert Reiz
  • Robert Reiz http:/ /robert-reiz.com https:/ /twitter.com/robertreiz ! http:/ /about.me/robertreiz ! http:/ /www.VersionEye.com
  • Agenda History Java/Ruby Culture Background Java/Ruby Tech. Background Ruby Lang Rails - Short Intro + Tools Rails Demo App Performance Else The End
  • A Presentation is no Documentation A good presentation supports only the speaker
  • History Yukihiro Matsumoto in Japan 1993 first ideas 1995 Version 0.95 released
  • History "I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. That's why I decided to design my own language." - Matsumoto
  • History "Often people, especially computer engineers, focus on the machines. They think, "By doing this, the machine will run faster. By doing this, the machine will run more effectively. By doing this, the machine will something something something." They are focusing on machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the machines. We are the masters. They are the slaves." - Matsumoto
  • History for (int i = 0 ; i < 3 ; i++){ System.out.println(“Hallo World”); } 3.times{ print “Hallo World” }
  • History Language developed by Open Standards Promotion Center of the InformationTechnology Promotion Agency 2011: Japanese Industrial Standard (JIS X 3017) 2012: International standard (ISO/IEC 30170)
  • Culture Background “Java Programmers are writing strange Ruby Code.”
  • Java Culture JME Java for Desktops (Swing, AWT, JavaFX) J EE
  • Java Culture = Enterprise Culture Enterprise Environment
  • Java Culture Waterfall Servlet LDAP Intranet Eclipse Excel Application Server Oracle Jira Deadlines Outlook Requirements SVN SLAs EJB
  • Ruby Culture Start-Up Culture in Silicon Valley
  • Ruby Culture Start-Up Environment (Epicenter Cafe @ SF)
  • Ruby Culture Start-Up Environment (The Summit @ SF)
  • Ruby Culture Hackathon
  • Fail fast Fail early
  • Ruby Culture Login with Twitter / Facebook OAuth Cloud Internet GMail SaaS Agile PostgreSQL SimpleNote RTM Heroku NoSQL Textmate Dropbox Ideas GitHub
  • Java Tech. Background WAR EAR WAR EAR WAR App-Server DB SAP LDAP This makes sense for big companies with different apartments. But it doesn’t make sense for a small Start-Up!
  • Ruby Tech. Background In a typical Ruby environment there is usually ... No SAP No LDAP No Oracle No App-Server No WAR No EAR
  • Ruby Tech. Background Just the App! Application Everything else is secondary!
  • Java Language 640 Pages
  • Java Language Inheritance Polymorphismus AutoBoxing Interfaces Object Oriented Annotations Generics static typing Enums
  • Java Language More language features don’t make a language better. Just more complicated and more difficult to learn. Without monster tools like Eclipse it is nearly not possible to use the language.
  • Can you write down the Java code to open this file and output the content? ! - Without IDE - Without Google text_file.txt
  • Java import java.io.*; ! class FileRead { public static void main(String args[]) { try{ FileInputStream fstream = new FileInputStream("text_file.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { System.out.println (strLine); } in.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
  • Ruby puts File.read 'text_file.txt'
  • Python f = open('text_file.txt', 'r') Perl open FILE, "text_file.txt" or die $!;
  • Ruby Language Polymorphismus Inheritance Object Oriented Duck typing dynamic typing
  • Ruby Language No Interfaces No static types No Generics No Annotations
  • Java Ruby package xyz; ! import xyz; ! public class User { ! public void sayHello(){ System.out.println(“Hello”); } ! class User ! def say_hello p “Hello” end ! } end User user = new User() user.sayHello() user = User.new user.say_hello
  • Java Ruby package xyz; ! import xyz; ! class User ! def say_hello p “Hello” end public class User { ! public void sayHello(){ System.out.println(“Hello”); } ! private ! ! private String secretHero(){ return “secret hero”; } ! } def secret_hero “secret hero” end ! end
  • Java public String doubleIt(String name){ result = name + “ ” + name; return result; } Ruby def double_it name "#{name} #{name}" end
  • Java public String greetz(String name){ if (name != null){ result = “Hello” + name; else { result = “Hello”; } System.out.println( result ); }
  • Ruby def greetz( name ) if !name.nil? p "Hello #{name}" else p “Hello” end end
  • Ruby def greetz(name) p "Hello #{name}" if name p “Hello” unless name end
  • Ruby def greetz(name = “Rob”, say_name = true) p "Hello #{name}" if say_name p “Hello” unless say_name end user.greetz(“Bob”, false) user. greetz(“Bob”) user. greetz()
  • Java List<String> list = new ArrayList<String>(); ! list.add("Spiderman"); list.add("Batman"); list.add("Hulk"); ! for (String name : list){ System.out.println(name); }
  • Ruby names = Array.new names << “Hans” names << “Tanz” names[0] names[1] names.first names.last
  • Ruby names = [‘Spiderman’, ‘Batman’, ‘Hulk’] names.each do |name| print “#{name}” end
  • Ruby hash = Hash.new hash[“a”] = 100 hash[“b”] = 200 hash[“a”] hash.delete(“a”) hash.first hash.last hash.each {|key, value| puts "#{key} is #{value}" } hash.each_key {|key| puts key }
  • irb
  • Ruby on Rails Initial Release 2004 David Heinemeier Hansson Web application framework MIT License http:/ /rubyonrails.org/
  • Ruby on Rails activesupport : 3.2.8 bundler : ~>1.0 activerecord : 3.2.8 actionpack : 3.2.8 activeresource : 3.2.8 actionmailer : 3.2.8 railties : 3.2.8 http:/ /www.versioneye.com/package/rails
  • Ruby on Rails MVC Framework Convention over Configuration KIS Testable No UI Components You are in control
  • Ruby on Rails REST Stateless Session in cookies OR database
  • Ruby on Rails http:/ /www.myapp.com/photos http:/ /www.myapp.com/photos/17 http:/ /www.myapp.com/photos/17/edit
  • Bundler - Gemfile source 'https:/ /rubygems.org' ! gem 'rails', '3.2.6' gem 'sqlite3' gem 'jquery-rails' ! # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1' gem 'uglifier', '>= 1.0.3' end
  • Environments development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 ! test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000 ! production: adapter: sqlite3 database: db/production.sqlite3 pool: 5 timeout: 5000 export RAILS_ENV=test export RAILS_ENV=production export RAILS_ENV=development
  • Rake require File.expand_path('../config/application', __FILE__) ! Myapp::Application.load_tasks rake db:create rake routes
  • Ruby on Rails DEMO live coding
  • Performance Ruby is slower than Java! ! ... True! But ...
  • Performance Client Request Response WEB Server 40 % 20 % READ, WRITE Response 40 % DB
  • Performance Request Response 1 HTML Page WEB Server N - Requests to load additional Resources
  • Performance
  • Performance
  • Performance Performance opt. for Web Apps. Minify Uglify CSS Stripes Opt. HTML Opt. Database Access
  • Performance http:/ /guides.rubyonrails.org/asset_pipeline.html http:/ /tools.pingdom.com/fpt/
  • Who is using Ruby? Ruby is just good small projects. Right? -> Right! Small Projects like ...
  • -> $ 800 Million worth
  • -> $ 1 Billion worth
  • Count of Open Source Projects Java Java Ruby PHP 0 12500 25000 37500 50000 4061 PHP R 12320 R Node.JS 23439 Node.JS Python 43620 Python Ruby 48034 2973
  • Ruby on Rails is very good solution for WebApplications!
  • What is not good for?
  • It is not good for ... Long living batch jobs parsing 2 million documents Use Java or C for that kind of jobs.
  • Links http:/ /www.ruby-lang.org/en/ http:/ /rubyonrails.org http:/ /ruby.railstutorial.org http:/ /rubygems.org/ http:/ /www.heroku.com http:/ /travis-ci.org
  • Links http:/ /www.engineyard.com/ https:/ /www.dotcloud.com/ http:/ /www.CloudControl.com/ http:/ /jruby.org/ http:/ /www.ironruby.net/
  • ???