JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing...
Transcript of JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing...
![Page 1: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/1.jpg)
Ola Binicomputational metalinguist
[email protected] http://olabini.com/blog
698E 2885 C1DE 74E3 2CD5 03AD 295C 7469 84AF 7F0C
JRuby For The Win
onsdag 12 juni 13
![Page 2: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/2.jpg)
Logistics and Demographics
onsdag 12 juni 13
![Page 3: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/3.jpg)
LAST MINUTE DEMO
onsdag 12 juni 13
![Page 4: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/4.jpg)
Implementation of the Ruby language
Java 1.6+
1.8.7 and 1.9.3 compatible (experimental 2.0 support)
Open Source
Created 2001
Embraces testing
Current version: 1.7.4
Support from EngineYard, RedHat & ThoughtWorks
JRuby
onsdag 12 juni 13
![Page 5: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/5.jpg)
Threading
Unicode
Performance
Memory
Explicit extension API and OO internals
Libraries and legacy systems
Politics
Why JRuby?
onsdag 12 juni 13
![Page 6: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/6.jpg)
InvokeDynamic
onsdag 12 juni 13
![Page 7: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/7.jpg)
Most compatible alternative implementation
Native threads vs Green threads
No C extensions (well, some)
No continuations
No fork
ObjectSpace disabled by default
JRuby Differences
onsdag 12 juni 13
![Page 8: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/8.jpg)
Simple JRuby
onsdag 12 juni 13
![Page 9: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/9.jpg)
Java types == Ruby types
Call methods, construct instances
Static generation of classes
camelCase or snake_case
.getFoo(), setFoo(v) becomes .foo and .foo = v
Interfaces can be implemented
Classes can be inherited from
Implicit closure conversion
Extra added features to Rubyfy Java
Java integration
onsdag 12 juni 13
![Page 10: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/10.jpg)
Ant+Rake
onsdag 12 juni 13
![Page 11: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/11.jpg)
Clojure STM
onsdag 12 juni 13
![Page 12: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/12.jpg)
Web
onsdag 12 juni 13
![Page 13: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/13.jpg)
Rails
onsdag 12 juni 13
![Page 14: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/14.jpg)
Sinatra
onsdag 12 juni 13
![Page 15: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/15.jpg)
Trinidad
onsdag 12 juni 13
![Page 16: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/16.jpg)
SwingSwing API == large and complex
Ruby magic simplifies most of the tricky bits
Java is a very verbose language
Ruby makes Swing fun (more fun at least)
No consistent cross-‐platform GUI library for Ruby
Swing works everywhere Java does
onsdag 12 juni 13
![Page 17: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/17.jpg)
Swing -‐ the direct approachjava_import javax.swing.JFramejava_import javax.swing.JButton
frame = JFrame.new("Swing is easy now!")frame.set_size 300, 300frame.always_on_top = true
button = JButton.new("Press me!")button.add_action_listener do |evt| evt.source.text = "Don't press me again!" evt.source.enabled = falseend
frame.add(button)frame.show
onsdag 12 juni 13
![Page 18: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/18.jpg)
Swing -‐ Cheri (builder)include Cheri::Swing
frame = swing.frame("Swing builders!") { |form| size 300, 300 box_layout form, :Y_AXIS content_pane { background :WHITE }
button("Event binding is nice") { |btn| on_click { btn.text = "You clicked me!" } }}
frame.visible = true
onsdag 12 juni 13
![Page 19: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/19.jpg)
Swing -‐ Profligacyclass ProfligacyDemo java_import javax.swing.* include Profligacy
def initialize layout = "[<translate][*input][>result]" @ui = Swing::LEL.new(JFrame, layout) {|cmps, ints| cmps.translate = JButton.new("Translate") cmps.input = JTextField.new cmps.result = JLabel.new
translator = proc {|id, evt| original = @ui.input.text translation = MyTranslator.translate(original) @ui.result.text = translation }
ints.translate = {:action => translator} } endend
onsdag 12 juni 13
![Page 20: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/20.jpg)
Swing -‐ MonkeyBars (tools)GUI editor friendly (e.g. NetBeans “Matisse”)
Simple Ruby MVC based API
Combines best of both worlds
onsdag 12 juni 13
![Page 21: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/21.jpg)
TestingRuby frameworks
Cucumber
JtestR
onsdag 12 juni 13
![Page 22: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/22.jpg)
The problem with mockingIt works fine while staying in Ruby-‐land
Setting expectations to be consumed by Java is problematic
onsdag 12 juni 13
![Page 23: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/23.jpg)
The interface
package org.test;
public interface Quux { String one(); String two();}
onsdag 12 juni 13
![Page 24: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/24.jpg)
The class
package org.test;
public class Foo implements Quux { public String one() { return "hello"; }
public String two() { return "goodbye"; }}
onsdag 12 juni 13
![Page 25: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/25.jpg)
The consumerpackage org.test;
public class Bar { public void doFoo(Foo foo) { System.out.println("Foo one: " + foo.one()); System.out.println("Foo two: " + foo.two()); }
public void doQuux(Quux q) { System.out.println("Quux one: " + q.one()); System.out.println("Quux two: " + q.two()); }}
onsdag 12 juni 13
![Page 26: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/26.jpg)
Mocking an interface
describe "Foo and Bar with RSpec mocking" do it "can mock out parts of interface methods with RSpec" do f = org.test.Quux.new b = org.test.Bar.new f.should_receive(:one).and_return "Canned answer 1 from RSpec" f.should_receive(:two).and_return "Canned answer 2 from RSpec"
b.do_quux f endend
onsdag 12 juni 13
![Page 27: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/27.jpg)
Mocking a class
describe "Foo and Bar with RSpec mocking" do it "can mock out parts of instance methods with RSpec" do f = org.test.Foo.new b = org.test.Bar.new f.should_receive(:one).and_return "Canned answer 1 from RSpec" f.should_receive(:two).and_return "Canned answer 2 from RSpec"
b.do_foo f endend
onsdag 12 juni 13
![Page 28: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/28.jpg)
The output
Quux one: Canned answer 1 from RSpecQuux two: Canned answer 2 from RSpec.Foo one: helloFoo two: goodbyeF
1)Spec::Mocks::MockExpectationError in 'Foo and Bar with RSpec mocking can mock out parts of instance methods with RSpec'org.test.Foo@7570b819 expected :one with (any args) once, but received it 0 times./rspec_mocking_spec.rb:18:
Finished in 0.321 seconds
2 examples, 1 failure
onsdag 12 juni 13
![Page 29: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/29.jpg)
The JtestR solution
onsdag 12 juni 13
![Page 30: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/30.jpg)
CucumberBehavior driven development
Plain text stories
Used to describe high level behavior
“Business-‐readable domain specific language”
Serves as documentation, automated tests and dev aid
Supports table-‐based tests
onsdag 12 juni 13
![Page 31: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/31.jpg)
Erlang+Ruby
onsdag 12 juni 13
![Page 32: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/32.jpg)
Google AppEngineJRuby runs on it
JRuby-‐rack supports it
Google gems
Startup time
Merb, Ramaze and Sinatra easy options
Rails works
onsdag 12 juni 13
![Page 33: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/33.jpg)
Mobile
onsdag 12 juni 13
![Page 34: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/34.jpg)
Usage
onsdag 12 juni 13
![Page 35: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/35.jpg)
onsdag 12 juni 13
![Page 36: JRubyForThe$ Winwinstonyw.com/assets/downloads/JRubyForTheWin.pdf · Swing Swing$API$==$large$and$complex Ruby$magic$simplifies$most$of$the$tricky$bits Java$is$a$very$verbose$language](https://reader036.fdocuments.us/reader036/viewer/2022070112/6056726280329f1c712ffdb0/html5/thumbnails/36.jpg)
Questions?
OLA BINI
http://olabini.com
@olabini
onsdag 12 juni 13