[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Question about Ruby philosophy

user@domain.invalid

12/4/2006 12:05:00 PM

Hello, when I compare Ruby to Java there is something I don't understand .

For example, let say that I create instances of JDBCFooBaseDriver in
Java - The methods and their behaviors will never change, unless I
update JDBCFooBaseDriver jar file. I can be sure that this part of my
environment will stay the same even if new third party libraries are
added and used by my application.

Now, in Ruby I can use a new library (FancyDates) that will alter the
behavior of some JDBCFooBaseDriver methods - Some methods of
JDBCFooBaseDriver will be redefined by FancyDates and new methods will
be added - All this stuff will occurs without giving me a chance to be
informed of what is going on under the scene.

So,

1) Is what I say right ?
2) Why should I not be scared by that ?
3) Why most C#, Java, C++ developper thinks that this approach is
dangerous and lead to bad practices ?

Thanks

If this question have been answered many times, feel free to only
provide some links to references.
24 Answers

Stephen Duncan Jr

12/4/2006 12:29:00 PM

0

As a Java developer still learning the Ruby way, here's my understanding:

1) Yes
2) If you're forced to integrate with code from bad programmers, maybe
you should be worried (maybe some Rubyists will provide some way this
can be mitigated...). If not then:
3) The Ruby philosophy is that it's better to give you, the developer,
the power to do things like this, even if you COULD should yourself in
the foot; Ruby trusts you to be smart and not make changes that will
break things.

I guess the only way to protect to yourself is to have automated
functional tests that provide you with comfort that everything works
even with all the code loaded that may make these kinds of
alterations.

-Stephen

On 12/4/06, Zouplaz <user@domain.invalid> wrote:
> Hello, when I compare Ruby to Java there is something I don't understand .
>
> For example, let say that I create instances of JDBCFooBaseDriver in
> Java - The methods and their behaviors will never change, unless I
> update JDBCFooBaseDriver jar file. I can be sure that this part of my
> environment will stay the same even if new third party libraries are
> added and used by my application.
>
> Now, in Ruby I can use a new library (FancyDates) that will alter the
> behavior of some JDBCFooBaseDriver methods - Some methods of
> JDBCFooBaseDriver will be redefined by FancyDates and new methods will
> be added - All this stuff will occurs without giving me a chance to be
> informed of what is going on under the scene.
>
> So,
>
> 1) Is what I say right ?
> 2) Why should I not be scared by that ?
> 3) Why most C#, Java, C++ developper thinks that this approach is
> dangerous and lead to bad practices ?
>
> Thanks
>
> If this question have been answered many times, feel free to only
> provide some links to references.
>
>


--
Stephen Duncan Jr
www.stephenduncanjr.com

Trans

12/4/2006 12:37:00 PM

0


Zouplaz wrote:
> Hello, when I compare Ruby to Java there is something I don't understand .
>
> For example, let say that I create instances of JDBCFooBaseDriver in
> Java - The methods and their behaviors will never change, unless I
> update JDBCFooBaseDriver jar file. I can be sure that this part of my
> environment will stay the same even if new third party libraries are
> added and used by my application.
>
> Now, in Ruby I can use a new library (FancyDates) that will alter the
> behavior of some JDBCFooBaseDriver methods - Some methods of
> JDBCFooBaseDriver will be redefined by FancyDates and new methods will
> be added - All this stuff will occurs without giving me a chance to be
> informed of what is going on under the scene.
>
> So,
>
> 1) Is what I say right ?
> 2) Why should I not be scared by that ?
> 3) Why most C#, Java, C++ developper thinks that this approach is
> dangerous and lead to bad practices ?

You are correct and your worry is not uncommon. And yes, it does _seem_
scary. But in practice it turns out not to be such a problem. Most
C/Java programmers don't know this simply b/c they can't do it. With a
bit of good sense, open classes can be a great productivity booster.
The reason for this are suprisingly simple. As with any library you
dont use it unless a) you need it and b) you know what it does. Combine
that with unit testing and there's no need to be so worried.

Also, it's generally accepted practice not to alter pre-existing
methods, and instead add new ones if you need additional functionality
(though there are execptions of course).

T.


Trans

12/4/2006 12:41:00 PM

0


Stephen Duncan wrote:
> As a Java developer still learning the Ruby way, here's my understanding:
>
> 1) Yes
> 2) If you're forced to integrate with code from bad programmers, maybe
> you should be worried (maybe some Rubyists will provide some way this
> can be mitigated...). If not then:
> 3) The Ruby philosophy is that it's better to give you, the developer,
> the power to do things like this, even if you COULD should yourself in
> the foot; Ruby trusts you to be smart and not make changes that will
> break things.

A typo I know, but that's a perfect way to put it: You can "should
yourself in the foot" with such worries :)

T.


Robert Klemme

12/4/2006 9:36:00 PM

0

On 04.12.2006 13:04, Zouplaz wrote:

Others have given good answers that I cannot answer better. However:

> 3) Why most C#, Java, C++ developper thinks that this approach is
> dangerous and lead to bad practices ?

Are you sure this is true? True, people frequently are scared of Ruby's
dynamic nature - or criticize it. But I would not go as far as to claim
that the majority of C# / Java developers thinks this approach is dangerous.

> If this question have been answered many times, feel free to only
> provide some links to references.

You will find discussions of these issues in threads dealing with
"dynamic typing" - there's a ton of them. Also, IIRC there are
discussions of these issues that revolve around "rational" which used to
change the behavior of Fixnum#/ which could cause problems for some
programs.

Kind regards

robert

Pat Maddox

12/4/2006 10:04:00 PM

0

On 12/4/06, Zouplaz <user@domain.invalid> wrote:
> Hello, when I compare Ruby to Java there is something I don't understand .
>
> For example, let say that I create instances of JDBCFooBaseDriver in
> Java - The methods and their behaviors will never change, unless I
> update JDBCFooBaseDriver jar file. I can be sure that this part of my
> environment will stay the same even if new third party libraries are
> added and used by my application.
>
> Now, in Ruby I can use a new library (FancyDates) that will alter the
> behavior of some JDBCFooBaseDriver methods - Some methods of
> JDBCFooBaseDriver will be redefined by FancyDates and new methods will
> be added - All this stuff will occurs without giving me a chance to be
> informed of what is going on under the scene.

Not really. Presumably if you're using a third-party library, you
have a clue as to why you're using it. You've probably looked at the
documentation, you definitely have access to the source. Not saying
you should need to examine the source to use a lib, but basically you
should at least read the documentation and stuff before blindly
throwing it into a project.



> So,
>
> 1) Is what I say right ?
> 2) Why should I not be scared by that ?
> 3) Why most C#, Java, C++ developper thinks that this approach is
> dangerous and lead to bad practices ?

There's potential for things to go wrong, I guess. Just like there's
potential for mistakes in dynamic typing. Those opposed to dynamic
typing will say stuff like, "Well what if someone calls
refigerator.meow? It blows up at run time!" Those kinds of questions
basically boil down to "What if I'm stupid?" Well, can't help you
there...

Basically, just give Ruby a shot for a while. Use it in a real
project. If it doesn't work for you, drop it.

Pat

Martin DeMello

12/4/2006 10:29:00 PM

0

On 12/5/06, Robert Klemme <shortcutter@googlemail.com> wrote:
> "dynamic typing" - there's a ton of them. Also, IIRC there are
> discussions of these issues that revolve around "rational" which used to
> change the behavior of Fixnum#/ which could cause problems for some
> programs.

First I've heard of the 'used to'! When did that change?

martin

Max Muermann

12/5/2006 12:29:00 AM

0

On 12/4/06, Zouplaz <user@domain.invalid> wrote:
> Hello, when I compare Ruby to Java there is something I don't understand .
>
> For example, let say that I create instances of JDBCFooBaseDriver in
> Java - The methods and their behaviors will never change, unless I
> update JDBCFooBaseDriver jar file. I can be sure that this part of my
> environment will stay the same even if new third party libraries are
> added and used by my application.
>
> Now, in Ruby I can use a new library (FancyDates) that will alter the
> behavior of some JDBCFooBaseDriver methods - Some methods of
> JDBCFooBaseDriver will be redefined by FancyDates and new methods will
> be added - All this stuff will occurs without giving me a chance to be
> informed of what is going on under the scene.
>
> So,
>
> 1) Is what I say right ?
> 2) Why should I not be scared by that ?
> 3) Why most C#, Java, C++ developper thinks that this approach is
> dangerous and lead to bad practices ?
>

I can only speak from a Java perspective here, but if you look at what
most frameworks and (shudder) containers out there do, you'll find
there is an enormous amount of reflection going on. The more modern
frameworks also make use of runtime bytecode manipulation. Both of
these techniques introduce the same type of dynamics into a project
(and negate the "advantages" of static typing), but - unlike Ruby - it
is almost impossible to understand what is going on under the hood.
And every framework does things in a different way. At least with
Ruby, you can recognise this kind of metaprogramming easily, and if
used in libraries its use is normally well documented.

Ruby programmers are simply more aware of these features and are
therefore able to use them effectively.

Cheers,
Max

> Thanks
>
> If this question have been answered many times, feel free to only
> provide some links to references.
>
>

Edwin Fine

12/5/2006 12:42:00 AM

0

The bottom line seems to be that the current crop of Ruby programmers
are responsible enough not to mess with things under the hood unless
they understand the workings.

Is this an accurate assessment?

What scares me a bit is when Ruby becomes extremely popular and every
second programmer is using it, and less-disciplined developers start
providing libraries that tinker with core classes willy-nilly. At some
point you are going to get clashes between two same-named add-on methods
in (say) Array, that do different things <shudder>. That could be fun to
debug.

Sure, you can decide not to use such a library, but you have to get
burned first before you realize it's not good to use. I'm probably
showing my age here, but I remember cases where people used to code
macros in C header files (like MIN and MAX) that would clash with other
uses of MIN and MAX and cause untold havoc. Some of these were from
mainstream companies.

It's one thing to say "What if I'm stupid?". It's quite another thing to
say, "What if lots of stupid/undisciplined people start using Ruby?"
This tends to be the price of language popularity, I fear.

Probably, evolutionary forces will get rid of the poorly designed
libraries in time. I'm more worried about the beleaguered corporate IT
developer who often does not have much choice and has to use in-house
code.

I dunno. Thoughts?

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

David Vallner

12/5/2006 1:02:00 AM

0

Robert Klemme wrote:
> On 04.12.2006 13:04, Zouplaz wrote:
>
> Others have given good answers that I cannot answer better. However:
>
>> 3) Why most C#, Java, C++ developper thinks that this approach is
>> dangerous and lead to bad practices ?
>
> Are you sure this is true? True, people frequently are scared of Ruby's
> dynamic nature - or criticize it. But I would not go as far as to claim
> that the majority of C# / Java developers thinks this approach is
> dangerous.

<rant>

Aaactually, yes, they/we do. The Ruby way presumes reasonably skilled
coders, not going overboard on clobbering , sufficient documentation,
and test coverage. After having seen my odd share of undocumented,
untested messes (usually cobbled together by generations of interns)
that are *barely* maintainable -with- the security blanket of type
checks, tool support, and no possibility of out-of-sight clobbering
changes, I pray /those people/ don't discover Ruby with me having to set
eyes on their code.

(I'm not accepting that the blame be laid on the language, the problems
are usually plain newbiedom, laziness, or copy-pasting snippets of "what
everyone before used and worked" instead of cleaning up the design. I've
seen it with Java, I've seen it with PHP, I have very little doubts I'll
eventually see it with Ruby when it reaches the popularity / hype
threshold. Some of that approach I already notice in some of the newbie
posts here, though in yet negligible amounts.)

Compared with Ruby having a low barrier to entry, followed by a (IMO)
steep learning curve to mastery, and the tendency of people in their
intern phase to be infatuated by shiny sparkly objects (like, oh, witty
eval meta hacks), this scares the heck out of me. (Hopefully, the
harmful features are too advanced for the pointy-haired-boss-acting-hip
sort of programmers.)

Basically, the messiest Java codebase I can imagine isn't nearly as
scary as the messiest Ruby one. FUD? Maybe. Personal experience?
Certainly - code I have to tackle would invariably be much worse if it
abused the wordt of Ruby. But as usual, just a language comparison
without context doesn't really say anything, and the above quoted point
3 is an overgeneralising blanket statement; i.e. more often than not,
patent nonsense, and at least in this case, horribly phrased. Lack Of A
Clue (tm) is what leads to bad practices, the important question is "How
bad practices can you have?". Or scratch that, the only practically
relevant question is "How bad practices DO you have right now?",
anything more general tends to speculation, and in programming
discussions, speculations leads to a vapid cloudfest really fast.

Provided the assumptions mentioned hold for a project during its
lifetime, the dangers of the approach are a non-issue. Except they don't
necessarily, and then the security blanket helps a lot - not everyone
can afford to wrinkle his nose in disgust at ugly code and quit on a
whim. (Need just a *little* more time in the global Fortune 100 entries
spearheading the CV before I can consider moving on from "grin and bear
the soul-draining horror 75% of the time, read bash.org for the rest of
it" employment to being more picky with regards to personally rewarding
experiences.) Ruby's critical point of mass adoption is yet to come, and
if the blogosphere noise is even remotely representative, I'm halfways
sure it -will- come (the mindshare Ruby gets despite not having a single
notable sugar daddy is rather spectacular), and I expect Interesting
Things (tm) to happen if/when it does. Hopefully, of the good sort (job
openings, development funding), but the opposite (widespread
language-altering libraries becoming a tangled mess that requires effort
to get working in a nontrivial project) isn't entirely impossible.

</rant>

David Vallner
Sleep Deprived

Ara.T.Howard

12/5/2006 1:02:00 AM

0