The  Ruby Programming Language Or, Why are you wasting brain power?
Agneda <ul><li>The Principles of Languages </li></ul><ul><li>So What’s Ruby? </li></ul><ul><li>The Principles of Ruby </li...
The Principles of Languages <ul><li>Cogito ergo sum – Pascal. </li></ul><ul><li>We think, therefore we are. </li></ul><ul>...
<ul><li>Theorem #1 Languages therefore influence human thought </li></ul><ul><ul><li>Languages are not only tools to commu...
Programmers' Thought <ul><li>Written-down thoughts become programs.  </li></ul><ul><li>When a good programmer thinks about...
<ul><li>Theorem #2 &quot;languages&quot; include programming languages. </li></ul><ul><ul><li>We express our programming n...
Purpose of Programming Languages <ul><li>Teach computers what to do. </li></ul><ul><li>Describe problem to solve. </li></u...
A programming language should be: <ul><li>A language that: </li></ul><ul><li>helps our thought </li></ul><ul><li>guides us...
Consider the Human Brain <ul><li>Human Brain is Limited </li></ul><ul><li>Men are good at </li></ul><ul><ul><li>making err...
Languages Must be Nice to Human <ul><li>To focus on Human to be productive </li></ul><ul><ul><li>At the price of machine p...
How do programmers become stressed? <ul><li>By repetitive tasks </li></ul><ul><ul><ul><li>How may times have you written  ...
 
 
 
 
 
Designing a  useable  language <ul><li>How to make better programming experience? By providing good usability: </li></ul><...
Which leads us to… <ul><li>Is there such a wonder language that provides all this? </li></ul><ul><li>Long answer : Try all...
What’s Ruby? <ul><li>Free Object-Oriented Scripting Language. </li></ul><ul><li>Ruby = [Smalltalk - Unfamiliar syntax]    ...
What’s Ruby? <ul><li>Free, as in &quot;Free Drink“. </li></ul><ul><ul><li>Developed as open source with a very open licens...
What’s Ruby? <ul><li>Ruby the Scripting Language: </li></ul><ul><li>Scripting is programmability </li></ul><ul><li>Generat...
What’s Ruby? <ul><li>Ruby is as strong in scripting as Perl. </li></ul><ul><ul><li>built-in regular expression (Perl5 comp...
What’s Ruby? <ul><li>Ruby's OOP Features </li></ul><ul><ul><li>Object Everything is an object </li></ul></ul><ul><ul><li>C...
What’s Ruby? <ul><li>Ruby's Advanced OOP Features </li></ul><ul><ul><li>No Multiple Inheritance, but Mix-ins Mix-in is as ...
The Principles of Ruby <ul><li>Focusing on the human </li></ul><ul><li>Dynamic Programming </li></ul><ul><li>Principle of ...
Focusing on the human <ul><li>Languages can be viewed as interface. </li></ul><ul><ul><li>Do you like to fight/play with a...
Fun and Easy Programming <ul><li>Less frustration makes programmer feel smart and productive. </li></ul><ul><li>Easy thing...
Examples: Easy on the Brain <ul><li>Method chaining: print array.uniq.sort.reverse </li></ul><ul><li>Method names can incl...
Examples: Easy on the Brain <ul><li>class MyClass </li></ul><ul><li>attr_reader  :name, :age </li></ul><ul><li>attr_access...
Examples: Blocks <ul><li>Most method calls can take a block </li></ul><ul><li>It's kind of callback </li></ul><ul><li>Used...
Dynamic Programming <ul><li>Duck Typing aka Dynamic typing. Based on signatures, not class inheritance. </li></ul><ul><li>...
Examples: Dynamic Programming <ul><li>require ‘singleton’  </li></ul><ul><li>Class MyClass </li></ul><ul><li>include Singl...
Examples: Dynamic Programming <ul><li>Class scope reopening: </li></ul><ul><li>class String # that’s the systems’ String! ...
Examples: Dynamic Programming <ul><li>Object singleton class </li></ul><ul><li>ary = [1,2,3]  # an object </li></ul><ul><l...
The Principle of Least Surprise <ul><li>The supreme design goal of Ruby. Individual &quot;surprise&quot; differs person to...
Examples: POLS <ul><li>What class is an object? o.class </li></ul><ul><li>Is it Array#size or Array#length? same method – ...
Principle of Succinctness <ul><li>We're frustrated when  </li></ul><ul><ul><li>We feel we’re wasting time. </li></ul></ul>...
Principle of Succinctness <ul><li>Also known as “Principle of Least Effort” </li></ul><ul><li>You write less code, you see...
Lightweight Language <ul><li>Lightweight languages are languages that consume less Brain Power. Imagine something like Lea...
Choosing Good Names <ul><li>“ Name&quot; is Power </li></ul><ul><li>If you know a true name of a thing, you have control o...
Embedding Hidden Messages <ul><li>This is how languages can influence programmers. There's more than one way to do it, but...
Examples: Hidden Messages <ul><li>All member variables (and properties ) of  objects are private. </li></ul><ul><li>The  a...
So…? <ul><li>Should I or Shouldn’t I use Ruby? </li></ul>
Why Ruby? <ul><li>Because it's productive. Ruby programs tend to be shorter yet readable. </li></ul><ul><li>Because it's t...
Why Ruby? <ul><li>Because it's fast enough. Fairly fast for an interpreter. Replace bottleneck by C extension. </li></ul><...
Why Ruby? <ul><li>Because it's fun! </li></ul><ul><li>Programming should be a fun and creative experience. </li></ul>
More examples: Sockets <ul><li>Basic networking: </li></ul><ul><li>require 'socket‘ </li></ul><ul><li>print TCPSocket.open...
More examples: Database <ul><li>PStore: the simplest OO database:  </li></ul><ul><li>db = PStore.new(&quot;/tmp/foo&quot;)...
Why Ruby sucks * <ul><li>Not quite as mature as perl/python </li></ul><ul><ul><li>In terms of available well-documented li...
The Future <ul><li>Ruby2 and Rite </li></ul><ul><li>Ruby2, the language </li></ul><ul><ul><li>Slightly Incompatible </li><...
Ruby Resources <ul><li>http://www.ruby-lang.org/ </li></ul><ul><li>http://www.rubycentral.com/ </li></ul><ul><li>http://ww...
Upcoming SlideShare
Loading in …5
×

The Ruby Programming Language: Or, Why are you wasting brain power?

18,080 views
17,848 views

Published on

From: http://matt.cdo.linux.org.ph/files/RubyLanguageTalk.ppt

Published in: Technology, Education
5 Comments
41 Likes
Statistics
Notes
  • @guest5bff54 shame you didnt actually read and absorb the information ... its about brain power consumed to achieve the same outcome ...
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Nice presentation.
    Just one note: 'Cogito ergo sum' was written by Rene Descartes, not by Pascal... ;-)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Impressive presentation of 'The Ruby Programming Language: Or, Why are you wasting brain power?'. You've shown your credibility on presentation with this slideshow. This one deserves thumbs up. I'm John, owner of www.freeringtones.ws/ . Hope to see more quality slides from you.

    Best wishes.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Excellent slideshow. I've taken some of the framework graphics as well as adapted to my startup
    Anisa
    http://financejedi.com http://healthjedi.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • yeah that's what i feel too
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
18,080
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
0
Comments
5
Likes
41
Embeds 0
No embeds

No notes for slide

The Ruby Programming Language: Or, Why are you wasting brain power?

  1. 1. The Ruby Programming Language Or, Why are you wasting brain power?
  2. 2. Agneda <ul><li>The Principles of Languages </li></ul><ul><li>So What’s Ruby? </li></ul><ul><li>The Principles of Ruby </li></ul><ul><li>Why Ruby </li></ul><ul><li>Why Ruby sucks </li></ul><ul><li>Resources </li></ul>
  3. 3. The Principles of Languages <ul><li>Cogito ergo sum – Pascal. </li></ul><ul><li>We think, therefore we are. </li></ul><ul><li>Thinking is a most important activity for programmers. </li></ul><ul><li>But how do we think? </li></ul><ul><ul><li>I think in words of specific language (probably different to yours) </li></ul></ul><ul><ul><li>I grasp the world by a language and express myself with it </li></ul></ul><ul><ul><li>Languages are not only tools to communicate, but also tools to think. </li></ul></ul><ul><li>But conversely, language influence thoughts </li></ul><ul><ul><li>When I use English, I am more logical and formal. </li></ul></ul><ul><ul><li>When I use Hebrew, I speak lot more, and tend to be more expressive </li></ul></ul>
  4. 4. <ul><li>Theorem #1 Languages therefore influence human thought </li></ul><ul><ul><li>Languages are not only tools to communicate, but also tools to think. </li></ul></ul><ul><ul><li>They influence human thought, possibly more than you think. </li></ul></ul><ul><li>But this is a talk about Ruby. Do programming languages influence human thoughts? </li></ul>
  5. 5. Programmers' Thought <ul><li>Written-down thoughts become programs. </li></ul><ul><li>When a good programmer thinks about programs, perhaps he thinks in a programming language, because natural languages are </li></ul><ul><ul><li>too ambiguous, </li></ul></ul><ul><ul><li>too verbose, </li></ul></ul><ul><ul><li>too indirect. </li></ul></ul><ul><li>Compare learning a new language to learning a new programming language (“how do I say that?”) </li></ul><ul><li>If programmers think in programming languages, they must influence thoughts as much as natural languages do. </li></ul>
  6. 6. <ul><li>Theorem #2 &quot;languages&quot; include programming languages. </li></ul><ul><ul><li>We express our programming needs in them and they in turn affect the way we think and express thoughts. </li></ul></ul><ul><li>So… </li></ul><ul><ul><li>What is the purpose of programming languages? </li></ul></ul><ul><ul><li>Do programming languages differ in productivity? </li></ul></ul><ul><ul><li>What makes programming languages more productive? </li></ul></ul>
  7. 7. Purpose of Programming Languages <ul><li>Teach computers what to do. </li></ul><ul><li>Describe problem to solve. </li></ul><ul><li>Most importantly, express programmers thought in a form of program. </li></ul><ul><li>But often forgotten: Man is not a Machine </li></ul><ul><ul><li>If you are a machine, there's no need for programming languages. You can talk to the machine directly. </li></ul></ul>
  8. 8. A programming language should be: <ul><li>A language that: </li></ul><ul><li>helps our thought </li></ul><ul><li>guides us to be better programmers </li></ul><ul><li>makes us to enjoy programming </li></ul><ul><li>but does not brainwash us ;-) </li></ul><ul><ul><li>We just want to be &quot;influenced&quot;* </li></ul></ul><ul><li>* Read “Babel-17” by Samuel R. Delaney. </li></ul>
  9. 9. Consider the Human Brain <ul><li>Human Brain is Limited </li></ul><ul><li>Men are good at </li></ul><ul><ul><li>making errors </li></ul></ul><ul><ul><li>Creation </li></ul></ul><ul><ul><li>Imagination </li></ul></ul><ul><li>Men are bad at </li></ul><ul><ul><li>making copies </li></ul></ul><ul><ul><li>routine works </li></ul></ul><ul><ul><li>fast calculation </li></ul></ul>
  10. 10. Languages Must be Nice to Human <ul><li>To focus on Human to be productive </li></ul><ul><ul><li>At the price of machine power </li></ul></ul><ul><li>Reduce Programmers' Stress </li></ul><ul><ul><li>Stress is the enemy of Programmers </li></ul></ul><ul><ul><li>Stress reduces productivity </li></ul></ul>
  11. 11. How do programmers become stressed? <ul><li>By repetitive tasks </li></ul><ul><ul><ul><li>How may times have you written for (int i=o; i < max; ++i) … ? </li></ul></ul></ul><ul><li>By unnecessarily complex tasks </li></ul><ul><ul><ul><li>C++ templates. ‘nough said. </li></ul></ul></ul><ul><li>By resolving problems that are not within the application domain </li></ul><ul><ul><ul><li>Shutting up the compiler, build scripts </li></ul></ul></ul><ul><li>i.e. By expending brain power on unnecessary things, that do not solve your main objective. </li></ul>
  12. 17. Designing a useable language <ul><li>How to make better programming experience? By providing good usability: </li></ul><ul><ul><li>Learnability </li></ul></ul><ul><ul><ul><li>Useability for beginners, “Common sense” </li></ul></ul></ul><ul><ul><li>Efficiency </li></ul></ul><ul><ul><ul><li>Performance vs. Programming Efficiency </li></ul></ul></ul><ul><ul><ul><li>Users are not beginners forever </li></ul></ul></ul><ul><ul><li>Memorability </li></ul></ul><ul><ul><ul><li>Re-establishing proficiency with old code </li></ul></ul></ul><ul><ul><li>Errors </li></ul></ul><ul><ul><ul><li>Errors are the source of knowledge </li></ul></ul></ul><ul><ul><ul><li>Creativity is hindered by arbitrary restrictions </li></ul></ul></ul><ul><ul><li>Satisfaction </li></ul></ul><ul><ul><ul><li>We program for money, but want to have fun as well </li></ul></ul></ul>
  13. 18. Which leads us to… <ul><li>Is there such a wonder language that provides all this? </li></ul><ul><li>Long answer : Try all languages and see what fits your brain best. </li></ul><ul><li>Short answer : Duh, this is what this presentation is all about  </li></ul>
  14. 19. What’s Ruby? <ul><li>Free Object-Oriented Scripting Language. </li></ul><ul><li>Ruby = [Smalltalk - Unfamiliar syntax] + Perl's scripting power + Python's exception etc. + CLU's iterator + a lot more good things </li></ul>
  15. 20. What’s Ruby? <ul><li>Free, as in &quot;Free Drink“. </li></ul><ul><ul><li>Developed as open source with a very open license. </li></ul></ul><ul><ul><li>Freedom to learn from the source </li></ul></ul><ul><ul><li>Freedom to extend and modify </li></ul></ul>
  16. 21. What’s Ruby? <ul><li>Ruby the Scripting Language: </li></ul><ul><li>Scripting is programmability </li></ul><ul><li>Generations of Scripting Language </li></ul><ul><ul><li>0th Generation Sequence of interactive commands, UUCP chat, etc. </li></ul></ul><ul><ul><li>1st Generation Small, tool chest languages, shell, SED, AWK, etc. </li></ul></ul><ul><ul><li>2nd Generation One step toward &quot;usual&quot; programming language, Perl </li></ul></ul><ul><ul><li>3rd Generation Full featured programming language, Python, Ruby, Perl5 </li></ul></ul>
  17. 22. What’s Ruby? <ul><li>Ruby is as strong in scripting as Perl. </li></ul><ul><ul><li>built-in regular expression (Perl5 compatible). </li></ul></ul><ul><ul><li>almost all equivalent functionality of Perl. Except weird features and syntax. ;-) </li></ul></ul><ul><li>can access all system calls on UNIX and Windows via a standard library </li></ul><ul><ul><li>Ruby/DL (Dynamic Loading) </li></ul></ul><ul><ul><li>Older (explicit) libraries: syscall and Win32API </li></ul></ul><ul><li>Useful for scripting, but not limited to it. </li></ul>
  18. 23. What’s Ruby? <ul><li>Ruby's OOP Features </li></ul><ul><ul><li>Object Everything is an object </li></ul></ul><ul><ul><li>Class Every class is an object </li></ul></ul><ul><ul><li>Methods Every procedure is a method; first-class/lambda </li></ul></ul>
  19. 24. What’s Ruby? <ul><li>Ruby's Advanced OOP Features </li></ul><ul><ul><li>No Multiple Inheritance, but Mix-ins Mix-in is as strong as multiple inheritance, only simpler. </li></ul></ul><ul><ul><li>Singleton Properties belong to specific object. </li></ul></ul><ul><ul><li>Reflection </li></ul></ul><ul><ul><li>Operation over meta information. Highly dynamic. </li></ul></ul>
  20. 25. The Principles of Ruby <ul><li>Focusing on the human </li></ul><ul><li>Dynamic Programming </li></ul><ul><li>Principle of Least Surprise </li></ul><ul><li>Principle of Succinctness </li></ul><ul><li>Lightweight Language </li></ul><ul><li>Choosing good names </li></ul><ul><li>Embedding hidden messages </li></ul>
  21. 26. Focusing on the human <ul><li>Languages can be viewed as interface. </li></ul><ul><ul><li>Do you like to fight/play with a programming language? </li></ul></ul><ul><li>Ruby lets you focus on problems. </li></ul><ul><li>Ruby lets you stay high level of abstraction. </li></ul><ul><li>Ruby lets you make less errors by: </li></ul><ul><ul><li>Garbage Collection </li></ul></ul><ul><ul><li>Extensive Class Libraries </li></ul></ul><ul><ul><li>Arbitrary Precision Integer </li></ul></ul><ul><ul><li>Syntax is fairly close to be “runnable peudocode” </li></ul></ul><ul><li>When did you feel fun in programming last time? </li></ul>
  22. 27. Fun and Easy Programming <ul><li>Less frustration makes programmer feel smart and productive. </li></ul><ul><li>Easy things should be easy, hard things should be possible. (Perl slogan, but we do believe it too). </li></ul><ul><li>Programs should not go obfuscated without programmers' consent. </li></ul><ul><ul><li>No need to forbid obfuscation (There’s more than one way to do it) </li></ul></ul><ul><ul><li>No need to encourage obfuscation (But some ways are better than others) </li></ul></ul>
  23. 28. Examples: Easy on the Brain <ul><li>Method chaining: print array.uniq.sort.reverse </li></ul><ul><li>Method names can include ! and ? ary.sort! #=> sorts in place </li></ul><ul><li>Easy syntax: exit unless mystring.include? &quot;aura&quot; </li></ul><ul><li>Iterators vs. loops: files.each { |file| process(file) } </li></ul><ul><li>Case usage: </li></ul><ul><ul><li>Class names begin with a Capital letter </li></ul></ul><ul><ul><li>Constants are ALL_CAPS </li></ul></ul><ul><ul><li>Everything else is either a method call or a local variable </li></ul></ul>
  24. 29. Examples: Easy on the Brain <ul><li>class MyClass </li></ul><ul><li>attr_reader :name, :age </li></ul><ul><li>attr_accessor :address </li></ul><ul><li>alias to_s :name </li></ul><ul><li>end </li></ul><ul><li>Person = Struct.new(‘person’, </li></ul><ul><li> :name, :age, :address) </li></ul><ul><li>Person.class #=> Class </li></ul><ul><li>rec = Person.new #=> rec.class== Person </li></ul>
  25. 30. Examples: Blocks <ul><li>Most method calls can take a block </li></ul><ul><li>It's kind of callback </li></ul><ul><li>Used for Iteration, Hook, Procedure abstraction, etc. </li></ul><ul><li>array.each {|a| print a} </li></ul><ul><li>File.open(filename) {|f| f.readlines.grep(/…/) } </li></ul><ul><li>ary.map {|x| f(x) }.reject {|x| x<10} .inject {|sum,x| sum+=x if x%3 == 0} </li></ul>
  26. 31. Dynamic Programming <ul><li>Duck Typing aka Dynamic typing. Based on signatures, not class inheritance. </li></ul><ul><li>Dynamic Dispatch key concept of OOP </li></ul><ul><li>Dynamic Behavior reflection, scope reopening, eval </li></ul>
  27. 32. Examples: Dynamic Programming <ul><li>require ‘singleton’ </li></ul><ul><li>Class MyClass </li></ul><ul><li>include Singleton </li></ul><ul><li>end </li></ul><ul><li>o = MyClass.instance # ‘new’ has been undefined </li></ul><ul><li>Class MyDataClass </li></ul><ul><li>def <=> (other) # returns -1, 0 or 1 </li></ul><ul><li> self.to_s <=> other.to_s </li></ul><ul><li>end </li></ul><ul><li>include Comperable </li></ul><ul><li>end </li></ul>
  28. 33. Examples: Dynamic Programming <ul><li>Class scope reopening: </li></ul><ul><li>class String # that’s the systems’ String! </li></ul><ul><li>def firstNonMatch(str, idx=0) </li></ul><ul><li>i = idx </li></ul><ul><li>i += 1 while self[i] == str[i] </li></ul><ul><li> return i </li></ul><ul><li>end </li></ul><ul><li> alias trim strip </li></ul><ul><li>alias trim! strip! </li></ul><ul><li>end </li></ul>
  29. 34. Examples: Dynamic Programming <ul><li>Object singleton class </li></ul><ul><li>ary = [1,2,3] # an object </li></ul><ul><li>class << ary # it’s singleton class </li></ul><ul><li>def [] (idx) # redefined </li></ul><ul><li>puts “DEBUG: accessing #{idx}” </li></ul><ul><li>super </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
  30. 35. The Principle of Least Surprise <ul><li>The supreme design goal of Ruby. Individual &quot;surprise&quot; differs person to person, but in general there are good surprises and bad surprises. “least surprise&quot; means &quot;least bad surprise&quot; </li></ul><ul><li>POLS makes the language transparent </li></ul><ul><li>POLS makes programmers happy. </li></ul><ul><li>Caveat: Surprise fundamentally means Matz’s own surprise. </li></ul>
  31. 36. Examples: POLS <ul><li>What class is an object? o.class </li></ul><ul><li>Is it Array#size or Array#length? same method – they’re aliased </li></ul><ul><li>What are the differences between arrays? diff = ary1 – ary2 union = ary1 + ary2 </li></ul><ul><li>How do I call some well known C methods? Time.now.strftime(&quot;%Y-%b-%d&quot;) </li></ul>
  32. 37. Principle of Succinctness <ul><li>We're frustrated when </li></ul><ul><ul><li>We feel we’re wasting time. </li></ul></ul><ul><ul><li>We can't focus on problem itself. </li></ul></ul><ul><ul><li>We are interrupted. </li></ul></ul><ul><li>TIME is an important factor. </li></ul><ul><li>We can approximate our stress by the time we spent. </li></ul><ul><ul><li>The quicker we program, the more we program. </li></ul></ul><ul><ul><li>The faster we finish our job, the better programmer we can be. Succinctness is Power </li></ul></ul><ul><ul><li>Place your burden to machine's shoulders </li></ul></ul>
  33. 38. Principle of Succinctness <ul><li>Also known as “Principle of Least Effort” </li></ul><ul><li>You write less code, you see less bugs </li></ul><ul><li>You see less bugs, you can consider yourself smarter. </li></ul><ul><li>You can be 10 times (or even 1000 times) more productive </li></ul><ul><li>According to Fred P. Brooks: “Programmers generate about same amount of code per day regardless of the language” </li></ul>
  34. 39. Lightweight Language <ul><li>Lightweight languages are languages that consume less Brain Power. Imagine something like Learning Curve. </li></ul><ul><li>How do we measure the amount of consumed &quot;brain power&quot; in programming? </li></ul><ul><ul><li>Brain Power is spent when I make up the logic to solve the problem.  This is OK. It's a purpose of programming </li></ul></ul><ul><ul><li>Remember the syntax of the language </li></ul></ul><ul><ul><li>Look for reference </li></ul></ul><ul><ul><li>Try to locate bugs </li></ul></ul><ul><ul><li>Try to shut up compiler. Sometimes we have to modify programs for compiler's sake </li></ul></ul>
  35. 40. Choosing Good Names <ul><li>“ Name&quot; is Power </li></ul><ul><li>If you know a true name of a thing, you have control over it. </li></ul><ul><li>If you give a good name for a concept, 80% of the design is done already. </li></ul><ul><li>A good name keeps motivation. </li></ul><ul><li>A good name encourages us working with it. </li></ul>
  36. 41. Embedding Hidden Messages <ul><li>This is how languages can influence programmers. There's more than one way to do it, but the language can encourage some by making them comfortable than others. </li></ul><ul><li>Example: Bang Methods Some &quot;dangerous&quot; methods have &quot;!&quot; in their names. They might be faster, but you have to care about side effects. &quot;!&quot; reminds you of their side effect. You can avoid ugly &quot;!&quot; by using safer version. </li></ul>
  37. 42. Examples: Hidden Messages <ul><li>All member variables (and properties ) of objects are private. </li></ul><ul><li>The attr family of methods are used to specify attributes by create accessor methods: </li></ul><ul><ul><li>attr_accessor :foo is equal to: </li></ul></ul><ul><ul><li>def foo; @foo; end def foo= (val); @foo=val; end </li></ul></ul><ul><li>What if the developer needs to access the “private parts” of the object? There are methods like: </li></ul><ul><ul><li>instance_variable_get / instance_variable_set </li></ul></ul><ul><ul><li>instance_eval / module_eval etc. </li></ul></ul><ul><li>All these methods have long and explicit (ugly?) names. You can still do it, but by using them you are made aware of the implications. </li></ul>
  38. 43. So…? <ul><li>Should I or Shouldn’t I use Ruby? </li></ul>
  39. 44. Why Ruby? <ul><li>Because it's productive. Ruby programs tend to be shorter yet readable. </li></ul><ul><li>Because it's transparent. You may want to focus on programming itself. </li></ul><ul><li>Because it's free. Not only free of charge, but freedom to use/modify/copy. Freedom to learn from its source </li></ul><ul><li>Because of the Ruby community. Helpful, without flame wars  </li></ul>
  40. 45. Why Ruby? <ul><li>Because it's fast enough. Fairly fast for an interpreter. Replace bottleneck by C extension. </li></ul><ul><li>Because it's portable. Portable among many platforms thanks to open source. Including GUI toolkits. </li></ul><ul><li>Because it has what you need. Enough libraries to cover maths, DBs, distributed programming, os administration, networking, serializations, graphics, web-works... </li></ul>
  41. 46. Why Ruby? <ul><li>Because it's fun! </li></ul><ul><li>Programming should be a fun and creative experience. </li></ul>
  42. 47. More examples: Sockets <ul><li>Basic networking: </li></ul><ul><li>require 'socket‘ </li></ul><ul><li>print TCPSocket.open(&quot;localhost&quot;, &quot;daytime&quot;).read </li></ul><ul><li>Web networking: </li></ul><ul><li>Net::HTTP::Proxy(addr, port).start(site) do |http| </li></ul><ul><li>response = http.get(uri) </li></ul><ul><li>File.open(filename, &quot;w+&quot;) { |file| </li></ul><ul><li>file.puts response.body </li></ul><ul><li>} </li></ul><ul><li>end </li></ul>
  43. 48. More examples: Database <ul><li>PStore: the simplest OO database: </li></ul><ul><li>db = PStore.new(&quot;/tmp/foo&quot;) # open database </li></ul><ul><li>db.transaction do # begin transaction </li></ul><ul><li>p db.roots # display roots </li></ul><ul><li>ary = db[&quot;root&quot;] = [1,2,3,4] # add to root </li></ul><ul><li>ary[0] = [1,1.5] # modify object </li></ul><ul><li>end # end transaction </li></ul><ul><li>We also have PostgreSQL, MySQL, Interbase interfaces, plus Ruby/DBI database abstraction layer </li></ul>
  44. 49. Why Ruby sucks * <ul><li>Not quite as mature as perl/python </li></ul><ul><ul><li>In terms of available well-documented libraries </li></ul></ul><ul><ul><li>On the plus side: more is available “out of the box” </li></ul></ul><ul><li>No CPAN and the like </li></ul><ul><ul><li>but ruby gems is maturing rapidly </li></ul></ul><ul><li>“ Fast enough” but not really fast. Syntax tree interpreter often slower than VM. This is planned for Ruby 2.0. </li></ul><ul><li>Unicode support. Currently only through UTF-8. </li></ul><ul><li>Green threads only Native threads planned for Ruby2. </li></ul><ul><li>* Presentation given by Matz on the future of Ruby. </li></ul>
  45. 50. The Future <ul><li>Ruby2 and Rite </li></ul><ul><li>Ruby2, the language </li></ul><ul><ul><li>Slightly Incompatible </li></ul></ul><ul><ul><li>Not Just Addition </li></ul></ul><ul><ul><li>Better Syntax </li></ul></ul><ul><ul><ul><li>Language syntax is taking form as ruby 1.9 </li></ul></ul></ul><ul><li>Rite, the interpreter </li></ul><ul><ul><li>Bytecode based virtual machine </li></ul></ul><ul><ul><li>Better Performance </li></ul></ul><ul><ul><li>Allow Native Threads and better Embedding </li></ul></ul><ul><ul><ul><li>Still vaporware </li></ul></ul></ul>
  46. 51. Ruby Resources <ul><li>http://www.ruby-lang.org/ </li></ul><ul><li>http://www.rubycentral.com/ </li></ul><ul><li>http://www.rubygarden.org/ </li></ul><ul><li>&quot; Programming Ruby “ - The Pragmatic Programmer's Guide, Addison Wesley, October 2000 Available online at: http://www.rubycentral.com/book </li></ul><ul><li>http://poignantguide.net/ruby - Why’s (poignant) Guide to Ruby (with cartoon foxes) </li></ul><ul><li>The scientific proof to why Ruby the is most loveable language  http:// bluebones.net/news/default.asp?action = view_story&story_id =81 </li></ul>

×