Opal chapter 4_a_new_hope

70
my-preamble OPAL - CHAPTER 4: A NEW HOPE FORREST CHANG [email protected]

description

Opal presentation given at OC Ruby 7/25/2013

Transcript of Opal chapter 4_a_new_hope

Page 1: Opal chapter 4_a_new_hope

my-preamble

OPAL - CHAPTER 4: ANEW HOPE

FORREST [email protected]

Page 2: Opal chapter 4_a_new_hope
Page 3: Opal chapter 4_a_new_hope

WHO CODES RUBY?

Page 4: Opal chapter 4_a_new_hope

WHO WORKS WITH THE WEB?

Page 5: Opal chapter 4_a_new_hope

WHO LIKES JAVASCRIPT

Page 6: Opal chapter 4_a_new_hope

WHO LIKES RUBY BETTER?

from http://dark--romance.deviantart.com/art/Screamy-and-

Bee-love-Ruby-146852940

Page 7: Opal chapter 4_a_new_hope

YOU ARE MY AUDIENCE

Page 8: Opal chapter 4_a_new_hope

THE PITCH

Page 9: Opal chapter 4_a_new_hope

OPAL WILL MAKE YOU HAPPY

Page 10: Opal chapter 4_a_new_hope

STEP BACK

(from:

)

http://www.celiajohnsononline.com/knee-exercises-osteoarthritis-joint-pain/

Page 11: Opal chapter 4_a_new_hope

WHAT IS OPAL?Ruby to JS Source to Source, similar to CoffescriptRuntime (supports method missing, operator overloading,etc)

Page 12: Opal chapter 4_a_new_hope

TOTALLY AWESOME

Page 13: Opal chapter 4_a_new_hope

AS CODEclass Opal < Ruby include Browser::Access include Javascript::Interaction

runs_in :browser runs_in :nodeend

Page 14: Opal chapter 4_a_new_hope

WHAT'S CURRENTLY UNDERGITHUB.COM/OPAL

Page 15: Opal chapter 4_a_new_hope

PAGE 2

Page 16: Opal chapter 4_a_new_hope

THE RUBY WAY

Matz wrote in an introductory article to Ruby

"For me the purpose of life is partly to have joy. Programmersoften feel joy when they can concentrate on the creative sideof programming, So Ruby is designed to make programmers

happy."

Page 17: Opal chapter 4_a_new_hope

OPAL IS THE RUBY WAY

(from

)

http://www.get-covers.com/do-more-of-what-makes-you-happy/

Page 18: Opal chapter 4_a_new_hope

OPAL IS JDD FOR MEJoy Driven Development

no need for it, but I can't stop codingForrest just loves to write opal (Test Infected parody)

Page 19: Opal chapter 4_a_new_hope

WHAT IF YOU CODE RUBY IN THE BROWSER?

Page 20: Opal chapter 4_a_new_hope

TOP 7 REASONS WHY OPAL WILL MAKE YOUHAPPY

1. It is a viable Ruby2. Greenspun's 10th Rule, Opal Edition3. Solves things the Ruby way4. Tools you already know and love5. Easy integration with Ruby6. Better tools (In Browser)7. A new future

Page 21: Opal chapter 4_a_new_hope

#1 VIABLE - NOT A TOYIn production - 5 + apps, 2 more coming soonReal Ruby1.9.3 - compliant (mostly)passes 1377 rubyspec examplesruns asciidoc gem unmodifiedruns mspec gem unmodifiedcan compile itself

Capable of compiling complex codeIs written in Ruby, easy to contribute

Page 22: Opal chapter 4_a_new_hope

RUBY LANGUAGE FEATURES IN OPALclassesmodules & mixinssingleton methodsmethod_missingarity checkslambdablocksyieldCONSTANTSglobal variables

Page 23: Opal chapter 4_a_new_hope

MORE FEATURESclass variablesinstance variableEnumerableBasicObjectKernelNilClassRangeHashString InterpolationHeredocs%w splits

Page 24: Opal chapter 4_a_new_hope

DON'T UNDERESTIMATE THE POWER OF ABETTER LANGUAGE

opal-irb, opal-inspector, easy to writeleads us to Greenspun's 10th rule

Page 25: Opal chapter 4_a_new_hope

GREENSPUN'S 10TH RULEAny sufficiently complicated C or Fortran program contains

an ad hoc, informally-specified, bug-ridden, slowimplementation of half of Common Lisp.

Page 26: Opal chapter 4_a_new_hope

#2 GREENSPUN'S 10TH RULE, OPAL EDITIONAny sufficiently complicated Javascript program contains an

ad hoc, informally-specified, bug-ridden, slow implementationof half of Ruby

Page 27: Opal chapter 4_a_new_hope

JAVASCRIPT EFFORTS THAT IMITATE RUBY ORRAILS

Page 28: Opal chapter 4_a_new_hope

PROTOTYPE

Page 29: Opal chapter 4_a_new_hope

UNDERSCORE

Page 30: Opal chapter 4_a_new_hope

HTTP://RUBYJS.ORG

Page 31: Opal chapter 4_a_new_hope

STRUKT

Page 32: Opal chapter 4_a_new_hope

STRINGJS

Page 33: Opal chapter 4_a_new_hope

HTTP://JSCLASS.JCOGLAN.COM

Page 34: Opal chapter 4_a_new_hope

HTTP://CODE.GOOGLE.COM/P/JOOSE-JS/

Page 35: Opal chapter 4_a_new_hope

HTTP://BLOG.JAVASCRIPTMVC.COM/?P=61

Page 36: Opal chapter 4_a_new_hope

HTTPS://GITHUB.COM/TOBEYTAILOR/DEF.JS

Page 37: Opal chapter 4_a_new_hope

HTTP://YEHUDAKATZ.COM/2012/01/10/JAVASCRIPT-NEEDS-BLOCKS/

Page 38: Opal chapter 4_a_new_hope

HTTP://WWW.CODEPROJECT.COM/ARTICLES/31452/RAIYA-IN-HUMAX-V0-3-EXTENDING-YOUR-JAVASCRIPT-CLAS

Page 39: Opal chapter 4_a_new_hope

HTTP://WWW.SCATTERPOLL.COM/#TITLE-SLIDE

Page 40: Opal chapter 4_a_new_hope

ACTIVEJS

Page 41: Opal chapter 4_a_new_hope

REDSCRIPT

Page 42: Opal chapter 4_a_new_hope

FORML

Page 43: Opal chapter 4_a_new_hope

OTHER ATTEMPTS TO DO RUBY ON JS

(from:

)

https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS

Page 44: Opal chapter 4_a_new_hope

WHY NOT THE REAL THING?

Page 45: Opal chapter 4_a_new_hope

OPAL IS RUBY

Page 46: Opal chapter 4_a_new_hope

#3 SOLVING THINGS THE RUBY WAYpackaging/modulesjavascript integrationtesting

Page 47: Opal chapter 4_a_new_hope

PACKAGING AND MODULE

Page 48: Opal chapter 4_a_new_hope

JAVASCRIPT MODULES long article

AMDCommonJSHarmony

http://addyosmani.com/writing-modular-js/

Page 49: Opal chapter 4_a_new_hope

MODULESDo This

define( module_id /*optional*/, [dependencies] /*optional*/, definition function /*function for instantiating the module or object*/);// Consider 'foo' and 'bar' are two external modules// In this example, the 'exports' from the two modules loaded are passed as// function arguments to the callback (foo and bar)// so that they can similarly be accessed

And Thisrequire(['foo', 'bar'], function ( foo, bar ) { // rest of your code here foo.doSomething();});

Page 50: Opal chapter 4_a_new_hope

RUBYrequireuses gems

require 'file_or_gem_you_want'

Page 51: Opal chapter 4_a_new_hope

OPALrequireuses gemsopal-sprockets handles requiresalso include templates

require 'file_gem_template_you_want'

Page 52: Opal chapter 4_a_new_hope

FOR NON RAILS STANDALONE - RAKEFILErequire 'bundler/setup'# require 'opal/rake_task'require 'opal'require 'opal-sprockets'

desc "build jqconsole based irb"task :build_jqconsole do

File.open("js/app-jqconsole.js", "w+") do |out| env = Opal::Environment.new env.append_path "examples" env.append_path "opal" out << env["app-jqconsole"].to_s end # system "terminal-notifier -title 'opal-irb build' -message 'js file built'" system "open -a 'Google Chrome' index-jq.html"end

Page 53: Opal chapter 4_a_new_hope

FOR NON RAILS STANDALONE APP-JQCONSOLE.RBrequire 'opal'require 'opal-jquery'require 'opal-parser'require 'opal_irb_jqconsole'

Document.ready? do OpalIrbJqconsole.create("#console")end

Page 54: Opal chapter 4_a_new_hope

JAVASCRIPT INTEGRATIONx strings (backticks %x)method missing

window = windowwindow.location

Page 55: Opal chapter 4_a_new_hope

TESTINGopal-specrake/phantomjsin browser

Page 56: Opal chapter 4_a_new_hope

OPAL-SPEC

Page 57: Opal chapter 4_a_new_hope

#4 THE TOOLS YOU KNOW AND LOVElanguage - Rubyeditor - emacs, vim, sublime, Rubymine, etc.Rakerspec (sorry DHH)guard<fill in the ruby tool> - remember it's just Ruby

Page 58: Opal chapter 4_a_new_hope

#5 EASY INTEGRATION WITH RUBYopal-railsopal-sprockets (already shown in modules)it's Ruby

Page 59: Opal chapter 4_a_new_hope

OPAL RAILShttps://github.com/opal/opal-rails

Page 60: Opal chapter 4_a_new_hope

#6 NEW IN BROWSER TOOLSopal-irbopal-inspector

Page 61: Opal chapter 4_a_new_hope

OPAL-IRBirb for opalhistoryreadline controlsmultiline edit (over all of history)send a link - live gist

Page 62: Opal chapter 4_a_new_hope

OPAL-INSPECTORinspired by amber.js in browser Smalltalk like code browserchange the paradigm of developmentdevelop in browser w/better toolspersistent live Opal objects is similar to Smalltalk image

Page 63: Opal chapter 4_a_new_hope

DEMOSopal-irbopal-inspectorSource Maps (head has broken it somewhat though)

Page 64: Opal chapter 4_a_new_hope

QUICK LOOK AT CODEonly 440 lines for opal-inspector current statevery short, small classesdidn't need a framework

Page 65: Opal chapter 4_a_new_hope

#7 A NEW FUTURE (HOPE)in browser dev, goodness from Smalltalk, Ruby and LispMachinesmeteor.js like same code on both sides

blurring front and back1 language…

Page 66: Opal chapter 4_a_new_hope

THERE CAN ONLY BE ONE

May that language be Ruby/Opal

Page 67: Opal chapter 4_a_new_hope

CALL TO ARMSthings are goodthey can be betterneed your help

Page 68: Opal chapter 4_a_new_hope

HELPtry it outtalk, google group, ircdocumentcontribute, it's just Rubyhave fun

Page 69: Opal chapter 4_a_new_hope

KISS JAVASCRIPT GOODBYE

Page 70: Opal chapter 4_a_new_hope

Created by fkchang.