Advertisement

MacRuby: What is it? and why should you care?

May. 13, 2011
Advertisement

More Related Content

Advertisement
Advertisement

MacRuby: What is it? and why should you care?

  1. MacRuby What is it? and why should you care? Presented by: Joshua Ballanco
  2. A bit about me... • Using Ruby since 2004 (didn’t discover Rails until 2006) • Worked for Apple 2006-2010 (Fifth Ave store & HQ in Cupertino) • Now at Patch (and just completed a migration to Ruby 1.9) • MacRuby Core Team member
  3. A bit about me... • Using Ruby since 2004 (didn’t discover Rails until 2006) • Worked for Apple 2006-2010 (Fifth Ave store & HQ in Cupertino) • Now at Patch (and just completed a migration to Ruby 1.9) • MacRuby Core Team member • As of yesterday: Dr. Joshua Ballanco, Ph.D.
  4. Overview • Practical MacRuby • How is MacRuby different? • Working with Cocoa • Compiled Ruby! • Make your millions on the App store • Nuts & Bolts • GC • Regular Expression Engine • Hash method syntax • LLVM & other Hacking • GCD
  5. What is MacRuby?
  6. What is MacRuby? • http://www.macruby.org • http://www.macruby.org/files/ • http://www.macruby.org/files/nightlies/ • Available from RVM (but not recommended) • Source now located at GitHub! https://github.com/MacRuby/MacRuby
  7. What is MacRuby? • Compiling MacRuby: • Need LLVM (see the README; brew install llvm) • rake ; sudo rake install • Bugs – https://www.macruby.org/trac/ report • MacRuby-devel mailing list • @macruby, #macruby
  8. No Really, What is MacRuby?
  9. No Really, What is MacRuby? A language with: • Dynamic typing • Objects everywhere • Method calls via sending messages • Automatic generation of accessors • Methods can be added to classes at runtime • Garbage Collection • Closures
  10. No Really, What is MacRuby? A language with: • Dynamic typing • Objects everywhere • Method calls via sending messages • Automatic generation of accessors • Methods can be added to classes at runtime • Garbage Collection • Closures ...called Objective-C
  11. Ruby Syntax Parser MRI’s parse.y Compiler RoxorCompiler <C++> VM (sans GVL) LLVM (with JIT) RoxorVM & RoxorCore <C++> Objective-C Runtime
  12. Integrating with Cocoa • Bridge Support (please download preview 3 from the “files” page) • Reads header files and generates XML descriptions of types and method signatures • MacRuby uses BS files to construct calls and access constants and types
  13. A Ruby You Can Compile • macrubyc • Advantages: • Faster startup, faster runtime (in most cases) • Don’t distribute the source! • Disadvantages: • ? • ...some bugs
  14. A Ruby You Can Compile • -c → Compile and assemble; good for multistage builds • -C → Compile, assemble, and link creating an *.rbo • Can also create stand-alone executables and entire “*.framework”s (experimental)
  15. I wanna be an App store billionaire... • Downloads contain Xcode templates (mostly work in Xcode 4) • Integration with Interface Builder • macruby_deploy • Includes BS files • Unpacks Gems • Compiles source
  16. I wanna be an App store billionaire...
  17. I wanna be an App store billionaire... QuickAlarm Briquette Timey Zero2Nine
  18. MacRuby Nuts & Bolts
  19. Garbage Collector: libauto • Yet another open source project from Apple • The GC for Obj-C • Based on write barriers • scanning, conservative, generational, multi- threaded garbage collector... • ...unfortunately...slow
  20. Garbage Collector: the Next Generation(?) • Ruby does A LOT of allocations • Nice to not have to stop the world, but... • Write barriers are slow • Maybe ref counting? • Maybe MRI’s collector isn’t so bad after all...
  21. RegExps: ICU • Oniguruma is not (real thread) thread safe • ICU is • thread safe • Unicode compatible • not as crazy feature-full as Oniguruma • There are some bugs...but honestly, stop doing that with RegExps!!!
  22. Hash method syntax • Ruby 1.9’s hash syntax with Symbol keys: a = { foo: 1, bar: 2, baz: “Hello, world” } • ...looks a bit like: [@”Hello, world” rangeOfString:@”Ello” options: NSCaseInsensitiveSearch] • Let’s go with that!
  23. Hash method syntax • MacRuby turns method calls with hash arguments into SEL • MacRuby turns method definitions with hash lists into SEL • MacRuby can call Objective-C • Objective-C can call MacRuby, but when possible you should use: [[MacRuby sharedRuntime] performRubySelector]
  24. LLVM, JIT, and Hacking • LLVM provides optimizations • LLVM provides JIT utilities (kinda slow) • MacRuby can emit LLVM... VM_DUMP_IR=1 macruby -e "def foo; puts 'hello'; end; foo" • Find other neat tricks in HACKING.rdoc
  25. GCD & The Future
  26. GCD • MacRuby can tap directly into GCD • Dispatch module: • Dispatch::Queue • Dispatch::Group • Dispatch::Source • Dispatch Gem too!
  27. GCD • Dispatch is a powerful tool for concurrent programming • Example: ControlTower • MacRuby Rack-based server • Uses GCD to handle requets • Accomplishes in 1 line what takes Thin/ EventMachine > 6000 lines of C++ & Ruby
  28. GCD
  29. GCD • Can we make GCD work in MRI? • JRuby thinks they can make it work... https://github.com/headius/jcd • GCD is Multithreaded Programming, Ruby Style
  30. Thank you! http://ofps.oreilly.com/titles/9781449380373/

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
Advertisement