Forum: Ruby Diff of opinion on dynamic stuff

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.
20b256c6ae857102b2c0721b4a7ba682?d=identicon&s=25 Drew Mills (Guest)
on 2005-12-22 22:30
(Received via mailing list)
Let me preface this post by saying that I'm no Ruby expert.  I like it.
 It's fun.  But I won't claim extensive knowledge on it.

So when this guy blogs about a Python quality that he feel is better
than a Ruby quality:

    It's the second generation that's going to be less enthused,
    that's going to stare in bafflement at these classes that
    mysteriously spawn methods, and trying to figure out what's
    going when there's an exception in dynamically generated
    code. You can monkeypatch code in Python pretty easily, but we
    look down on it enough that we call it "monkeypatching". In
    Ruby they call it "opening a class" and think it's a cool
    feature. I will assert: we are right, they are wrong.

    -- http://blog.ianbicking.org/theres-so-much-more-tha...

I am curious what this means.  Is Python against dynamic stuff?  And
Ruby for it?  And so we just agree to disagree?  Or do I misunderstand?

Just curious.

Drew
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2005-12-22 23:12
(Received via mailing list)
Hi,

In message "Re: Diff of opinion on dynamic stuff"
    on Fri, 23 Dec 2005 06:27:50 +0900, "Drew Mills"
<drewmills@gmail.com> writes:

|    In Ruby they call it "opening a class" and think it's a cool
|    feature. I will assert: we are right, they are wrong.
|
|    -- http://blog.ianbicking.org/theres-so-much-more-tha...
|
|I am curious what this means.  Is Python against dynamic stuff?  And
|Ruby for it?  And so we just agree to disagree?  Or do I misunderstand?

"open class" is so strong (often too strong), we can break things
easily.  In other word, Ruby trust you to give you sharp knives, where
Python don't.  From the Python point of view, it's wrong, I guess.

							matz.
4b174722d1b1a4bbd9672e1ab50c30a9?d=identicon&s=25 Ryan Leavengood (Guest)
on 2005-12-22 23:18
(Received via mailing list)
On 12/22/05, Drew Mills <drewmills@gmail.com> wrote:
>     code. You can monkeypatch code in Python pretty easily, but we
>     look down on it enough that we call it "monkeypatching". In
>     Ruby they call it "opening a class" and think it's a cool
>     feature. I will assert: we are right, they are wrong.
>
>     -- http://blog.ianbicking.org/theres-so-much-more-tha...
>
> I am curious what this means.  Is Python against dynamic stuff?  And
> Ruby for it?  And so we just agree to disagree?  Or do I misunderstand?

I think what he is complaining about are some of the dynamically
created convenience methods provided by ActiveRecord when dealing with
the Model for a database. Things like Person.find_by_user_name are
methods which are implemented using method_missing to do specific
searches of database tables. Because these aren't "real methods", Ian
feels they could be hard to debug. He probably has a point. But in
this case I think the convenience overrides the occasional weird bug.
I don't keep up with the Rails list and haven't done much Rails
programming yet, but it might be interesting to see how many problems
there are related to these kind of methods. I suspect in reality there
are many less than what Mr. Bicking might think.

Also his lack of Ruby knowledge is showing in that he is talking about
method_missing implementations being like "opening a class", which
they aren't. They are basically dynamic method dispatch.

There are a lot of neat things that can be done with method_missing
that are very powerful and convenient. I certainly do not subscribe
the Pythonic "it is better not to have something powerful if it can be
occasionally dangerous" philosophy that Mr. Bicking is describing. I
suspect most other Rubyists (and Matz) have the same opinion.

Regarding the issue of "re-opening a class", there is certainly room
for abuse here. Again in my opinion the convenience and flexibility
this provides probably out-weigh the risks. Others may not agree. But
there are a lot of major Ruby libraries that would be totally
different and/or impossible if we didn't have this feature. Rails and
RubyGems both come to mind, as well as a lot of the code provided in
the standard library. All I know is that I really cringe when I look
back at Java code which requires separate utility classes for special
String methods instead of just adding them to the String class (which
you cannot do in Java without the source code for it.) To me it makes
sense to just re-open the class and add the methods there, where they
belong. But I've been programming Ruby for quite a while, so maybe I'm
just brainwashed ;)

Ryan
E3c79c779c0b390049289cdfe7cb9705?d=identicon&s=25 Bob Hutchison (Guest)
on 2005-12-22 23:24
(Received via mailing list)
On Dec 22, 2005, at 4:27 PM, Drew Mills wrote:

>     going when there's an exception in dynamically generated
>     code. You can monkeypatch code in Python pretty easily, but we
>     look down on it enough that we call it "monkeypatching". In
>     Ruby they call it "opening a class" and think it's a cool
>     feature. I will assert: we are right, they are wrong.
>
>     -- http://blog.ianbicking.org/theres-so-much-more-tha...
>
> I am curious what this means.  Is Python against dynamic stuff?  And
> Ruby for it?  And so we just agree to disagree?  Or do I
> misunderstand?

Well, Python is plenty dynamic. I think he is complaining about
Ruby's ability to re-open a class. This can make it difficult to find
the complete definition of a class (imagine doing this in a
completely random way in multiple files). So while it can be abused,
it can also be an incredible simplification of the code you write.
One thing it does is flattens inheritance hierarchies,  you don't
need to introduce specialising classes just to add a few methods.
Using xampl as an illustration: the Ruby version of xampl generates 1
class for every 3 generated by the Java version of xampl, one of
those classes is eliminated because I can re-open classes (the other
is eliminated due to duck typing). Another thing reopening classes
does is, obviously, to allow you to extend the built in Ruby classes
(they are just classes after all). I suppose Ian would think things
even worse because in Ruby you can do this to objects as well as
classes.

This 'monkeypatching' is very similar to concepts in Smalltalk and
CLOS (Common Lisp's object system). Nobody in those communities
complains too much (though Smalltalk's browser reassembles classes
for you, and new CLOS programmers are sometimes at a bit of a loss
because in CLOS methods may belong to two or more classes and it
doesn't seem that the obvious thing to do is the right thing). Ruby
just makes thing a lot easier.

Just be careful where you aim that thing.

Cheers,
Bob

>
> Just curious.
>
> Drew
>
>

----
Bob Hutchison          -- blogs at <http://www.recursive.ca/hutch/>
Recursive Design Inc.  -- <http://www.recursive.ca/>
Raconteur              -- <http://www.raconteur.info/>
2c51fec8183a5d21c4e11b430beabb47?d=identicon&s=25 Patrick Hurley (Guest)
on 2005-12-22 23:33
(Received via mailing list)
On 12/22/05, Bob Hutchison <hutch@recursive.ca> wrote:
> >     It's the second generation that's going to be less enthused,
> > I am curious what this means.  Is Python against dynamic stuff?  And
> Using xampl as an illustration: the Ruby version of xampl generates 1
> complains too much (though Smalltalk's browser reassembles classes
> >
>
>
>
>

I think there are two conflated issues here. First open classes and
their abuse and second dynamic method creation. I think they distinct
enough they should be considered separately.

Considering open classes, I find many of the conventions used in
Rails, once they are understood, simplify the resulting code. Given
this, it is worth pointing out that Rails is fairly unique in Ruby
development being a mainstream library that does modify base classes.
Additionally very few of the enhancements to the base classes are
"non-obvious" even a non-programmer will recognize the purpose of
item.pluralize. It is arguable and I would not disagree that this is
still thin ice. Using different Ruby libraries may cause issues?it
would be good if such changes could be better scoped. Still in
practice I have encountered none of the sort of problems I have would
expected. And unit tests are still the best medicine

The second issue of dynamic method generation (which I think was the
meat of the above quote) seems more like a documentation issue than
anything else. Consider a different framework that used a data file to
code generate a large number of access methods into a database,
similar to the functionality which is dynamically generated within
ActiveRecord?would this be the monkey patching that is so troubling?
Similarly, while it can take some acclimation, who cannot understand
code like:

item_list = Item.find_all_upc(upc)

Yes, you would look long and hard to find this particular method in
the API, but once the convention is understood (as it should be by
anyone who has developed in Rails for more than a day or two) it is
very intuitive.

In the end, I think it is a matter of trust. Any programming language
worth using, can be used poorly. Ruby and Python are no exception in
this regard. Writing good code which by definition is maintainable
code by both first and second generation coders is difficult. Rails
uses much of the power of the Ruby language to map the code to the
problem domain (database driven web applications).

As always the devil is in the details. I would be very curious which
aspects of Ruby/Rails development in particular anyone thinks will be
a long term maintenance issue.

pth
4674615d2cf231975c741731be9a8685?d=identicon&s=25 why the lucky stiff (Guest)
on 2005-12-22 23:39
(Received via mailing list)
Yukihiro Matsumoto wrote:
> "open class" is so strong (often too strong), we can break things
> easily.  In other word, Ruby trust you to give you sharp knives, where
> Python don't.  From the Python point of view, it's wrong, I guess.
>
Matz has put us in great danger.  But Rubyist are okay with it I guess.
I am strangely at peace with this perilous language in my home!

Superman does dangerous things to solve problems, too.  He'll bend a
street pole around a villianous guy.  People, stop cheering.

_why
682fff6db11e1a150d6ce17f3b862448?d=identicon&s=25 Doug H (Guest)
on 2005-12-23 00:18
(Received via mailing list)
Anyone who tries to reverse engineer ruby code into a different
language is bound to be frustrated.
47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 Joel VanderWerf (Guest)
on 2005-12-23 00:27
(Received via mailing list)
Yukihiro Matsumoto wrote:
> "open class" is so strong (often too strong), we can break things
> easily.  In other word, Ruby trust you to give you sharp knives, where
> Python don't.  From the Python point of view, it's wrong, I guess.

A chef will tell you that sharp knives are safer than dull ones, since
they do not have to be forced.
4b174722d1b1a4bbd9672e1ab50c30a9?d=identicon&s=25 Ryan Leavengood (Guest)
on 2005-12-23 00:51
(Received via mailing list)
On 12/22/05, Joel VanderWerf <vjoel@path.berkeley.edu> wrote:
> Yukihiro Matsumoto wrote:
> > "open class" is so strong (often too strong), we can break things
> > easily.  In other word, Ruby trust you to give you sharp knives, where
> > Python don't.  From the Python point of view, it's wrong, I guess.
>
> A chef will tell you that sharp knives are safer than dull ones, since
> they do not have to be forced.

If these two quotes together aren't a perfect Ruby quotable quote, I
don't know what is.

<tongue_in_cheek>

And now we have another weapon in the Python vs Ruby war:

Python: Dull
Ruby: Sharp

</tongue_in_cheek>

Seriously though, a Python vs Ruby war is kind of dumb, since it is
like brothers fighting.

Ryan
Bf1e672f5e54581db4e6d45b7030d286?d=identicon&s=25 Steven Lumos (Guest)
on 2005-12-23 00:54
(Received via mailing list)
why the lucky stiff <ruby-talk@whytheluckystiff.net> writes:
> street pole around a villianous guy.  People, stop cheering.
>
> _why

I'm going to play devil's advocate and hopefully somebody with some
direct experience will chime in.

Rubyists are mostly people who know how not to aim at their foot, and
are skilled in first-aid just in case.  But what happens when the code
is delivered and moves into maintenance mode? It falls into the hands
of code-slaves who are just dying to sacrifice toes and heap the blame
straight on you is what.  I'm assuming it's these -- probably not
Rubyist -- people who are being refered to as the "second generation".

Surely, if you delivered Pascal code instead of Ruby code, it would be
less likely that the bozo trying to make a one-line change is going to
end up deleting 25 million rows from your customer's database or
something.

Steve
Fd22ee3cfc7dac283ce8e451af324f7d?d=identicon&s=25 Chad Perrin (Guest)
on 2005-12-23 02:46
(Received via mailing list)
On Fri, Dec 23, 2005 at 07:36:48AM +0900, why the lucky stiff wrote:
> Yukihiro Matsumoto wrote:
> >"open class" is so strong (often too strong), we can break things
> >easily.  In other word, Ruby trust you to give you sharp knives, where
> >Python don't.  From the Python point of view, it's wrong, I guess.
> >

I understood that 100%, and agree with it similarly.  Keep in mind, I'm
mostly coming to Ruby from the direction of Perl -- the Swiss Army
Chainsaw to some -- and have no problem with being handed a sharp tool
and being told to be careful with it.

Perhaps more imporantly than how this relates to my agreement, though,
is the fact that I think you have hit on a fundamental point of
divergence between the Python community and most of the rest of the
"very powerful and succinct scripting language" communities out there
(particularly Lisp, Perl, and Ruby come to mind).  Python is,
essentially, to this family of languages as Pascal is to the family of
languages that includes stuff like C++, Objective C, and so on.

Some languages are designed primarily to empower the programmer,
trusting that the programmer will be smart enough to avoid doing
something suicidal with that power.  Python strikes me, on reflection,
as a language designed primarily to protect the programmer, trusting
that the programmer will be smart enough to use it effectively despite
limitations.

. . . and thus, I have more explanation and understanding of why Python
just "feels wrong" to me.  One of the reasons I like Perl is that it
doesn't limit me "for my own good".  I guess I prefer a swiss army
chainsaw over a plastic scalpel. [1]


> Matz has put us in great danger.  But Rubyist are okay with it I guess.
> I am strangely at peace with this perilous language in my home!
>
> Superman does dangerous things to solve problems, too.  He'll bend a
> street pole around a villianous guy.  People, stop cheering.

Nice to know your emails are as entertaining as your excellent Ruby
tutorial.


[1] No offense intended to the "plastic scalpel" contingent.  There's
nothing objectively wrong with precision wedded to safety limitations.
I simply find it to be subjectively distasteful.

--
Chad Perrin [ CCD CopyWrite | http://ccd.apotheon.org ]

unix virus: If you're using a unixlike OS, please forward
this to 20 others and erase your system partition.
Fd22ee3cfc7dac283ce8e451af324f7d?d=identicon&s=25 Chad Perrin (Guest)
on 2005-12-23 02:52
(Received via mailing list)
On Fri, Dec 23, 2005 at 08:53:18AM +0900, Steven Lumos wrote:
>
> Rubyists are mostly people who know how not to aim at their foot, and
> are skilled in first-aid just in case.  But what happens when the code
> is delivered and moves into maintenance mode? It falls into the hands
> of code-slaves who are just dying to sacrifice toes and heap the blame
> straight on you is what.  I'm assuming it's these -- probably not
> Rubyist -- people who are being refered to as the "second generation".

I think you're probably right, and it's a valid concern.  I just don't
think it's a valid reason for eschewing Ruby.


>
> Surely, if you delivered Pascal code instead of Ruby code, it would be
> less likely that the bozo trying to make a one-line change is going to
> end up deleting 25 million rows from your customer's database or
> something.

That's really only because while it might take a ten-line change to do
the same thing in Pascal, that one line in Ruby has the functionality of
about twenty lines of Pascal code.  There are things I like about
Pascal, but this isn't one of them.

By the way . . .
I have, in the past, found myself thinking Python might be the Pascal of
scripting languages, and you got me thinking about that again.
--
Chad Perrin [ CCD CopyWrite | http://ccd.apotheon.org ]

unix virus: If you're using a unixlike OS, please forward
this to 20 others and erase your system partition.
A87f7a014c624587fab0d3d78c5b9c18?d=identicon&s=25 Bil Kleb (Guest)
on 2005-12-23 03:43
(Received via mailing list)
Steven Lumos wrote:
>
> Rubyists are mostly people who know how not to aim at their foot, and
> are skilled in first-aid just in case.  But what happens when the code
> is delivered and moves into maintenance mode?

My code goes into maintenance mode almost as soon as
I've written 40 lines, i.e., I try to go depth-first
and then flesh out the skeleton as priorities dictate.

This is all done while creating a safety-net, a custom-
application debugger, through test-first development.
(Note: I've never had need of Ruby's debugger.)

The maintenance folks (me initially) are left with
executable, non-lying specifications for how everything
should behave and recipes for building new safety net.

Later,
Bc6d88907ce09158581fbb9b469a35a3?d=identicon&s=25 James Britt (Guest)
on 2005-12-23 04:28
(Received via mailing list)
Bob Hutchison wrote:
...

> Just be careful where you aim that thing.


Oh, inspiration for Yet Another Ruby Slogan:

Ruby: You'll Shoot Your Eye Out.

(Mad props to Ralphie, too.)

James Britt
--

http://www.ruby-doc.org       - Ruby Help & Documentation
http://www.artima.com/rubycs/ - Ruby Code & Style: Writers wanted
http://www.rubystuff.com      - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com     - Playing with Better Toys
http://www.30secondrule.com   - Building Better Tools
A0599814ceddc2e283792f4e47c57f5e?d=identicon&s=25 Brian Takita (Guest)
on 2005-12-23 05:04
(Received via mailing list)
There seems to be alot of industry inertia on static time tools. Better
runtime tools would make a dynamic language such as Ruby more
mainstream.

A number of people have proposed that the runtime tools can work with
good
unit tests in place to exercise all of the code paths.

The breakpoint library is a good start but there is more potential. For
example, a tool that analyzes the runtime paths and graphs an object's
dependencies would be nice.
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 unknown (Guest)
on 2005-12-23 05:31
(Received via mailing list)
Hi --

On Fri, 23 Dec 2005, Chad Perrin wrote:

> and being told to be careful with it.
> trusting that the programmer will be smart enough to avoid doing
> something suicidal with that power.  Python strikes me, on reflection,
> as a language designed primarily to protect the programmer, trusting
> that the programmer will be smart enough to use it effectively despite
> limitations.

I've had for a long time a kind of semi-formulated idea about all this
in my head, and have never expressed it clearly.  Let me try, and
probably fail.

In the Perl world, there was ("was" as in, I'm not in that world any
more) a perennial sense that all this "shooting in the foot" stuff was
a kind of test of personal resistance and fortitude.  It felt
sometimes like the power of the language was mainly serving to allow
people to demonstrate how careful and wise they were.  I don't say
that the best Perl programmers fell into this pattern, but in a wider
sense it definitely seemed that knowing about the "rope", and
maintaining a healthy distance from it, was a kind of badge of honor.

In Ruby, I see it differently.  This is where I start having trouble
expressing it.  It's a kind of wish that the gravitational forces be
aligned differently: instead of showing one's strength by pulling
away from the vortex, perhaps the powerful things in the language
could be *used* in productive ways, so that one falls *toward* them,
but without danger.

I'm not sure what this means, in practical terms.


David

--
David A. Black
dblack@wobblini.net

"Ruby for Rails", from Manning Publications, coming April 2006!
http://www.manning.com/books/black
1b9427edf8a90eb877b3490a7b36b95c?d=identicon&s=25 Matthew J Desmarais (Guest)
on 2005-12-23 05:34
(Received via mailing list)
On Fri, 2005-12-23 at 12:27 +0900, James Britt wrote:
> (Mad props to Ralphie, too.)
>
> James Britt
Holy Crap.  If that were to end up on clothing, I would buy it.  I mean,
I'd have all my Christmas shopping done by now.

Cheers,
Matthew J Desmarais
Ff63c03fd68754adbadd2c6314646bef?d=identicon&s=25 Bill Guindon (agorilla)
on 2005-12-23 05:37
(Received via mailing list)
On 12/22/05, James Britt <james_b@neurogami.com> wrote:
> Bob Hutchison wrote:
> ...
>
> > Just be careful where you aim that thing.
>
>
> Oh, inspiration for Yet Another Ruby Slogan:
>
> Ruby: You'll Shoot Your Eye Out.

It is indeed "The Red Ruby BB Gun"
Well done!
682fff6db11e1a150d6ce17f3b862448?d=identicon&s=25 Doug H (Guest)
on 2005-12-23 06:10
(Received via mailing list)
Bill Guindon wrote:
>
> It is indeed "The Red Ruby BB Gun"
> Well done!

A BB gun doesn't cut it though.
Ever seen the movie Training Day?:
http://img456.imageshack.us/img456/3705/trainingday8ry.jpg
8979474815030ad4a5d59718d1905715?d=identicon&s=25 Isaac Gouy (Guest)
on 2005-12-23 06:50
(Received via mailing list)
Bob Hutchison wrote:
> >     that's going to stare in bafflement at these classes that
> > misunderstand?
> those classes is eliminated because I can re-open classes (the other
>  because in CLOS methods may belong to two or more classes and it
>  doesn't seem that the obvious thing to do is the right thing). Ruby
>  just makes thing a lot easier.

Yes, the equivalent of "method_missing" has been used for many things
in Smalltalk.  Glorifying in how we can hack "doesNotUnderstand:"
avoids having to admit that there's been a problem with the language.

"This comparison highlights that the most commonly used technique based
on the specialization of the doesNotUnderstand: method is not the best
one. As a first explanation of this situation, one should note that the
ability to directly execute a method has only lately been introduced in
the interpreters (methods valueWithReceiver:arguments: on
CompiledMethod class in VisualWorks and
executeWithReceiver:andArguments: in IBM Smalltalk). Moreover, this
comparison shows that the techniques based on VM lookup method or
method wrappers should be considered by more programmers than it is
currently the case."

"Evaluating Message Passing Control Techniques in Smalltalk"
http://www.iam.unibe.ch/~scg/Archive/Papers/Duca99...
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2005-12-23 07:08
(Received via mailing list)
On Dec 22, 2005, at 8:37 PM, Bill Guindon wrote:

>
> It is indeed "The Red Ruby BB Gun"
> Well done!

Well you can shoot your own eye out but just remember one thing.
Rubyists don't throw rocks at dogs.

-Ezra
E3c79c779c0b390049289cdfe7cb9705?d=identicon&s=25 Bob Hutchison (Guest)
on 2005-12-23 15:10
(Received via mailing list)
On Dec 22, 2005, at 5:30 PM, Patrick Hurley wrote:

> I think there are two conflated issues here. First open classes and
> their abuse and second dynamic method creation. I think they distinct
> enough they should be considered separately.

I agree. But these issues and a few others (e.g. types, inheritance,
encapsulation, modules, namespaces) are often combined, or conflated,
deliberately, into a single solution -- the Class. For an absolutely
excellent explanation of the reasoning see Bertrand Meyer's <http://
en.wikipedia.org/wiki/Bertrand_Meyer> Object Oriented Software
Construction 2nd Edition where he lays out Eiffel (which you really
have to try seriously before you dismiss it). For an absolutely
excellent experience of what happens when you relax some of this give
CLOS -- or Ruby -- a try.


> practice I have encountered none of the sort of problems I have would
> expected. And unit tests are still the best medicine

Xampl also modifies existing classes. It will, optionally, write a
file that shows you exactly what it did, but the changes are very
uniform and predictable. From what I've seen of Rails the changes it
makes are also uniform and predictable (I don't know if it will write
a file). Furthermore, it looks as though the demands of Rails and
xampl are independent. I've found that the biggest problem comes from
putting requirements on the inheritance structure of extended
objects. Ruby lets you side-step that problem very neatly (Java does
not -- it is horribly complex what you have to do).

Unit tests are necessary I think. But they are not sufficient. Back
in the Old Days when we worked in assembler, there was this horrid
practice of 'patching' that worked by loading the original code then
over-writing parts, maybe just a few bytes, of that with new code
that fixed problems. This was a nightmare. Assembler is bad enough,
patches are over top. Now, in Ruby, what if some clever 'programmer'
decides to fix a problem by replacing a method without removing the
original from the source? Though this is better than the assembler
situation it is still outrageous... well, at least I'd be outraged
not to mention enraged :-) And unit tests won't detect this behaviour.

Never-the-less, I *like* open classes. They are very powerful, very
useful.

> item_list = Item.find_all_upc(upc)
>
> Yes, you would look long and hard to find this particular method in
> the API, but once the convention is understood (as it should be by
> anyone who has developed in Rails for more than a day or two) it is
> very intuitive.


A little more than just a documentation issue I think, but certainly
related. What if a soon-to-be-unemployed 'programmer' built up a
string in memory, maybe computing the name somehow, then evaled it?
The fact that the original method is also generated, and that you
know that because Rails is consistent, will only make it harder to
even recognise what is happening.

(I still like this capability, don't forget, just pointing out a
stupid thing to do)

>
> In the end, I think it is a matter of trust. Any programming language
> worth using, can be used poorly. Ruby and Python are no exception in
> this regard. Writing good code which by definition is maintainable
> code by both first and second generation coders is difficult. Rails
> uses much of the power of the Ruby language to map the code to the
> problem domain (database driven web applications).

I agree. But a lot of people think programmers need safety shields.

>
> As always the devil is in the details. I would be very curious which
> aspects of Ruby/Rails development in particular anyone thinks will be
> a long term maintenance issue.

Not the code generation part I think, in fact, it might turn out to
be a major boon to maintenance (fix it in one place kind of thing).
I'd be more concerned with having to re-factor a controller and
breaking a bunch of URLs (but I don't know Rails well enough to know
if this is actually a possible issue).

Cheers,
Bob

>
> pth

----
Bob Hutchison          -- blogs at <http://www.recursive.ca/hutch/>
Recursive Design Inc.  -- <http://www.recursive.ca/>
Raconteur              -- <http://www.raconteur.info/>
2c51fec8183a5d21c4e11b430beabb47?d=identicon&s=25 Patrick Hurley (Guest)
on 2005-12-23 15:34
(Received via mailing list)
On 12/23/05, Bob Hutchison <hutch@recursive.ca> wrote:
> I agree. But these issues and a few others (e.g. types, inheritance,
> encapsulation, modules, namespaces) are often combined, or conflated,
> deliberately, into a single solution

These are powerful tools and their power increases by using them
together, I suppose that the danger (the point of the article) may as
well, but you would have to show me a case. The "danger" issues appear
to be specific case issues and not with their combined use.

> ...in Ruby, what if some clever 'programmer'
> decides to fix a problem by replacing a method without removing the
> original from the source?

Trust :-)
It is possible to intentionally write code to pass a unit test and
later fail. Of course you could argue that some higher level set of
tests should fail and start a "arms race" with your devious
programming the and rest of the responsible coders writing unit tests.
Of course you could just take the poor misguided soul aside and
explain the error of their ways -- show them how to write a proper
unit test for the original method that was in error and then correct
it. Of course if you could just fire the numbnut too :-) If you work
in an environment where you cannot trust the developers powerful tool
may be better replaced with straight jackets -- as always select the
best tool for your environment and task.

> A little more than just a documentation issue I think, but certainly
> related. What if a soon-to-be-unemployed 'programmer' built up a
> string in memory, maybe computing the name somehow, then evaled it?

Trust...

> I'd be more concerned with having to re-factor a controller and
> breaking a bunch of URLs (but I don't know Rails well enough to know
> if this is actually a possible issue).

Internal to the application good coding in Rails uses url_for type
helpers that will generally deal with all of this correctly. External
to the app, if it is a concern routes can be pretty easily manipulated
-- but this is a good point for externally linked sites, action names
are "pushed" into your URL interface by default and they should be
carefully considered.

> Cheers,
> Bob

Happy Holidays and thank you for taking the time to respond
pth
E3c79c779c0b390049289cdfe7cb9705?d=identicon&s=25 Bob Hutchison (Guest)
on 2005-12-23 15:37
(Received via mailing list)
On Dec 23, 2005, at 12:47 AM, Isaac Gouy wrote:

> Yes, the equivalent of "method_missing" has been used for many things
> in Smalltalk.  Glorifying in how we can hack "doesNotUnderstand:"
> avoids having to admit that there's been a problem with the language.

The problem being: in Smalltalk the language there is no explicit way
in the language to add a method to a class at runtime?

Maybe so, but the Smalltalk *environment* allows the programmer to do
exactly the same thing as the browser or debugger at runtime (though
only on a class level). In some implementations, there is a method
that changes an object's class, and that combined with the ability to
create a new class at runtime... (well, this is hard to manage, and
some implementations will, effectively, only redefine the parent
class of an object). This excessive use/dependency on
doesNotUnderstand is not necessary in Smalltalk.

Isn't re-opening a class very similar to some of the better methods
in the paper below? At the very least, the associated problems are
similar :-)

What are the Python folks doing as an alternative?

> executeWithReceiver:andArguments: in IBM Smalltalk). Moreover, this
> comparison shows that the techniques based on VM lookup method or
> method wrappers should be considered by more programmers than it is
> currently the case."
>
> "Evaluating Message Passing Control Techniques in Smalltalk"
> http://www.iam.unibe.ch/~scg/Archive/Papers/
> Duca99aMsgPassingControl.pdf

----
Bob Hutchison          -- blogs at <http://www.recursive.ca/hutch/>
Recursive Design Inc.  -- <http://www.recursive.ca/>
Raconteur              -- <http://www.raconteur.info/>
Bc6d88907ce09158581fbb9b469a35a3?d=identicon&s=25 James Britt (Guest)
on 2005-12-23 16:13
(Received via mailing list)
Matthew J Desmarais wrote:
>>
>>Ruby: You'll Shoot Your Eye Out.
>>
>>(Mad props to Ralphie, too.)
>>
>>James Britt
>
> Holy Crap.  If that were to end up on clothing, I would buy it.  I mean,
> I'd have all my Christmas shopping done by now.

Oooo ...


Off to the RubyStuff secret lab ...



James


--

http://www.ruby-doc.org       - Ruby Help & Documentation
http://www.artima.com/rubycs/ - Ruby Code & Style: Writers wanted
http://www.rubystuff.com      - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com     - Playing with Better Toys
http://www.30secondrule.com   - Building Better Tools
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2005-12-23 16:43
(Received via mailing list)
On 12/23/05, Ezra Zygmuntowicz <ezmobius@gmail.com> wrote:

> Well you can shoot your own eye out but just remember one thing.
> Rubyists don't throw rocks at dogs.

The Rubyist, Dog's best friend :)
E0ed615bd6632dd23165e045e3c1df09?d=identicon&s=25 =?ISO-8859-1?Q?Florian_Gro=DF?= (Guest)
on 2005-12-23 20:54
(Received via mailing list)
Brian Takita wrote:

> There seems to be alot of industry inertia on static time tools. Better
> runtime tools would make a dynamic language such as Ruby more mainstream.
>
> A number of people have proposed that the runtime tools can work with good
> unit tests in place to exercise all of the code paths.
>
> The breakpoint library is a good start but there is more potential. For
> example, a tool that analyzes the runtime paths and graphs an object's
> dependencies would be nice.

The ruby-breakpoint library is not yet everything I would like it to be.

I might even morph it into a Smalltalk style IDE in the future.

However, as soon as I have that PowerBook I owe myself I will work on
finishing the basic functionality of the GUI client. After that we'll
see what else is possible. I have high hopes on GTK2 and Glade and all
that. It makes it easy to keep the code in a clean and sane state.

Here's a recent screenshot of what already works:

http://flgr.0x42.net/breakpoint/cyclic-threads.png

The code visible on there is the code of the GUI itself. It is written
in wxRuby and ugly. wxRuby tends to be in the way way too often.

I want this to work well on OS X, though, which means that it should run
without an X server. There's a port of GTK going on that should achieve
just that. I'd like to test this, but am still missing the PowerBook. It
should reach me soon enough, though...

And Ruby-GTK just rocks.

The more help I can get on this the better. But I'm also interested in
other development tools that actually make use of Ruby's dynamic nature
instead of working around it... (For example the method name completion
in jEdit's Ruby plug in is insanely clever. We need more of that kind of
thing!)
E0ed615bd6632dd23165e045e3c1df09?d=identicon&s=25 =?ISO-8859-1?Q?Florian_Gro=DF?= (Guest)
on 2005-12-23 21:00
(Received via mailing list)
dblack@wobblini.net wrote:

> In Ruby, I see it differently.  This is where I start having trouble
> expressing it.  It's a kind of wish that the gravitational forces be
> aligned differently: instead of showing one's strength by pulling
> away from the vortex, perhaps the powerful things in the language
> could be *used* in productive ways, so that one falls *toward* them,
> but without danger.

Wrapping unrubyish things behind a rubyish interface so other people can
do things in the Ruby way without endangering themself?

Of course this doesn't work when the very thing you are trying to do is
unrubyish and not just its implementation.

Oh, and I didn't define "rubyish" and its opposite on purpose because I
can't.
E0ed615bd6632dd23165e045e3c1df09?d=identicon&s=25 =?ISO-8859-1?Q?Florian_Gro=DF?= (Guest)
on 2005-12-23 21:12
(Received via mailing list)
Ryan Leavengood wrote:

> And now we have another weapon in the Python vs Ruby war:
>
> Python: Dull
> Ruby: Sharp

Heh, and suddenly the name C# starts making sense when comparing it to
Java.

Not meaning to start a language war here either. I don't like Java, but
will let people use it. Hell, I even have to use it myself.
Fd22ee3cfc7dac283ce8e451af324f7d?d=identicon&s=25 Chad Perrin (Guest)
on 2005-12-23 23:40
(Received via mailing list)
On Sat, Dec 24, 2005 at 04:58:52AM +0900, Florian GroƟ wrote:
> do things in the Ruby way without endangering themself?
I don't think that was the intent of that statement at all.

--
Chad Perrin [ CCD CopyWrite | http://ccd.apotheon.org ]

unix virus: If you're using a unixlike OS, please forward
this to 20 others and erase your system partition.
8979474815030ad4a5d59718d1905715?d=identicon&s=25 Isaac Gouy (Guest)
on 2005-12-27 20:09
(Received via mailing list)
Bob Hutchison wrote:
> On Dec 23, 2005, at 12:47 AM, Isaac Gouy wrote:
>
> > Yes, the equivalent of "method_missing" has been used for many things
> > in Smalltalk.  Glorifying in how we can hack "doesNotUnderstand:"
> > avoids having to admit that there's been a problem with the language.
>
> The problem being: in Smalltalk the language there is no explicit way
> in the language to add a method to a class at runtime?

Adding a method to a class at runtime is trivial, simply send the
message "compile: aMethodSourceString" to the class.

Integer compile: 'plus: anInteger
^self + anInteger'


afaict Over the years Smalltalk has accumulated a bunch of really
clever programming techniques to work-around the lack of meta protocols
for controlling message passing.

afaict CLOS provides directly what Smalltalk can only accomplish
indirectly - so we should celebrate "doesNotUnderstand:" trickery as
clever programming rather than clever language design.
Cc8334869c9d2a9e603017f2da805eb3?d=identicon&s=25 Ian Bicking (Guest)
on 2005-12-28 21:38
(Received via mailing list)
Drew Mills wrote:
>     code. You can monkeypatch code in Python pretty easily, but we
>     look down on it enough that we call it "monkeypatching". In
>     Ruby they call it "opening a class" and think it's a cool
>     feature. I will assert: we are right, they are wrong.
>
>     -- http://blog.ianbicking.org/theres-so-much-more-tha...
>
> I am curious what this means.  Is Python against dynamic stuff?  And
> Ruby for it?  And so we just agree to disagree?  Or do I misunderstand?

There's some inaccurate ideas of Python in this thread, so I just
thought I'd chime in with a followup.  You can open a class in Python
just fine (except for some select built-in classes which are closed
except in subclasses, like int, list, dict).  Opening a class in Python
does not look as nice as in Ruby, and is used less often.  In Python it
looks like this:

  class Foo(object):
      pass

  def new_method(self, blah): ...
  Foo.new_method = new_method

You can also open instances in Python, replace objects with a delegate
or completely different implementation, and lots of other things, many
of which are very bad ideas.  There was also some mention of
method_missing in the thread, and I can assure you that it is present
in Python as well (__getattr__) and used fairly often.

My criticism isn't about what you *can* do in either language -- both
languages are quite open in this respect.  Instead it is about what the
community and the language itself encourage you to do (in this case
Ruby encourages opening classes by making the syntax appealing, and the
community encourages it because examples of opening a class are fairly
common).  In Python I consider opening a class to be a kind of code
smell  (http://xp.c2.com/CodeSmell.html) -- but smelly code happens,
and the entire point of code smell is that a technique might *suggest*
problems in code, but does not *necessarily* mean that the code is bad.
 The code might just be tackling a complex problem, or working around
problems in other code.

In a dynamic language like Ruby or Python we have to be very aware of
code smells because that's a big part of what keeps us sane.  In both
languages there are techniques that look fine, but experience shows us
are dangerous or indicative of misdesign.  Here I'm highlighting a case
where opinions on design differ between the communities.  It's easy to
tell they differ *because* the technique is available in both
languages.

Also, to generalize, it seems that the Ruby community is perhaps less
sensitive to code smells or more tollerant of magic compared to the
Python community, which I guess was my larger point.  Though I also
think that the specific case of opening a class is important enough
that it's also worthy of discussion, but this thread doesn't seem to
have much discussion of that particular issue.  If you have a sharp
tool it is good to discuss what the appropriate use of that tool is --
sharp tools are only safer than dull tools if you use them correctly!

  Ian
31ab75f7ddda241830659630746cdd3a?d=identicon&s=25 Austin Ziegler (Guest)
on 2005-12-28 21:59
(Received via mailing list)
On 28/12/05, Ian Bicking <ianb@colorstudy.com> wrote:
> Also, to generalize, it seems that the Ruby community is perhaps less
> sensitive to code smells or more tollerant of magic compared to the
> Python community, which I guess was my larger point.

Is it less sensitive to code smells, or is it something that isn't
considered a code smell in Ruby? I think that the Ruby community is as
... rough on code smell as any community, but we consider different
things smelly than the Python community does.

I think that's where some of the resistance to your points come in; to
the community at large, it is not necessarily considered bad to write
something that essentially opens classes (or objects) again. See my
own Transaction::Simple for an example -- it injects its functionality
into any class that requests it. In Ruby, that's definitely not code
smell. In Python? I don't know.

-austin
Cc8334869c9d2a9e603017f2da805eb3?d=identicon&s=25 Ian Bicking (Guest)
on 2005-12-28 23:45
(Received via mailing list)
Austin Ziegler wrote:
> On 28/12/05, Ian Bicking <ianb@colorstudy.com> wrote:
> > Also, to generalize, it seems that the Ruby community is perhaps less
> > sensitive to code smells or more tollerant of magic compared to the
> > Python community, which I guess was my larger point.
>
> Is it less sensitive to code smells, or is it something that isn't
> considered a code smell in Ruby? I think that the Ruby community is as
> .. rough on code smell as any community, but we consider different
> things smelly than the Python community does.

It's a little of both -- clearly there's some awareness among Ruby
programmers that opening classes introduces some possible issues.  And
the "sharp tools" comments imply that there's potential to cut
yourself, but people feel that's okay.  There's always a danger to any
technique; the question is how much danger is okay, depending on how
complex the problem at hand is.  I get a sense that prevailing opinion
in the Ruby community accepts a balance with more danger than in
Python.  Neither language forces you to be careful or not; in both you
could do explicit (runtime) type checking, or you can generate source
willy-nilly, or anything in-between.

Also, there's the issue about what is smelly at all.  Of course,
anything that is unusual is a bit smelly, so there's a circular
justification; opening a class is smelly in Python because people don't
do it, and people don't do it because it is smelly.  But just because
idioms are different doesn't mean that there isn't *any* commonality --
in both languages you are signficantly affecting code that isn't
"yours".

> I think that's where some of the resistance to your points come in; to
> the community at large, it is not necessarily considered bad to write
> something that essentially opens classes (or objects) again. See my
> own Transaction::Simple for an example -- it injects its functionality
> into any class that requests it. In Ruby, that's definitely not code
> smell. In Python? I don't know.

In Python, probably with a delegate, though multiple inheritance or a
mix-in would also be possible.  Also, I think there's something very
different about a class that pulls in functionality, from code that
pushes functionality into a class that might not be expecting it.  As I
said, there's room for discussion -- there's probably very useful rules
of thumb that could be offered about what's a good use of this sort of
feature, and what's bad.

  Ian
Cee38055ae36590c654c04c2d5cc2778?d=identicon&s=25 Sky Yin (Guest)
on 2005-12-29 00:43
(Received via mailing list)
On 12/28/05, Austin Ziegler <halostatue@gmail.com> wrote:
> See my
> own Transaction::Simple for an example -- it injects its functionality
> into any class that requests it. In Ruby, that's definitely not code
> smell. In Python? I don't know.

Looks like AOP-style feature. AOP is definitely powerful though there
was a debate
<http://www.theserverside.com/news/thread.tss?threa... its
potential of being dangerous. Even strong-type language Java has several
AOP
implementations, some of which modify byte-codes on the fly (poor java
guys
don't have open class). Not to mention the usage in Rails (ex.
before_filter, acts_as_*).

I feel that Ruby is more implicit than Python in style, which is
actually
similar to our natural languages, though we may sometimes misunderstand
each
others.
918c6daad03c85e51ad1a11f57017947?d=identicon&s=25 Devin Mullins (Guest)
on 2005-12-29 03:35
(Received via mailing list)
Ian Bicking wrote:

>>>
>yourself, but people feel that's okay.  There's always a danger to any
>technique; the question is how much danger is okay, depending on how
>complex the problem at hand is.  I get a sense that prevailing opinion
>in the Ruby community accepts a balance with more danger than in
>Python.
>
Well, I can think of two applicable "dangers," off the top of my head:
the danger of coding the wrong thing (i.e. bugs), and the danger of
taking to long to do it (i.e. un-maintainability) (and, of course,
they're related). Many factors play a role in this, including unit
tests, coding skills, code complexity, the language semantics at hand...
And I think Rubyists are just tackling those two dangers with a
different combination of tools than the Pythonistas -- not saying that
"more danger is okay."

Devin
A0599814ceddc2e283792f4e47c57f5e?d=identicon&s=25 Brian Takita (Guest)
on 2005-12-30 20:08
(Received via mailing list)
One thing that Open objects are useful for are creating
"seams<http://c2.com/cgi/wiki?SoftwareSeam>"
and making the object easier to test. Bearing this in mind, systems that
use
open objects can be made more reliable than systems that dont.
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 unknown (Guest)
on 2006-01-01 21:33
(Received via mailing list)
Hi --

On Sat, 24 Dec 2005, Chad Perrin wrote:

>> Wrapping unrubyish things behind a rubyish interface so other people can
>> do things in the Ruby way without endangering themself?
>
> I don't think that was the intent of that statement at all.

You're right: it wasn't :-)

I think the best example is still the idea of something along the
lines of Ruby Behaviors or selector namespaces -- that is, a way to
make changes to core Ruby that are block- or file- or
namespace-scoped.  (Ruby Behaviors was my attempt; there have been
others, and selector namespaces is a possible way this kind of thing
might happen in Ruby 2.)  The idea is to harness the power, rather
than look at it as something that only serves the purpose of not being
used.

Basically it seems to me that if a language is designed with this kind
of power, and it's unuseable (or nearly so), that has to mean that the
design doesn't make sense.  I am convinced that Ruby's design makes
sense.  I think it just hasn't been fully explored and exploited.

Mind you, there are several "Behaviors"-like libraries (better written
than Behaviors, in fact), yet I don't personally know of anyone who
uses them.  So maybe the demand for this isn't so great... but I
continue to believe that if there were some way to make limited-scope
core changes built into the language, it *would* be used.  And it
would take a lot of pressure off the RCR process :-)

Anyway, that's an example -- for me probably the best one -- of what I
mean by finding ways to fall *toward* the power of the language,
instead of constantly pushing away from it.


David

--
David A. Black
dblack@wobblini.net

"Ruby for Rails", from Manning Publications, coming April 2006!
http://www.manning.com/books/black
This topic is locked and can not be replied to.