Things I am wondering... 
Author Message
 Things I am wondering...

Just some more random questions. These are some
things I have been wondering about, and I thought
I might ask them all at once.  :)

1. Why is Dir::foreach not named Dir::each?

2. Why are these control structures and not methods?
&& || ! and or not

3. Why are TrueClass and FalseClass separate classes?
In a way, I see the logic of it. But my instinct would
have been a single class called Boolean.

4. Why was the keyword "yield" chosen? Is this a legacy
from another language? It is not intuitive to me.

5. Like many other languages, Ruby does short-circuiting
of Boolean expressions. Other than efficiency, what is
the rationale for this? Was the other way (full
evaluation) ever considered?

Thanks for enlightening me...

Hal



Sat, 09 Nov 2002 03:00:00 GMT  
 Things I am wondering...

Quote:

>In message "[ruby-talk:02948] Things I am wondering..."

>|1. Why is Dir::foreach not named Dir::each?

>`each' is reserved for default enumeration.

What is "default enumeration"?

Quote:
>|3. Why are TrueClass and FalseClass separate classes?
>|In a way, I see the logic of it. But my instinct would
>|have been a single class called Boolean.

>I don't think true and false ever share the implementation, thus
>there's little reason to have common single boolean class. Having
>Boolean class as common ancestor of True and False may be helpful to
>classify boolean values.

I could see wanting to expand Boolean, and having True and False there would be nice.

I'm always having to say (though normally without "return" in a definition):

   return ((foo =~ /pat/) != nil)

Perfect for an expansion to class Boolean....

Quote:
>|5. Like many other languages, Ruby does short-circuiting
>|of Boolean expressions. Other than efficiency, what is
>the rationale for this? Was the other way (full
>evaluation) ever considered?

>hey are designed so because I was C tainted programmer. They are
>ffective too. I haven't considered other way; I dislike Pascal.

To flip-flop the question: what is the rationale for "and" "or" et al?  Isn't "&&" and "||" enough? :-)

Thanks for the hard and dedicated work you put in on Ruby!



Sat, 09 Nov 2002 03:00:00 GMT  
 Things I am wondering...
Hi,

In message "[ruby-talk:02948] Things I am wondering..."

|Just some more random questions. These are some
|things I have been wondering about, and I thought
|I might ask them all at once.  :)
|
|1. Why is Dir::foreach not named Dir::each?

`each' is reserved for default enumeration.

|2. Why are these control structures and not methods?
|&& || ! and or not

&&, ||, and, or are shurtcut operators, which cannot be accomplished
by methods.  !, not can be implemented by methods.  They are control
structure mostly for performance reason.

|3. Why are TrueClass and FalseClass separate classes?
|In a way, I see the logic of it. But my instinct would
|have been a single class called Boolean.

I don't think true and false ever share the implementation, thus
there's little reason to have common single boolean class.  Having
Boolean class as common ancestor of True and False may be helpful to
classify boolean values.

|4. Why was the keyword "yield" chosen? Is this a legacy
|from another language? It is not intuitive to me.

Yes, it's from CLU.

|5. Like many other languages, Ruby does short-circuiting
|of Boolean expressions. Other than efficiency, what is
|the rationale for this? Was the other way (full
|evaluation) ever considered?

They are designed so because I was C tainted programmer.  They are
effective too.  I haven't considered other way; I dislike Pascal.

                                                        matz.



Sun, 10 Nov 2002 03:00:00 GMT  
 Things I am wondering...
Hi,

In message "[ruby-talk:02954] Re: Things I am wondering..."

|>|1. Why is Dir::foreach not named Dir::each?
|>
|>`each' is reserved for default enumeration.
|
|What is "default enumeration"?

Well, the name 'each' is used by for statement and Enumerable module
to iterate over container's each items.  For example, simple for
statement

  for i in array
    ...
  end

is implemented by

  array.each do |i|
    ...
  end

So I wanted to reserve the name for the purpose.  The class Dir is not
a container (the instance of Dir is).

|I could see wanting to expand Boolean, and having True and False there would be nice.

Possible.  I'll add this to ToDo file.  But remember, the values true
and false are merely representative values for conditional value.  All
non-nil, non-false values are truth value in Ruby.  Introducing
Boolean class may be the cause of confusion.  I think more discussion
is needed before add it to Ruby.

|To flip-flop the question: what is the rationale for "and" "or" et al?
|Isn't "&&" and "||" enough? :-)

Functionaly enough.  They are mere aliases.  Lower precedence logical
keyword operators are inspired by Perl.

  unlink "a", "b", "c" or raise "error!"

Can be written as follows using || operator:

  unlink("a", "b", "c") || raise("error!")

                                                        matz.



Sun, 10 Nov 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. 2 or 3 things I wonder about: MF and Fujitsu Cobol

2. Am I seeing things?...

3. I am wondering what I am going to do with the following simulation error.

4. I am not deaf, but am I mute?

5. Just wondering

6. Wonders of IBM's REXX compiler

7. I was wondering...

8. VA's table --wondering how

9. BASIC's WONDER !!!!!!!!!!

10. I was wondering...

11. I was wondering...

12. Sharing violations -- wondering...

 

 
Powered by phpBB® Forum Software