• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Java, Ruby & Rails
 

Java, Ruby & Rails

on

  • 2,813 views

An introduciton to the ruby/jruby ecosystem. Also touching a bit on Rails. Presented internally for our Java consultants

An introduciton to the ruby/jruby ecosystem. Also touching a bit on Rails. Presented internally for our Java consultants

Statistics

Views

Total Views
2,813
Views on SlideShare
2,794
Embed Views
19

Actions

Likes
2
Downloads
23
Comments
0

2 Embeds 19

http://www.slideshare.net 17
https://www.linkedin.com 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

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…
Post Comment
Edit your comment
  • 15/01/10

Java, Ruby & Rails Java, Ruby & Rails Presentation Transcript

  • Java, Ruby & Rails
  • The Java platform
    • “ It’s all about the Java Virtual Machine. That’s the integration hub.” Gosling, Sun Tech Days 2007
    • Lots of new languages for the JVM
      • Scala, Clojure, Groovy, Jython, (J)Ruby, JavaScript (Rhino), JavaFX
    • The DaVinci Machine
      • JSR-292
      • Target JDK 7
      • invokedynamic instruction
  • Why Ruby?
    • Ubiquity
      • C-Ruby (MRI)
      • JRuby
      • IronRuby (.NET)
      • Rubinius, Maglev, YARV
    • Scripting
      • java
      • shebang/backticks
    • Rails Framework
    • Support from Sun, Thoughtworks
    • Most likely to succeed?
  • What is Ruby?
    • Created by Yukihiro Matsumoto (Matz) in 1993
    • “ A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.”
    • The principle of least surprise
    • Runtime efficiency not a top priority
    • “ More powerful than Perl, more OO
    • than Python”
    • MRI is the specification
      • RubySpec is in the works
  • Ruby Characteristics
    • Interpreted
    • Object oriented
      • ” myString”.upcase
      • 2_500.+2
      • 44.modulo 5
    • Reflective
    • Garbage collected
    • Duck typing
      • If it walks like a duck and quacks
      • like a duck it must be a duck
  • Dynamic features
    • Reopen existing classes
      • redefine methods
      • “ monkeypatching”
    • Meta-programming
    • Method aliasing
      • alias_method :validates_size_of , :validates_length_of
    • method_missing
      • Eg provide a generic sort method sort_by_x
    • Closures
  • Core Ruby tools
    • (j)ruby
      • the interpreter
    • (j)irb
      • interactive ruby, ~readline support, tab completion
    • ri
      • ruby interactive ~man pages
    • rdoc
      • html doc ~javadoc
    • rake
      • ant/make for ruby
    • gem
      • package manager
  • Ruby anatomy
    • Classes are CamelCased
    • Methods are under_scored
    • Generally no need for curly braces, parentheses, semicolon or return statement
      • code more compact
    • Comments
      • =begin block comment =end
      • # line comment
    • Variables
      • Constant
      • @@classVariable
      • @instanceVariable
      • localVariable
    • :symbol
  • Example
  • Ruby structure
    • Modules
      • Module::Class
      • Mix-ins interfaces with functionality
      • Namespace
    • Subclass < Superclass
      • Single inheritance only
    • Files are named *.rb
      • can hold many classes
    • require ’file’
    • include Module
    • searches $LOAD_PATH
  • Access modifiers
    • private
      • Private to this instance (might be a subclass)
      • You can’t specify the receiver, not even self
    • protected
      • Can be called by instances of the same class
      • Eg use for comparators
    • public
      • FFA
    • private :method or private (until end)
    • The modifiers are methods, not keywords
  • Testing
    • Test::Unit::TestCase
      • xUnit for ruby
    • JRuby to test Java code?
      • JtestR to invoke
      • Code coverage
      • might be an issue
    • RSpec
      • BDD
  • Method signature - Java
    • Method overloading
    • Number of method signatures increases fast if flexibility is wanted
  • Method signature – PL/SQL
    • Named parameters
    • Still have to change method signature too add parameters
  • Method signature – Ruby
    • Hash as optional parameter, not named parameters
    • No need to change method signature
    • Hash doesn’t need curly braces
    • Method overload unavailable
    • *args => arguments array
  • More syntax examples
    • =~ regexp matcher
      • myString =~ /[0-9]+/
    • %w[] String array
      • myArray = %w[ruby java haskell]
    • {||} or do || end closures
      • (and embedded variables)
      • myHash.each { |k, v| puts k+’ is ‘+v }
      • myHash.each do |key, val|
      • puts “#{key} is #{val}”
      • end
  • Ruby on Rails
    • MVC Framework
    • “ Rails is the most well thought-out web development framework I’ve ever used. And that’s in a decade of doing web applications for a living. I’ve built my own frameworks, helped develop the Servlet API, and have created more than a few web servers from scratch. Nobody has done it like this before.” -James Duncan Davidson, Creator of Tomcat and Ant
    • “ Rails is the killer app for Ruby.” Yukihiro Matsumoto, Creator of Ruby
  • RoR principles
    • Opinionated software
    • Convention over configuration
    • DRY
    • REST
      • GET /products #get all
      • GET /products/42 #get id=42
      • POST /products #create
    • Fast feedback loop
      • just reload, no compile
    • Rails itself is a gem
  • Ruby on Rails concepts
    • rails <appname> generates skeleton
    • routes.rb ~struts-config.xml
    • *.html.erb ~JSP
    • Generators
      • Generates model, view, controller, tests
    • Partials (html.erb snippets)
    • Plugins (instead of gems)
    • Default database is sqlite3 (via JDBC for JRuby)
    • Filters (defined in controller)
  • RoR tools
    • rails <appname> -d <database>
    • script/generate scaffold Person name:string
    • script/server
    • script/console
      • irb with access to the application
    • script/dbconsole
      • enter SQL
    • script/server –debugger
      • debugger in the code drops to console
  • ActiveRecord O/R mapping
    • Db migrations, dev, test, prod
      • up and down
      • database agnostic
      • rake db:migrate
      • config/database.yml
    • Opinionated software
      • primary key named id
      • pluralization class Book => db books
  • RoR model example
    • class BlogPost < ActiveRecord::Base
    • belongs_to :author
    • has_many :comments
    • validates_presence_of :title
    • end
    • comments table needs blog_post_id
    • blog_posts table needs author_id
    • New post need title field
  • A/R Metaprogramming
  • A/R Metaprogramming
  • ActiveSupport::TestCase
    • Inherits Test::Unit::TestCase
      • Provides helpers, eg http calls
    • <app>/test
      • functional
      • integration
      • unit
    • fixtures/fixtures.yml
    • rake
  • Jruby Motivation
    • The JVM
    • Sneak into the enterprise
    • Reuse infrastructure
    • Integrate with Java applications
    • Performance and scalability
  • JRuby on Rails
    • Develop as Java
      • Netbeans
      • Eclipse
    • Integrate with Java
      • Call EJBs
      • Use JMS queues
      • Use JNDI
      • Use JAAS
    • Deploy on Java
      • As *.war using warbler
      • Rails deployer (JBoss, Glassfish)
  • Java integration
    • include Java / require ”java”
    • include Java::JavaxSwing
    • include_class &quot;javax.naming.InitialContext”
    • require ”path/to/my.jar”
    • prefix javaclasses to avoid name collisions
      • String => JString
      • include_class 'java.lang.String’ {|package,name| &quot;J#{name}&quot; }
    • Method alias
      • System.currentTimeMillis => System.current_time_millis
    • Getters and setters behaves like attr_accessor fields
  • IDE support
    • Eclipse - DLTK (Dynamic Languages Toolkit)
      • Eclipse foundation plugin
      • Support for TCL, Python, Ruby
      • No Rails
    • Eclipse - Aptana RadRails
      • RDT Ruby Editor
      • Rails support generators/scripts
      • Visual debug
      • Testrunner
    • Netbeans
      • Official plugin
  • Conclusion
    • Ruby is sweet!
      • Syntactic sugar
      • Fun to work with
    • Ruby is useful!
      • Integrate with Java
      • OO scripting
      • Rails is probably fast enough
    • Ruby is hard!
      • “ Good programmers become better, bad programmers become worse”
      • Test, test, test
  • Thank you and Namaste
  • Contact © Devoteam Consulting A/S. This document is not to be copied or reproduced in any way without the express permission of Devoteam Consulting. AUSTRIA BELGIUM CZECH REPUBLIC DENMARK FRANCE MOROCCO NETHERLANDS NORWAY POLAND SAUDI ARABIA SPAIN SWEDEN SWITZERLAND UNITED ARAB EMIRATES UNITED KINGDOM +46 (0)733-812135 Phone: [email_address] E-mail: Address Peter Sönnergren Person: CONTACT Author: Date: # ID: DOCUMENT