Slide 1

Slide 1 text

Ruby Is dead.

Slide 2

Slide 2 text

Ruby Is now more alive than ever!

Slide 3

Slide 3 text

Who am I? twitter.com/mehowte [email protected] ! " github.com/mehowte # Michal Taszycki gunpowderlabs crossplatformruby.com

Slide 4

Slide 4 text

Remember Javascript? Meteor

Slide 5

Slide 5 text

But now… We have the technology!

Slide 6

Slide 6 text

Opal.rb

Slide 7

Slide 7 text

Opal.rb • Ruby to Javascript compiler • Performant • Version < 1.0, actively developed • Out of the box Rails integration • Interesting libraries start to show up

Slide 8

Slide 8 text

RubyMotion

Slide 9

Slide 9 text

RubyMotion • Compiles Ruby to ObjectiveC runtime • Android Support will be available soon • Native performance • Version > 2.0, actively developed • Widely used in production

Slide 10

Slide 10 text

mruby

Slide 11

Slide 11 text

mruby • Supports ISO ruby standard • Can be embedded into any C application • low memory footprint • Faster than MRI • Works even on Arduino DUE (requires 96KB SRAM) • Promising for Windows desktop applications

Slide 12

Slide 12 text

Is any of them really a Ruby == ? == ? == ?

Slide 13

Slide 13 text

Differences • No require at runtime • No eval at runtime • Methods can have incompatible names • Threads are working • Memory leaks possible

Slide 14

Slide 14 text

Differences • no require at runtime • strings are immutable • symbols are strings • regexps differ • All numbers are floats • no for loop yet ;)

Slide 15

Slide 15 text

Differences • no require at runtime • gems (mrgems) need to be compiled into mruby • no Bignumber support • Regular Expressions unavailable by default • optimized for size (but ofter faster than MRI)

Slide 16

Slide 16 text

Is any of them really a Ruby

Slide 17

Slide 17 text

They’re Ruby enough!

Slide 18

Slide 18 text

Cross Platform Ruby

Slide 19

Slide 19 text

Cross Platform Ruby

Slide 20

Slide 20 text

Interactions

Slide 21

Slide 21 text

Internal interactions Hexagonal Clean Architecture DCI DDD CQRS Cowboy Coding Functional Programming Micro Libraries

Slide 22

Slide 22 text

This is your dreamland! Internal interactions DCI Hexagonal Clean Architecture DCI DDD Cowboy Coding Functional Programming CQRS Micro Libraries

Slide 23

Slide 23 text

Interactions

Slide 24

Slide 24 text

Access From Outside title_label.text = translator.get(:title)

<%= translator.get(:title) %>

Slide 25

Slide 25 text

Access From Outside event_logger.save_event(:user_signed_up) event_logger.save_event(:user_tapped_on_top_left_button) event_logger.save_event(:user_bought_an_in_app_purchase, type: "coin", amount: 1000) event_logger.save_event(:user_signed_in) event_logger.save_event(:user_browsed_products) event_logger.save_event(:user_bought_product, name: "beef_jerky", amount: 35)

Slide 26

Slide 26 text

Interactions

Slide 27

Slide 27 text

Driving from inside # toggle panels - same interface # for animation on all platforms ! image_editor_controller.animate_view( brushes_panel, :horizontall_slide, from: 0, to: -90) ! image_editor_controller.animate_view( shapes_panel, :horizontall_slide, from: -90, to: 0)

Slide 28

Slide 28 text

Interactions

Slide 29

Slide 29 text

class TodoItem def mark_as_done self.done = true end end Async interactions

Slide 30

Slide 30 text

! ! ! # We want to save it afterwards on each platform todo.mark_as_done Async interactions

Slide 31

Slide 31 text

Async interactions Abstract interface Notifications Aspect Oriented Programming

Slide 32

Slide 32 text

class Todo def self.saver=(saver) @saver = saver end ! def mark_as_done self.done = true self.class.saver.save(self) end end Abstract interface

Slide 33

Slide 33 text

Abstract interface Todo.saver = TodoSaver.new(DatabaseAdapter.new) todo.mark_as_done ! # or ! Todo.saver = TodoSaver.new(RestAdapter.new) todo.mark_as_done

Slide 34

Slide 34 text

Abstract interface +Well defined interaction - Core needs to know about use cases +Useful when use cases on each platform are similar

Slide 35

Slide 35 text

Notifications class Todo include Eventable def mark_as_done self.done = true trigger(:marked_as_done, self) end end

Slide 36

Slide 36 text

Notifications todo.on(:marked_as_done) do |todo| save_to_database(todo) end todo.mark_as_done ! # or ! todo.on(:marked_as_done) do |todo| post_to_api(todo) end todo.mark_as_done

Slide 37

Slide 37 text

Notifications +Core doesn’t need to know use cases - Hard to compose interactions !Beware of memory leaks +Useful when use cases on each platform are a bit different

Slide 38

Slide 38 text

AOP class Todo def mark_as_done self.done = true end end

Slide 39

Slide 39 text

AOP class DatabaseTodoSaver include AspectOrientedLibraryOfChoice after Todo, :mark_as_done do |todo| save_to_database(todo) end end

Slide 40

Slide 40 text

AOP class RestTodoSaver include AspectOrientedLibraryOfChoice after Todo, :mark_as_done do |todo| post_to_service(todo) end end

Slide 41

Slide 41 text

AOP +Core is blissfully unaware of surroundings - Platforms need to know about internals !Beware of memory leaks +Useful when use cases on each platform are different

Slide 42

Slide 42 text

Cross Platform Gems • Tell sprockets where to look for files using Opal.append_path • use require as usual (it is translated into Sprockets directive)

Slide 43

Slide 43 text

Cross Platform Gems • Use require only in the gem’s entry point • Add all required files in rubymotion config block

Slide 44

Slide 44 text

Cross Platform Gems It literally takes 20 lines of code http://blog.crossplatformruby.com/universal-ruby-gems-in-20-lines-of-code

Slide 45

Slide 45 text

Suggestions 1.Make a folder named as an app 2.Rename app folders to platform names 3.Keep them together with gems 4.Keep each of those in separate repositories 5.Use semantic versioning (if you work in teams) 6.Break Replace rules with better ones

Slide 46

Slide 46 text

Is it for everyone? (No but there are many use cases)

Slide 47

Slide 47 text

Does it work? (Hell yes!)

Slide 48

Slide 48 text

Ruby is alive

Slide 49

Slide 49 text

Ruby Is taking over the world… … one platform at a time.

Slide 50

Slide 50 text

Want to hear more? twitter.com/mehowte [email protected] ! " github.com/mehowte # Michal Taszycki gunpowderlabs crossplatformruby.com