Your SlideShare is downloading. ×
0
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Metaprogramming in Ruby
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Metaprogramming in Ruby

792

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
792
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
9
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Metaprogramming in Ruby ( II )Thinking in Lisp in Ruby in Lisp in …    http://jon.is.emotionull.com
  • 2. Creating a language  Parsers from scratch  Bison/yacc/lex   Metaprogramming FTW!   
  • 3. Bow to the masters  Lisp  Scheme  Forth  Smalltalk    
  • 4. Thinking again the problem  Code as data  Self modifying code  Dynamic adding/removing classes/functions  Describe the problem, dont solve it!   
  • 5. Metaprogramming in the wild  Web frameworks (Ruby On Rails)  A.I  DSL  Configuration files  ...   
  • 6. But, hooooow???  Function pointers (C,C++)  Open classes (Ruby)  Metaclasses (Python)  Lists (Lisp/Scheme/Clojure)   
  • 7. Tools of the trade for Ruby  Operators Overriding  OpenClasses  method_missing  Blocks and eval  Lambda   
  • 8. Speed penalty – Not always  Premature optimization  Fast and smart VM (JVM)  Bottleneck is somewhere else (DB)  You are not smart enough. Deal with it!   
  • 9. Cuby  Implemented in ~ 10 minutes  Looks like C  Feels like C  FULLY extensible  Trivial to add new libraries  You can use available Ruby libs  VM ~ 25 lines!   
  • 10. C in Ruby  Example // this is a test (example.cb) include ”stdio” main {     printf ”Hello Mr. %s !”, ”Jon” }        
  • 11. C in Ruby : Functions  Example include ”stdio” plea_for_merci_to name {   shout ”Please dont kill me” + name + ”!” } main {     plea_for_merci_to ”Jon” }        
  • 12. Real usage Prediction Modelling   
  • 13. Prediction Modelling  Lots of data (sometimes more than 60GB)  Long live C, Fortran, Lisp  Do you know OpenMP? If not, find another job  Speed, speed, speed   
  • 14. Predictions in Ruby?  RubyVM is not very robust (think BIG > 10GB)  Ruby is slow  Ruby threading is difficult and bad  Ruby does not SCALE!   
  • 15. You are right! Thanks for watching!   
  • 16. But ruby is slooooow  1.9 is waaay better than 1.8  Jruby is the King of the Hill   The bottleneck is not really here (hint: DB)   
  • 17. But ruby cannot scale!  Threading in RubyVM is bad  Fibers are way better   I love Jruby     
  • 18. Learn from the best: OpenMP  Standard for parallel processing  Easy to use  Very mature library   
  • 19. OpenMP example  Example #pragma omp parallel for  for (i = 0; i < arraySize; i++){         ....       y[i] = sin( exp( cos( ­ exp( sin(x[i]) ) ) ) );      ....    }   
  • 20. Can we do this in Ruby?  Example for j in 1..30     puts "Hello from iteration " + j.to_s       for i in 0..700000         c += a[i] * b[­i]       end       puts "I have just finished!"  end    
  • 21. In Cuby we trust  Example for j in 1..30     puts "Hello from iteration " + j.to_s       parallel {       for i in 0..700000         c += a[i] * b[­i]       end       puts "I have just finished!"       }     end 
  • 22.   Thank for watching! Questions? Cuby available at:  http://github.com/jonromero/Cuby http://jon.is.emotionull.com jon@emotionull.com   

×