The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Is Ruby Human-Understandable?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Michael Neumann

Posts: 66
Nickname: backflash
Registered: May, 2003

Michael Neumann is fallen in Love with Ruby
Is Ruby Human-Understandable? Posted: Aug 16, 2004 2:14 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Michael Neumann.
Original Post: Is Ruby Human-Understandable?
Feed Title: Mike's Weblog
Feed URL: http://www.ntecs.de/blog-old/index.rss?cat=ruby&count=7
Feed Description: Blogging about Ruby and other interesting stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Michael Neumann
Latest Posts From Mike's Weblog

Advertisement
Is Ruby human-understandable? Understandable by humans with absolutely no experience in computer programming? How can we as experienced programmers at all answer such a question? Well, we can't! The only way to determine whether a language is easily understood by novices is to actually ask them.

To find an answer to this question I performed some tests with my beloved girlfriend. She's an absolute novice in this area as she'd never seen any source code of a computer program before. I gave her a page of paper with examples written on it and told her to write down what would be the output for each example. Then I left the room to prevent any communication during the test.

The results were promising! She mastered 4 of 7 tests without my help. Tests two and seven were obvious after introducing := for assignment, and = for equality. And the failure of test 6 had more to do with the English word "select" than with Ruby (keep in mind that English is not our native tongue). Wow, she even implicitly used lazy evaluation ;-)

The Tests

Test 1

  print "hello world"

She passed this test easily.

Test 2

  result = (3*10) + 5
  print result

She pointed out a problem that I wasn't aware of. From her point of view, the output should be "(3*10) + 5" and not "35". I discussed this issue with her and found out that it would be easier for her to understand if the "=" would be a ":=". Once I changed the tests according to this problem, she was able to solve them.

Test 3

  5.times {
    print "hallo welt"
  }

No problems here!

Test 4

  5.downto(1) { |counter|
    print counter
  }

Again, no problems!

Test 5

  elements = ["Hydrogen", "Oxygen", "Helium", "Ferrite"]
  elements.each { |element|
    print element
  }

She even mastered this test without problems.

Test 6

  one_to_ten = [1,2,3,4,5,6,7,8,9,10]
  even = one_to_ten.select { |i| i.even? }

  print even

Once I told her that select translates to the German word auswählen (choose) she mastered this test easily.

Test 6b

Same as test 5, plus the following line:

  print elements.select { |element| element == 'Ferrite' }

I created this test after test 6 failed. She mastered this one easily and thereafter was able to solve test 6.

Test 7

  counter = 1

  loop {
    print counter
    counter = counter + 1
  }

This test raised the same issue as test 2: Assignment vs. Equality. Her result was "1 + 1 + 1 + ...", which is not all that wrong. Of course it's wrong in Ruby, but remember Haskell's lazy evaluation:

  {- create an infinite list of ones -}
  ones = 1 :: ones

She mastered the test after I introduced ":=" for assignment instead of "=".

Test 7b

  counter = 1

  loop {
    break if counter > 10
    print counter
    counter = counter + 1
  }

I created this one after she solved test 7 successfully. Of course it was a mere child's play for her ;-)

Discussing Loops

I took the opportunity and asked her about loops.

  loop {
    ...
  }

  loop {
    ...
    break if cond
    ...
  }

  while 1 {
    ...
  }

  while true {
    ...
  }

  while cond {
     ...
  }

  repeat
    ...
  until cond

She easily understood the loops that use the loop keyword, but not the others. That's exactly what I prefer for most of the loops I write in my programs. And IMO they are much more readable and less error prone than while or repeat until loops.

I remember a statement of a mathematics professor at University of Tuebingen who told us that the human mind is not good in understanding negation (the "not" operator from logics). And at least for my mind, he's correct. Whenever I can, I prefer positive logic over negative:

   # this one is easy to understand (for me)
   loop {
     break if cond
   }

   # tell me when this loop aborts!
   while not cond {
     ...
   }

And whenever I see something like "while 1", especially in so called very high level languages, I ask myself whether they got caught in C forever.

Finally, I asked her about for loops:

  for i in 1..10 do
    ...
  end

As she hasn't studied mathematics, she had problems understanding the for ... in notation. Luckily, Ruby supports customized loops like "1.upto(10)" which reads easily even for absolute beginners.

Read: Is Ruby Human-Understandable?

Topic: I'm willing to code Ruby... because of Rails Previous Topic   Next Topic Topic: Ruby on Rails with Panel 4 on RubyConf

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use