Forum: Ruby Why do true and false have separate classes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0026dd77fd9ecc97b36e5b79cdbcf590?d=identicon&s=25 R. Kumar (sentinel)
on 2009-01-14 14:27
This has puzzled me a bit. I googled and came up with responses like --
in any case we use respond_to? for duck typing.

I am writing a program in which some classes behave differently
depending on the data in various columns. Typically, this means
displaying and editing of cells. So true and false are boolean and are
displayed and edited as checkboxes.

Having 2 separate classes really complicated things since i don't want
to define 2 separate renderers and editors for true and false.

Just wondered what the thought behind this was?
83ca41657a99b65d99889abe712ba5e2?d=identicon&s=25 Jason Roelofs (Guest)
on 2009-01-14 14:56
(Received via mailing list)
On Wed, Jan 14, 2009 at 8:26 AM, Ruby Rabbit <sentinel.2001@gmx.com>
wrote:
>
> Just wondered what the thought behind this was?
> --
> Posted via http://www.ruby-forum.com/.
>
>

It's only the core philosophy of Ruby: You have objects send messages
to those objects.
If there weren't a TrueClass and FalseClass, what else would true and
false be?

Jason
0026dd77fd9ecc97b36e5b79cdbcf590?d=identicon&s=25 R. Kumar (sentinel)
on 2009-01-14 15:08
Jason Roelofs wrote:
> On Wed, Jan 14, 2009 at 8:26 AM, Ruby Rabbit <sentinel.2001@gmx.com>
> wrote:
>>
>> Just wondered what the thought behind this was?
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>>
>
> It's only the core philosophy of Ruby: You have objects send messages
> to those objects.
> If there weren't a TrueClass and FalseClass, what else would true and
> false be?
>
> Jason

I would assume one class named like "Boolean".

TAke for example numbers -- there is only one Fixnum class which can
have many values. Similarly i would assume one Boolean class with values
true and false.
9e2504e0b74e5384af09ce8a660afac4?d=identicon&s=25 Pascal J. Bourguignon (Guest)
on 2009-01-14 15:15
(Received via mailing list)
Jason Roelofs <jameskilton@gmail.com> writes:

>> to define 2 separate renderers and editors for true and false.
>>
>> Just wondered what the thought behind this was?
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>>
>
> It's only the core philosophy of Ruby: You have objects send messages
> to those objects.
> If there weren't a TrueClass and FalseClass, what else would true and false be?

You could have a Boolean class with a truth value attribute.  But then
you couldn't implement ifTrue: and ifFalse: without circularity.

But even if we kept TrueClass and FalseClass, it would be better to have
a common generalization:

(class Boolean
  # empty
end)

(class TrueClass < Boolean
  # ...
end)

(class FalseClass < Boolean
  # ...
end)


So now the OP would be able to define methods at the level of the
Boolean class only.
Instead he will have to define his methods at the level of the Object
class.
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-14 15:16
(Received via mailing list)
Hi --

On Wed, 14 Jan 2009, Ruby Rabbit wrote:

>> It's only the core philosophy of Ruby: You have objects send messages
> true and false.
Google for:  ruby "boolean class"
This is a borderline perma-thread.


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2009-01-14 15:17
(Received via mailing list)
Hi,

In message "Re: Why do true and false have separate classes"
    on Wed, 14 Jan 2009 22:26:32 +0900, Ruby Rabbit
<sentinel.2001@gmx.com> writes:

|Having 2 separate classes really complicated things since i don't want
|to define 2 separate renderers and editors for true and false.

Unlike Java, true and false are mere representative of boolean values.
false and nil are treated as false value, and everyhing else are true
value.  So just moving true and false under Boolean does not solve the
problem, I think.

              matz.
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-14 15:39
(Received via mailing list)
Hi --

On Wed, 14 Jan 2009, Pascal J. Bourguignon wrote:

>>>
>> to those objects.
>
> Instead he will have to define his methods at the level of the Object class.
I know you know you don't need those parentheses. Is this a LISP
homage? :-)


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
7bdabe3f82c3021258af612ad346a349?d=identicon&s=25 LaP (Guest)
on 2009-01-14 17:20
(Received via mailing list)
David A. Black a écrit :

> I know you know you don't need those parentheses. Is this a LISP
> homage? :-)

At least this helps text editors keep good indentation ;)

LaP
9e2504e0b74e5384af09ce8a660afac4?d=identicon&s=25 Pascal J. Bourguignon (Guest)
on 2009-01-14 20:11
(Received via mailing list)
"David A. Black" <dblack@rubypal.com> writes:

>>>> I am writing a program in which some classes behave differently
>>>>
>>
>> end)
>>
>>
>> So now the OP would be able to define methods at the level of the Boolean class only.
>> Instead he will have to define his methods at the level of the Object class.
>
> I know you know you don't need those parentheses. Is this a LISP
> homage? :-)

We can say that yes.  I like the parentheses.  They help my editor to
implement higher level editing commands (it becomes a structural
editor).  It's also a way to remember that Ruby is just a lisp that
has been Matzacred.  And a wonder why Ruby users don't use the true
thing, Common Lisp.
0026dd77fd9ecc97b36e5b79cdbcf590?d=identicon&s=25 R. Kumar (sentinel)
on 2009-01-14 20:18
Pascal J. Bourguignon wrote:
> "David A. Black" <dblack@rubypal.com> writes:
>
>> I know you know you don't need those parentheses. Is this a LISP
>> homage? :-)
>
> We can say that yes.  I like the parentheses.  They help my editor to
> implement higher level editing commands (it becomes a structural
> editor).  It's also a way to remember that Ruby is just a lisp that
> has been Matzacred.  And a wonder why Ruby users don't use the true
> thing, Common Lisp.

"Matzacred" - rotfl.

I had heard that the true thing was Smalltalk.
A246f7c0ce5f2909483d358bd9e83e4e?d=identicon&s=25 Mike Gold (mikegold)
on 2009-01-14 20:54
Pascal J. Bourguignon wrote:
> It's also a way to remember that Ruby is just a lisp that
> has been Matzacred.

Is the intended pun "massacred lisp" ... or "Matz' sacred lisp"?
9e2504e0b74e5384af09ce8a660afac4?d=identicon&s=25 Pascal J. Bourguignon (Guest)
on 2009-01-14 21:32
(Received via mailing list)
Ruby Rabbit <sentinel.2001@gmx.com> writes:

>> thing, Common Lisp.
>
> "Matzacred" - rotfl.
>
> I had heard that the true thing was Smalltalk

 http://web.archive.org/web/20060522191515/http://r...

| Subject: Re: Ruby's lisp features.
| From: Yukihiro Matsumoto <matz ruby-lang.org>
| Date: Mon, 13 Feb 2006 13:43:02 +0900
| In-reply-to: 179515
|
| Hi,
|
| In message "Re: Ruby's lisp features."
|     on Mon, 13 Feb 2006 02:38:18 +0900, Edward Kenworthy <edward / kenworthy.info> 
writes:
|
| |I've been programming for more years than I care to remember and am
| |enjoying programming in Ruby (especially on Rails). So far I've found
| |nothing "new" (to me) in Ruby, with the exception of the lisp-like
| |features and that's something I'd really like to explore.
|
| |Anyone able to point me to a resource please?
|
| Ruby is a language designed in the following steps:
|
|   * take a simple lisp language (like one prior to CL).
|   * remove macros, s-expression.
|   * add simple object system (much simpler than CLOS).
|   * add blocks, inspired by higher order functions.
|   * add methods found in Smalltalk.
|   * add functionality found in Perl (in OO way).
|
| So, Ruby was a Lisp originally, in theory.
| Let's call it MatzLisp from now on. ;-)
|
|                             matz.
|=========================================================================
| (Yukihiro Matsumoto aka matz is the creator of Ruby).
9e2504e0b74e5384af09ce8a660afac4?d=identicon&s=25 Pascal J. Bourguignon (Guest)
on 2009-01-14 21:33
(Received via mailing list)
Mike Gold <mike.gold.4433@gmail.com> writes:

> Pascal J. Bourguignon wrote:
>> It's also a way to remember that Ruby is just a lisp that
>> has been Matzacred.
>
> Is the intended pun "massacred lisp" ... or "Matz' sacred lisp"?

Both are true.
B32a1911d783e0a95e0b062fd5d0b64b?d=identicon&s=25 Jan Friedrich (janfri)
on 2009-01-15 10:41
(Received via mailing list)
LaP <lap.nospam@free.fr> wrote:

> David A. Black a écrit :
>
>> I know you know you don't need those parentheses. Is this a LISP
>> homage? :-)
>
> At least this helps text editors keep good indentation ;)
>
> LaP

At least good editors doesn't need this for correct indentation. :P
2ee1a7960cc761a6e92efb5000c0f2c9?d=identicon&s=25 William James (Guest)
on 2009-01-15 11:41
(Received via mailing list)
Pascal J. Bourguignon wrote:

> Mike Gold <mike.gold.4433@gmail.com> writes:
>
> > Pascal J. Bourguignon wrote:
> >> It's also a way to remember that Ruby is just a lisp that
> >> has been Matzacred.
> >
> > Is the intended pun "massacred lisp" ... or "Matz' sacred lisp"?
>
> Both are true.

Wrong.  Neither is true.  That is, each is either false or nil.
Understand?

Acolytes of Commune Lisp are incapable of comprehending any language
that isn't as ancient as COBOL, FORTRAN, LISP, or APL.

Give one of them like this one an inch, and he will erase your
hard drive:

http://groups.google.com/group/comp.lang.lisp/msg/...
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-15 14:02
(Received via mailing list)
On Thu, 15 Jan 2009, Pascal J. Bourguignon wrote:

> Mike Gold <mike.gold.4433@gmail.com> writes:
>
>> Pascal J. Bourguignon wrote:
>>> It's also a way to remember that Ruby is just a lisp that
>>> has been Matzacred.
>>
>> Is the intended pun "massacred lisp" ... or "Matz' sacred lisp"?
>
> Both are true.

You're not the first person, not even the first person on this list,
who scoffs at Ruby -- and that's your prerogative -- but please do not
talk about Matz as someone who has "massacred" any language.

Aside from being snide and obnoxious, the notion of a massacre is just
plain wrong. Lisp is still alive, and you can still use it.

Let's be nice.


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
A246f7c0ce5f2909483d358bd9e83e4e?d=identicon&s=25 Mike Gold (mikegold)
on 2009-01-15 16:03
David A. Black wrote:
> On Thu, 15 Jan 2009, Pascal J. Bourguignon wrote:
>
>> Mike Gold <mike.gold.4433@gmail.com> writes:
>>
>>> Pascal J. Bourguignon wrote:
>>>> It's also a way to remember that Ruby is just a lisp that
>>>> has been Matzacred.
>>>
>>> Is the intended pun "massacred lisp" ... or "Matz' sacred lisp"?
>>
>> Both are true.
>
> You're not the first person, not even the first person on this list,
> who scoffs at Ruby -- and that's your prerogative -- but please do not
> talk about Matz as someone who has "massacred" any language.
>
> Aside from being snide and obnoxious, the notion of a massacre is just
> plain wrong. Lisp is still alive, and you can still use it.
>
> Let's be nice.

Maybe Internet discussions such as this shouldn't be taken so seriously.

I think Matzacred is funny and obnoxious at the same time, which is why
I don't mind it.  I'd rather laugh with the sinners than cry with the
saints.

If you were aiming to be a peacemaker, then you made a crucial mistake.
You did not address William James' posts, which have been at least
equally obnoxious.  It appears that you are only censuring Pascal.
9e2504e0b74e5384af09ce8a660afac4?d=identicon&s=25 Pascal J. Bourguignon (Guest)
on 2009-01-15 16:25
(Received via mailing list)
"David A. Black" <dblack@rubypal.com> writes:

>> Both are true.
>
> You're not the first person, not even the first person on this list,
> who scoffs at Ruby -- and that's your prerogative -- but please do not
> talk about Matz as someone who has "massacred" any language.
>
> Aside from being snide and obnoxious, the notion of a massacre is just
> plain wrong. Lisp is still alive, and you can still use it.
>
> Let's be nice.

The wrong doing is in the mindshare.  I agree that it is not as wrong
and bad as C++ or Java, but still.
This topic is locked and can not be replied to.