Defending Ruby's OOP

On May 11, 2007, at 11:34 AM, Peña, Botp wrote:

anyway, can we chain booleans like this?

Indeed, it is a pointless argument. Even smalltalk is not 100 percent
OOP because the characters you use to type code are not objects. [ is
not an object and neither is ]
Big deal.
‘if’ could be made an object that responds to a message by returning
the equivalent of ‘jump’ or ‘goto’ in ASM or not. (which is basically
all if does in any language.)
You could very well make if an object if you wanted to, but there
would be little benefit, and only extra overhead for nearly pointless
abstraction.
The whole thing is just debasing an argument to win a debate.

On 5/11/07, Gregory B. [email protected] wrote:

But here’s a naive implementation of what you’re looking for:

Note if you really wanted to use this, you’d need to use some sort of
blank slate for your Null object.

On 5/10/07, Peña, Botp [email protected] wrote:

From: Jason R. [mailto:[email protected]] :

Or better yet, tell him to design a language that has “if”

“unless” etc as objects and see where that goes. What does having

if/unless as objects even mean?

Maybe they mean a boolean class. I myself would like a boolean class in ruby. Sometimes, i feel if-else constructs too restrictive,… maybe i hate grammar rules… (maybe because i find english weird language??)

anyway, can we chain booleans like this?

(x<2).iftrue{“got it!”}.capitalize.each{|c| puts c}

to get each char, you don’t do each, you do something like each_byte {
|c| c.chr }

But here’s a naive implementation of what you’re looking for:

class Null
def self.method_missing(id,*args)
self
end
end

class Object
def iftrue
self ? yield : Null
end
end

x = 1
(x<2).iftrue{“got it!”}.capitalize.each_byte {|c| puts c.chr}

x = 3
(x<2).iftrue{“got it!”}.capitalize.each_byte {|c| puts c.chr }

On 10.05.2007 21:51, Gary W. wrote:

If Ruby is 100% OOP, then what is Smalltalk?
Probably more in the 120% area. :wink:

robert

Probably more in the 120% area. :wink:

robert

LOL… That makes Smalltalk somehow metaphysical… It’s like saying
I am 120% human… That is 20% more human than a human can be…
scary :stuck_out_tongue:

Enrique Comba R.

On May 11, 2007, at 4:04 PM, Enrique Comba R. wrote:

Probably more in the 120% area. :wink:

robert

LOL… That makes Smalltalk somehow metaphysical… It’s like
saying I am 120% human… That is 20% more human than a human can
be… scary :stuck_out_tongue:

Enrique Comba R.

Smalltalk IS somehow metaphysical! quantum-something.
Ruby is a nice blend like good coffee

On Fri, May 11, 2007 at 04:53:06AM +0900, Dan Debertin wrote:

But to answer your actual question, your friend is correct. for, case,
do, else, if, etc. are reserved words, not objects. Check your pickaxe
book, page 329.

Blocks are not objects, either, until they are encapsulated into a Proc
object. Methods are also not objects, until they are encapsulated into
a Method object.

Making everything an object makes the language more consistent, but IMO
less natural. In fact, I think OOP isn’t very natural, but is beautiful
once you learn it.

Paul

On 5/10/07, Giles B. [email protected] wrote:

Smalltalk is the purest OOP language there is and it doesn’t have
if or unless at all. You know how you can bypass control structures in
Ruby by using blocks and closures instead? In Smalltalk, that’s the
only way to do control structures at all. “If” and “unless” don’t even
exist in Smalltalk.

Not entirely true.

Yes, in Smalltalk control structures are built using methods on
Booleans and Blocks, and with Block arguments.

On the other hand, most Smalltalk implementations cheat on this.
There’s an old VM implementors mantra that you have to cheat so you
have to work hard not to get caught cheating. In practice if:else:
gets compiled down to test and branch bytecodes, with exception
processing to handle the rare case where the receiver isn’t a boolean.
Evaluating a block in Smalltalk looks like a message send but in
reality it’s usually implemented as optimized byte code sequences
after some analysis. This led to some mystifying code reading. The
old Digitalk Smalltalk had the value method in Block which read

value
^self value

Which sure looks like it should be an infinite loop. In reality, this
code never got executed except when someone did something silly like:

 [1 + 2] perform:#value

or maybe less silly by doing this with a stored block.

In this regard, the purest OO language when it comes to control
structures is probably Self, which avoided such hand-crafted
optimizations in favor of dyamically optimized code.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

Hi Lucas,

On 10 May 2007, at 21:26, Lucas H. wrote:

Hi,

I’ve got someone here saying that Ruby (and other languages) can’t be
100% object-oriented because if and unless and so on (keywords) are no
objects.

How can I defend the claim that Ruby is 100% OOP?

Do you have to?

There are a lot of languages claiming to be pure OO languages, but
are they really? What is a pure OO language at all?

Some say Java is OO, but is it? I don’t think so. Java is OO in a
sense but lacks a lot of features that would make is “purely” OO.

A pure OO implementation of a language would have to have the
capacity to model anything in life. That is we would not have only
objects (or classes) but would also need some kind of verb construct
that we would be able to model. Or how do you model a class for let’s
say a while statement? This would be a verb that you could model
somehow…

verb While
def condition_met?
#bla bla bla
end
end

The real question here is if it makes sense at all. I think that the
work done so far in OO is much more impressive than this. Instead of
trying to focus on the pureness of a language regarding it’s OO-ness
we should focus on how good can I model the Domain Model (i.e. the
problem) at hand and how good does it help me to solve that problem.

Coming from a Java environment I can remember the times when we used
JDBC (back in the late 90’s) coding our access to the database,
transactions, two-phase-commits. Then Hibernate appeared down the
road and made life easier. And in Ruby…

Well, if you have ever coded a database access in Java (or C, or any
compiled language y guess) and then see the power of ActiveRecord
(and of Ruby in this case), how it dynamically gives you methods to a
class that did not have them before… That is impressive!

It not only helps you to work faster and having more fun (something i
really appreciate, I remember a few months ago, when I started
working with Ruby I changed a middleware server my company did in
Java for the last one and a half years in one day using Ruby), it
gives you those tools (idiomatic) to model much better the domain at
hand.

And that is something to consider. Does this language help me to get
the job done? Or if you are talking to your boss… Than make a
simple calculus:

1,5 years coding in Java = hundreds of thousands of euros
1 day coding in Ruby = lots of fun

Cheers,

Enrique Comba R.

Lucas H. wrote:

Hi,

I’ve got someone here saying that Ruby (and other languages) can’t be
100% object-oriented because if and unless and so on (keywords) are no
objects.

How can I defend the claim that Ruby is 100% OOP?

Yeah, it is just silly. If he has his own definition of 100% OOP, why
not make each character am object? What about font size? I agree with
the earlier post, argue with smarter people.

Lucas H. wrote:

Hi,

I’ve got someone here saying that Ruby (and other languages) can’t be
100% object-oriented because if and unless and so on (keywords) are no
objects.

How can I defend the claim that Ruby is 100% OOP?

I have to wonder what exactly the benefit of having control structures
as objects would be? The bottom line effectiveness of any language
relates to what one can accomplish with it and how efficiently said task
can be accomplished. Under what circumstance would overriding the “if”
method be beneficial? Not to mention the fact that since Ruby provides
the ability to override things like operators and more functional
components (that can be more logically represented as objects), then why
would the lack of control structure object orientation make Ruby less of
an OO language? Not to mention the kind of trouble that one could easily
get into attempting to override control structures.

Remind him that Ruby is, of course, superior to all other languages
because it is red.

On May 10, 2007, at 3:26 PM, Lucas H. wrote:

Peter B.
[email protected]
917 445 5663

On May 15, 2007, at 4:55 AM, Mike H. wrote:

less of
an OO language? Not to mention the kind of trouble that one could
easily
get into attempting to override control structures.


Posted via http://www.ruby-forum.com/.

Hmm… there could be some bizarre and interesting possibilities.
For example, instead of if,
why not a construct called ‘perhaps’ or ‘maybe’ to include randomness
or other interesting side-effects.
Or even ‘occasionally’ or ‘usually’ for weighted randomness.
Adverbs could make very interesting control structures, which could
of course be def’d more (or less) precisely.
Imagine the expressive possibilities of: often, quickly, slowly,
monthly, quarterly, hourly, randomly, quietly, obsequiously,
obscenely, derisively, politely, privately, publicly, etc…
‘unless’ could be ‘other_than’ or ‘except_if’
‘if’ itself could be semantically described as the same as ‘when’ in
many human languages.
Rather than simply being declarative like java keywords, many
constructs could become more descriptive.
This is one of Ruby’s biggest strengths, its expressiveness in a very
natural way.

Once it has got the native unicode thing happening, it will be
possible to begin to write Ruby in languages other than English!
Even in Japanese (which would by its grammar, make a very good
programming language)

Some abstraction is bad because it continues to slow things down, but
processing power is still increasing, while human limits are pretty
constant.

On the other hand, most Smalltalk implementations cheat on this.
There’s an old VM implementors mantra that you have to cheat so you
have to work hard not to get caught cheating. In practice if:else:
gets compiled down to test and branch bytecodes, with exception
processing to handle the rare case where the receiver isn’t a boolean.
Evaluating a block in Smalltalk looks like a message send but in
reality it’s usually implemented as optimized byte code sequences
after some analysis. This led to some mystifying code reading. The

Wow, that’s kind of surprising. So if you wanted to rewrite
Smalltalk’s Boolean logic, at that point even Smalltalk wouldn’t be
turtles all the way down?

In Smalltalk’s defense, dynamically patching Boolean logic is not a
common use case.


Giles B.

I’m running a time management experiment: I’m only checking e-mail
twice per day, at 11am and 5pm. If you need to get in touch quicker
than that, call me on my cell.

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org

I’ve got someone here saying that Ruby (and other languages) can’t be
100% object-oriented because if and unless and so on (keywords)
are no
objects.

I have to wonder what exactly the benefit of having control structures
as objects would be? The bottom line effectiveness of any language

Hmm… there could be some bizarre and interesting possibilities.
For example, instead of if,
why not a construct called ‘perhaps’ or ‘maybe’ to include randomness
or other interesting side-effects.
Or even ‘occasionally’ or ‘usually’ for weighted randomness.

I suppose it could make sense, actually, for a language where you
could patch If objects dynamically with fuzzy logic or Bayesian
back-propagation. Then you could say things like “for certain values
of if” and mean it.

You would have to call a language like that Socrates, I think.

Technically, though, couldn’t you build that in Ruby in about twenty
minutes? I think a framework in Ruby for weirdly-patched Boolean logic
would be much quicker to build than the individual weird patches
would. You could just do it with three methods named iif, aand, oor,
and then have them default to standard Boolean implementations of
if/and/or unless alternative implementations were supplied.


Giles B.

I’m running a time management experiment: I’m only checking e-mail
twice per day, at 11am and 5pm. If you need to get in touch quicker
than that, call me on my cell.

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org

On 5/10/07, Gregory B. [email protected] wrote:

On 5/10/07, Bill G. [email protected] wrote:

I’m patiently waiting for the Oatsmobile.

And once you get one, you can declare yourself to be Oatman! I’m not
sure what superpowers that brings, besides being ‘regular’.

well, a car fueled by oats would probably be carbon neutral…
One has to be careful about that, it depends how the oat is grown :frowning:
Oatman
would indeed be as least as eco-friendly as captain planet!
Picard’s brother?

Robert