Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
A quick introduction to


                           MacRuby          Objective-C, Cocoa, LLVM, Grand Central
            ...
Olivier Gutknecht
olg@no-distance.net
twitter : olg




                                         MacRuby


  iCal, iSync, ...
Breaking News !

MacRuby developer
attacked by raptors
Text
 Text
Text
 Text
MacRuby
Mac OS X Stack

  Applications


  Application
  Frameworks
                    Cocoa, WebKit, ...


Core Technologies   C...
Ruby on OS X
2002   Mac OS X 10.2      Ruby 1.6.7

2005   Mac OS X 10.4      Ruby 1.8.2

2007   Mac OS X 10.5      Ruby 1....
Ruby on OS X
• Ruby, just on another unix platform
• With some small improvements...
  e.g. mongrel_rails_persists on OS X...
Family business

         SmallTalk


Objective-C     Ruby
A “true” OS X App in
       Ruby ?




    Sure. Check out Gitnub
RubyCocoa
• A ruby-objc bridge
  (FUJIMOTO Hisakuni, 2001)
• Ruby 1.8
• Green threads, no reentrance
• Two runtimes, two G...
require 'osx/cocoa'; include OSX
app = NSApplication.sharedApplication
win = NSWindow.alloc.initWithContentRect_styleMask_...
Easy.
(when you’re proficient in Objective-C, Cocoa, Ruby and the bridge - here be dragons)
MacRuby
MacRuby

• One GC to release them all
MacRuby

• One GC to release them all
• One runtime to bind them
MacRuby

• One GC to release them all
• One runtime to bind them
• In the land of Cocoa where Obj-C lie
MacRuby
      Laurent Sansonetti
           (Apple)
          Vincent Isambart
            Kich Kilmer
             Eloy D...
Modest goals


• The best platform for Ruby developers
• A great platform for Cocoa developers
Bridge, what bridge ?
$ macirb
>> s = "osdc"
=> "osdc"

>> s.class
=> NSMutableString

>> s.class.ancestors
=> [NSMutableS...
Bridge, what bridge ?

• A Ruby class is an Objective-C class
• A Ruby method is an Objective-C method
• A Ruby instance i...
Syntax
                                             Objective-C
Person *person = [Person new];

[person name];
[person set...
HotCocoa
require ‘hotcocoa’
include HotCocoa

application do
  win = window :title => ‘hello OSDC’, :frame => [0, 0, 200, ...
Ruby 1.9


Parser     Runtime   Built-in classes

YARV        GC           Stdlib
MacRuby

               Runtime
  Parser                      Stdlib

LLVM/Roxor     libobjc   Built-in Classes
AOT    JIT...
MacRuby 0.4 - 04/09

•   XCode integration

•   Embedding / Runtime
    Control

•   HotCocoa

•   Threaded GC
MacRuby 0.5 - xx/09

•   YARV ? LLVM !

•   RubySpec

•   AOT

•   GrandCentral

•   ...
Why LLVM ?
Coolest Logo Ever
Everybody loves
 microbenchmarks
(lies, damn lies and benchmarks)



                            From a bench by Patrick T...
C

static int fib(int n)
{
  if (n < 3) {
    return 1;
  }
  else {
    return fib(n - 1) + fib(n - 2);
  }
}
Objective-C
@implementation Fib
- (int)fib:(int)n
{
  if (n < 3) {
     return 1;
  }
  else {
     return [self fib:n - 1...
4




                     3
execution time (s)




                     2




                     1




                ...
Ruby

def fib(n)
  if n < 3
    1
  else
    fib(n-1) + fib(n-2)
  end
end

p fib(ARGV.join("").to_i)
4




                     3
execution time (s)




                     2




                     1




                ...
MRI Ruby 1.8
$ ruby fibo.rb 40
102334155


                               MacRuby
$ macruby fibo.rb 40
102334155


         ...
Grand Central
# A GCD-based implementation of the sleeping barber problem:
#   http://en.wikipedia.org/wiki/Sleeping_barbe...
Tools Galore

    ?
Why MacRuby ?

• Ruby for “mac-like” desktop applications
• A wonderful experimentation playground
• ... Interesting persp...
Q&A

• Ruby 1.9 compatibility
 • Right now, ≈ 80% on rubyspec
• Other platforms, portability
 • No closed-source dependanc...
Thanks!
MacRuby, an introduction
Upcoming SlideShare
Loading in …5
×

MacRuby, an introduction

6,103 views

Published on

Translation of a presentation about MacRuby I made at OSDC.fr 2009

Published in: Technology, Education
  • She hasn't even mentioned my snoring!! When I read the story on your website I understood EXACTLY what you were talking about. I have been single for years because my snoring is so loud. As soon as I get to the stage where a girl stays over, I never hear from them again. Your program has taken my snoring down to a low hum. I now have a girlfriend and she hasn't even mentioned my snoring!! ■■■ http://ishbv.com/snoringno/pdf
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Download or read that Ebooks here ... ......................................................................................................................... DOWNLOAD FULL PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

MacRuby, an introduction

  1. 1. A quick introduction to MacRuby Objective-C, Cocoa, LLVM, Grand Central and other musings Olivier Gutknecht - OSDC.fr - Oct. 3 2009
  2. 2. Olivier Gutknecht olg@no-distance.net twitter : olg MacRuby iCal, iSync, [...] co-founder Active lurker Server Software
  3. 3. Breaking News ! MacRuby developer attacked by raptors
  4. 4. Text Text
  5. 5. Text Text
  6. 6. MacRuby
  7. 7. Mac OS X Stack Applications Application Frameworks Cocoa, WebKit, ... Core Technologies CoreGraphics, CoreFoundation, ... Darwin Kernel, userland, libdispatch, ...
  8. 8. Ruby on OS X 2002 Mac OS X 10.2 Ruby 1.6.7 2005 Mac OS X 10.4 Ruby 1.8.2 2007 Mac OS X 10.5 Ruby 1.8.6 RubyCocoa, gems, Rails 2009 Mac OS X 10.6 Ruby 1.8.7 RubyCocoa, gems, Rails 20xx ? Sky is the limit
  9. 9. Ruby on OS X • Ruby, just on another unix platform • With some small improvements... e.g. mongrel_rails_persists on OS X Server launchd / bonjour integration • What about Cocoa ?
  10. 10. Family business SmallTalk Objective-C Ruby
  11. 11. A “true” OS X App in Ruby ? Sure. Check out Gitnub
  12. 12. RubyCocoa • A ruby-objc bridge (FUJIMOTO Hisakuni, 2001) • Ruby 1.8 • Green threads, no reentrance • Two runtimes, two GC • ... interesting syntax • Ouch
  13. 13. require 'osx/cocoa'; include OSX app = NSApplication.sharedApplication win = NSWindow.alloc.initWithContentRect_styleMask_backing_defer( [0, 0, 200, 60], NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, NSBackingStoreBuffered, false) win.title = 'Hello World' button = NSButton.alloc.initWithFrame(NSZeroRect) win.contentView.addSubview(button) button.bezelStyle = NSRoundedBezelStyle button.title = 'Hello!' button.sizeToFit button.frameOrigin = NSMakePoint((win.contentView.frameSize.width/ 2.0)-(button.frameSize.width/2.0), (win.contentView.frameSize.height/ 2.0)-(button.frameSize.height/2.0)) button_controller = Object.new def button_controller.sayHello(sender) puts "Hello OSDC!" end button.target = button_controller button.action = 'sayHello:' win.display win.orderFrontRegardless app.run
  14. 14. Easy. (when you’re proficient in Objective-C, Cocoa, Ruby and the bridge - here be dragons)
  15. 15. MacRuby
  16. 16. MacRuby • One GC to release them all
  17. 17. MacRuby • One GC to release them all • One runtime to bind them
  18. 18. MacRuby • One GC to release them all • One runtime to bind them • In the land of Cocoa where Obj-C lie
  19. 19. MacRuby Laurent Sansonetti (Apple) Vincent Isambart Kich Kilmer Eloy Duran Ben Stiglitz Matt Aimonetti ... http://www.macruby.org http://twitter.com/macruby
  20. 20. Modest goals • The best platform for Ruby developers • A great platform for Cocoa developers
  21. 21. Bridge, what bridge ? $ macirb >> s = "osdc" => "osdc" >> s.class => NSMutableString >> s.class.ancestors => [NSMutableString, NSString, Comparable, NSObject, Kernel] >> s.upcase => "OSDC" >> s.uppercaseString => "OSDC" >> s.respondsToSelector(:upcase) => 1 >> s.respond_to?(:upcase) => true
  22. 22. Bridge, what bridge ? • A Ruby class is an Objective-C class • A Ruby method is an Objective-C method • A Ruby instance is an Objective-C instance
  23. 23. Syntax Objective-C Person *person = [Person new]; [person name]; [person setName:name]; [person setFirstName:first lastName:last]; MacRuby person = Person.new person.name person.name = myName person.setFirstName(first, lastName:last)
  24. 24. HotCocoa require ‘hotcocoa’ include HotCocoa application do win = window :title => ‘hello OSDC’, :frame => [0, 0, 200, 60] b = button :title => ‘Hello!’, :layout => {:align => :center} win << b b.on_action { puts “Hello OSDC!” } end A thin layer by Rich Kilmer, providing a natural ruby experience when coding Cocoa apps
  25. 25. Ruby 1.9 Parser Runtime Built-in classes YARV GC Stdlib
  26. 26. MacRuby Runtime Parser Stdlib LLVM/Roxor libobjc Built-in Classes AOT JIT libauto CoreFoundation
  27. 27. MacRuby 0.4 - 04/09 • XCode integration • Embedding / Runtime Control • HotCocoa • Threaded GC
  28. 28. MacRuby 0.5 - xx/09 • YARV ? LLVM ! • RubySpec • AOT • GrandCentral • ...
  29. 29. Why LLVM ?
  30. 30. Coolest Logo Ever
  31. 31. Everybody loves microbenchmarks (lies, damn lies and benchmarks) From a bench by Patrick Thomson @ C4
  32. 32. C static int fib(int n) { if (n < 3) { return 1; } else { return fib(n - 1) + fib(n - 2); } }
  33. 33. Objective-C @implementation Fib - (int)fib:(int)n { if (n < 3) { return 1; } else { return [self fib:n - 1] + [self fib:n - 2]; } } @end
  34. 34. 4 3 execution time (s) 2 1 0 fib(40) C Objective-C
  35. 35. Ruby def fib(n) if n < 3 1 else fib(n-1) + fib(n-2) end end p fib(ARGV.join("").to_i)
  36. 36. 4 3 execution time (s) 2 1 0 fib(40) C MacRuby Objective-C
  37. 37. MRI Ruby 1.8 $ ruby fibo.rb 40 102334155 MacRuby $ macruby fibo.rb 40 102334155 MacRuby AOT $ macrubyc fibo.rb -o fibo $ ./fibo 40 102334155
  38. 38. Grand Central # A GCD-based implementation of the sleeping barber problem: # http://en.wikipedia.org/wiki/Sleeping_barber_problem # http://www.madebysofa.com/#blog/the_sleeping_barber waiting_chairs = Dispatch::Queue.new('com.apple.waiting_chairs') semaphore = Dispatch::Semaphore.new(3) index = -1 while true index += 1 success = semaphore.wait(Dispatch::TIME_NOW) if success != 0 puts "Customer turned away #{index}" next end waiting_chairs.dispatch do semaphore.signal puts "Shave and a haircut #{index}" end end
  39. 39. Tools Galore ?
  40. 40. Why MacRuby ? • Ruby for “mac-like” desktop applications • A wonderful experimentation playground • ... Interesting perspectives
  41. 41. Q&A • Ruby 1.9 compatibility • Right now, ≈ 80% on rubyspec • Other platforms, portability • No closed-source dependancies, no definitive technical blocker • ... Any takers ?
  42. 42. Thanks!

×