jruby - programmer's best friend on jvm

41
Raimonds Simanovskis Programmer’s Best Friend on JVM

Upload: rsim

Post on 16-May-2015

1.190 views

Category:

Technology


0 download

DESCRIPTION

Presentation at Java Day Riga 2012 conference

TRANSCRIPT

Page 1: JRuby - Programmer's Best Friend on JVM

Raimonds Simanovskis

Programmer’s BestFriend on JVM

Page 2: JRuby - Programmer's Best Friend on JVM

Raimonds Simanovskisgithub.com/rsim

@rsim

Page 3: JRuby - Programmer's Best Friend on JVM

The easiest Business Intelligence tool on the Web

Page 4: JRuby - Programmer's Best Friend on JVM

What isRuby?

Page 5: JRuby - Programmer's Best Friend on JVM

object-orienteddynamic

programming language

simple from outside

powerful insideYukihiro

Matsumotoor “Matz”

Page 6: JRuby - Programmer's Best Friend on JVM

Classes

Page 7: JRuby - Programmer's Best Friend on JVM

Single Inheritance

Page 8: JRuby - Programmer's Best Friend on JVM

Constructor

Page 9: JRuby - Programmer's Best Friend on JVM

No Type Declarations

Page 10: JRuby - Programmer's Best Friend on JVM

Instance Variables

Page 11: JRuby - Programmer's Best Friend on JVM

Last expression is always return value

Page 12: JRuby - Programmer's Best Friend on JVM

.new is just a class method

Page 13: JRuby - Programmer's Best Friend on JVM

Blocks / ClosuresAnonymous function as argument

Page 14: JRuby - Programmer's Best Friend on JVM

Modules

Page 15: JRuby - Programmer's Best Friend on JVM

Metaprogramming

Page 16: JRuby - Programmer's Best Friend on JVM

Classes/Modules are open

Page 17: JRuby - Programmer's Best Friend on JVM
Page 18: JRuby - Programmer's Best Friend on JVM

Integration with Java

Embed JRuby asscripting engine

Use Java classesfrom JRuby

Page 19: JRuby - Programmer's Best Friend on JVM

Embed JRuby

Page 20: JRuby - Programmer's Best Friend on JVM

Embed JRuby

Page 21: JRuby - Programmer's Best Friend on JVM

Use Java classes from JRuby

Demo

Page 22: JRuby - Programmer's Best Friend on JVM

Build with Rake

Page 23: JRuby - Programmer's Best Friend on JVM

Test with Test::Unit or RSpec

Page 24: JRuby - Programmer's Best Friend on JVM

Test with Test::Unit or RSpec

Page 25: JRuby - Programmer's Best Friend on JVM

Ruby on RailsWeb applications development framework

Model View Controller (MVC) architecture

Convention over Configuration

Don’t Repeat Yourself (DRY)

Focused on developer productivity

Agile software development approach

Page 26: JRuby - Programmer's Best Friend on JVM

MVC Architecture

ActionController

ActiveRecord

ActionView

Browser

Request Router

Response

Database

SQL

Page 27: JRuby - Programmer's Best Friend on JVM

ActiveRecord (Model)class CreatePosts < ActiveRecor::Migration def self.up create_table :posts do |t| t.string :title t.text :body t.timestamps end endend

CREATE TABLE posts ( id NUMBER(38) NOT NULL, title VARCHAR2(255), body CLOB, created_at DATE, updated_at DATE);CREATE SEQUENCE posts_seq;

class Post < ActiveRecord::Base # nothing here!endpost = Post.newpost.title = "First post"post.savepost = Post.find(1)puts post.name # output: "First post"

Page 28: JRuby - Programmer's Best Friend on JVM

ActionControllerclass PostsController < ApplicationController # GET /posts def index @posts = Post.all end

# GET /posts/1 def show @post = Post.find(params[:id]) end

# GET /posts/new def new @post = Post.new end

# ...end

Page 29: JRuby - Programmer's Best Friend on JVM

ActionView

<h1>Posts</h1><% @posts.each do |post| %> <h2><%= post.title %></h2> <h3>Created at <%= post.created_at %></h3> <p><%= post.body %></p><% end %>

Page 30: JRuby - Programmer's Best Friend on JVM

JRuby deployment<insert app server here>

Java app sever

Application WAR file

JRuby Gems

Application

Application source

warbler

Page 31: JRuby - Programmer's Best Friend on JVM

JRuby deployment

Web Server

Trinidad JRubyApache Tomcat

ApplicationApplication

sourcedeploy

Gems

Page 32: JRuby - Programmer's Best Friend on JVM

JRuby deployment

Page 33: JRuby - Programmer's Best Friend on JVM

eazyBI case studyRuby on Rails application

JRubyJetty

Application Gems

.com

deploy

Mondrian OLAP engine

Apache Batik SVG toolkit

Packaged application

Application Gems

Privatepackage

pluginOSGi bundleJRuby *.jar

Application Gems

jruby-rack

package

SQL Server

Page 34: JRuby - Programmer's Best Friend on JVM

JRuby 1.7 and Java 7

invokedynamic

Page 35: JRuby - Programmer's Best Friend on JVM

Ruby method calls

Page 36: JRuby - Programmer's Best Friend on JVM

Ruby method calls

Page 37: JRuby - Programmer's Best Friend on JVM

Ruby method calls

Page 38: JRuby - Programmer's Best Friend on JVM

Ruby method calls

Page 39: JRuby - Programmer's Best Friend on JVM

Ruby method calls

Page 40: JRuby - Programmer's Best Friend on JVM

JRuby performance improvements

base64 richards neural mandelbrot redblack0

1.25

2.5

3.75

5

1.3461.538

1.914 1.8061.565

2.658

3.443.66

4.226 4.32

Times Faster than Ruby 1.9.3JRuby/Java 6 JRuby/Java 7

Page 41: JRuby - Programmer's Best Friend on JVM

JRuby BenefitsEasy to learn for Java programmers

Easy to mix Ruby and Java

Useful frameworks and libraries

Ruby community

Higher productivity for many tasks