0
Ruby for Java
Developers
!

Robert Reiz
Robert Reiz

http:/
/robert-reiz.com

https:/
/twitter.com/robertreiz

!

http:/
/about.me/robertreiz

!

http:/
/www.Vers...
Agenda
History

Java/Ruby Culture Background

Java/Ruby Tech. Background

Ruby Lang

Rails - Short Intro + Tools

Rails De...
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 ...
History
"Often people, especially computer engineers, focus on
the machines. They think, "By doing this, the machine
will ...
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: Japane...
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

Requirem...
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

N...
Java Tech. Background
WAR

EAR

WAR

EAR

WAR

App-Server
DB

SAP

LDAP

This makes sense for big companies with different...
Ruby Tech. Background
In a typical Ruby environment there is usually ...
No SAP

No LDAP

No Oracle

No App-Server

No WAR...
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

Enu...
Java Language
More language features don’t make a language
better. Just more complicated and more difficult
to learn.
Witho...
Can you write down the Java code to open this
file and output the content? 

!

- Without IDE

- Without Google

text_file.t...
Java
import java.io.*;


!
class FileRead {



public static void main(String args[]) {

try{

FileInputStream fstream = n...
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”);...
Java

Ruby

package xyz;

!

import xyz;

!

class User 

!

def say_hello

p “Hello”

end


public class User {

!

publi...
Java
public String doubleIt(String name){

result = name + “ ” + name;

return result;

}

Ruby
def double_it name

"#{nam...
Java
public String greetz(String name){ 

if (name != null){

result = “Hello” + name;

else {

result = “Hello”; 

}

Sys...
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...
Java
List<String> list = new ArrayList<String>();

!

list.add("Spiderman");

list.add("Batman");

list.add("Hulk");

!

f...
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, val...
irb
Ruby on Rails
Initial Release 2004

David Heinemeier Hansson

Web application framework

MIT License

http:/
/rubyonrails....
Ruby on Rails
activesupport : 3.2.8 

bundler : ~>1.0 

activerecord : 3.2.8 

actionpack : 3.2.8 

activeresource : 3.2.8...
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 use...
Environments
development:

adapter: sqlite3

database: db/development.sqlite3

pool: 5

timeout: 5000


!
test:

adapter: ...
Rake
require File.expand_path('../config/application', __FILE__)

!

Myapp::Application.load_tasks


rake db:create
rake ro...
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
...
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:...
Links
http:/
/www.engineyard.com/

https:/
/www.dotcloud.com/

http:/
/www.CloudControl.com/

http:/
/jruby.org/

http:/
/...
???
Upcoming SlideShare
Loading in...5
×

Ruby for Java Developers

7,065

Published on

Ruby introduction specially for Java Developers.

Published in: Technology
3 Comments
30 Likes
Statistics
Notes
No Downloads
Views
Total Views
7,065
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
91
Comments
3
Likes
30
Embeds 0
No embeds

No notes for slide
  • \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
  • Transcript of "Ruby for Java Developers"

    1. 1. Ruby for Java Developers ! Robert Reiz
    2. 2. Robert Reiz http:/ /robert-reiz.com https:/ /twitter.com/robertreiz ! http:/ /about.me/robertreiz ! http:/ /www.VersionEye.com
    3. 3. Agenda History Java/Ruby Culture Background Java/Ruby Tech. Background Ruby Lang Rails - Short Intro + Tools Rails Demo App Performance Else The End
    4. 4. A Presentation is no Documentation A good presentation supports only the speaker
    5. 5. History Yukihiro Matsumoto in Japan 1993 first ideas 1995 Version 0.95 released
    6. 6. 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
    7. 7. 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
    8. 8. History for (int i = 0 ; i < 3 ; i++){ System.out.println(“Hallo World”); } 3.times{ print “Hallo World” }
    9. 9. 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)
    10. 10. Culture Background “Java Programmers are writing strange Ruby Code.”
    11. 11. Java Culture JME Java for Desktops (Swing, AWT, JavaFX) J EE
    12. 12. Java Culture = Enterprise Culture Enterprise Environment
    13. 13. Java Culture Waterfall Servlet LDAP Intranet Eclipse Excel Application Server Oracle Jira Deadlines Outlook Requirements SVN SLAs EJB
    14. 14. Ruby Culture Start-Up Culture in Silicon Valley
    15. 15. Ruby Culture Start-Up Environment (Epicenter Cafe @ SF)
    16. 16. Ruby Culture Start-Up Environment (The Summit @ SF)
    17. 17. Ruby Culture Hackathon
    18. 18. Fail fast Fail early
    19. 19. Ruby Culture Login with Twitter / Facebook OAuth Cloud Internet GMail SaaS Agile PostgreSQL SimpleNote RTM Heroku NoSQL Textmate Dropbox Ideas GitHub
    20. 20. 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!
    21. 21. Ruby Tech. Background In a typical Ruby environment there is usually ... No SAP No LDAP No Oracle No App-Server No WAR No EAR
    22. 22. Ruby Tech. Background Just the App! Application Everything else is secondary!
    23. 23. Java Language 640 Pages
    24. 24. Java Language Inheritance Polymorphismus AutoBoxing Interfaces Object Oriented Annotations Generics static typing Enums
    25. 25. 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.
    26. 26. Can you write down the Java code to open this file and output the content? ! - Without IDE - Without Google text_file.txt
    27. 27. 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()); } } }
    28. 28. Ruby puts File.read 'text_file.txt'
    29. 29. Python f = open('text_file.txt', 'r') Perl open FILE, "text_file.txt" or die $!;
    30. 30. Ruby Language Polymorphismus Inheritance Object Oriented Duck typing dynamic typing
    31. 31. Ruby Language No Interfaces No static types No Generics No Annotations
    32. 32. 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
    33. 33. 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
    34. 34. Java public String doubleIt(String name){ result = name + “ ” + name; return result; } Ruby def double_it name "#{name} #{name}" end
    35. 35. Java public String greetz(String name){ if (name != null){ result = “Hello” + name; else { result = “Hello”; } System.out.println( result ); }
    36. 36. Ruby def greetz( name ) if !name.nil? p "Hello #{name}" else p “Hello” end end
    37. 37. Ruby def greetz(name) p "Hello #{name}" if name p “Hello” unless name end
    38. 38. 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()
    39. 39. Java List<String> list = new ArrayList<String>(); ! list.add("Spiderman"); list.add("Batman"); list.add("Hulk"); ! for (String name : list){ System.out.println(name); }
    40. 40. Ruby names = Array.new names << “Hans” names << “Tanz” names[0] names[1] names.first names.last
    41. 41. Ruby names = [‘Spiderman’, ‘Batman’, ‘Hulk’] names.each do |name| print “#{name}” end
    42. 42. 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 }
    43. 43. irb
    44. 44. Ruby on Rails Initial Release 2004 David Heinemeier Hansson Web application framework MIT License http:/ /rubyonrails.org/
    45. 45. 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
    46. 46. Ruby on Rails MVC Framework Convention over Configuration KIS Testable No UI Components You are in control
    47. 47. Ruby on Rails REST Stateless Session in cookies OR database
    48. 48. Ruby on Rails http:/ /www.myapp.com/photos http:/ /www.myapp.com/photos/17 http:/ /www.myapp.com/photos/17/edit
    49. 49. 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
    50. 50. 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
    51. 51. Rake require File.expand_path('../config/application', __FILE__) ! Myapp::Application.load_tasks rake db:create rake routes
    52. 52. Ruby on Rails DEMO live coding
    53. 53. Performance Ruby is slower than Java! ! ... True! But ...
    54. 54. Performance Client Request Response WEB Server 40 % 20 % READ, WRITE Response 40 % DB
    55. 55. Performance Request Response 1 HTML Page WEB Server N - Requests to load additional Resources
    56. 56. Performance
    57. 57. Performance
    58. 58. Performance Performance opt. for Web Apps. Minify Uglify CSS Stripes Opt. HTML Opt. Database Access
    59. 59. Performance http:/ /guides.rubyonrails.org/asset_pipeline.html http:/ /tools.pingdom.com/fpt/
    60. 60. Who is using Ruby? Ruby is just good small projects. Right? -> Right! Small Projects like ...
    61. 61. -> $ 800 Million worth
    62. 62. -> $ 1 Billion worth
    63. 63. 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
    64. 64. Ruby on Rails is very good solution for WebApplications!
    65. 65. What is not good for?
    66. 66. It is not good for ... Long living batch jobs parsing 2 million documents Use Java or C for that kind of jobs.
    67. 67. 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
    68. 68. Links http:/ /www.engineyard.com/ https:/ /www.dotcloud.com/ http:/ /www.CloudControl.com/ http:/ /jruby.org/ http:/ /www.ironruby.net/
    69. 69. ???
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×