Question about Ruby philosophy

David Vallner wrote:

Robert Klemme wrote:

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.

<rant>
I'm with David Vallner on this.

I've had to deal with a vast number of "messes" in too many languages to
mention, so this isn't a Ruby-specific phenomenon. Ruby simply adds one
more unique way to shoot yourself in the foot (I refer specifically to
the open classes). Speaking of shooting feet, if you haven't seen it,
there is an old but hilarious list of ways to shoot yourself in the foor
with <some programming language>:

http://www-users.cs.york.ac.uk/susan/joke/foot.htm

I don't know if Ruby has an entry for this somewhere on the Internet.
How about a Ruby Quiz for the funniest way to shoot yourself in the foot
with Ruby?

James Gray wrote:

I'm with Ruby's natural tendency on this issue: trust the programmer.

Sorry, but I don't think it's enough to trust the programmer - at least,
most of them. For every thoughtful, careful, circumspect programmer out
there, there are 100 or more clueless, undisciplined, lazy, and/or just
plain stupid programmers (of course none of the people on this forum
fall into this category :slight_smile:

I'm not Ruby-bashing. I think Ruby is great, and consider it in general
to be the best language I have worked with; it's certainly the most
enjoyable to use.

I just don't look forward to having to debug some horribly-written Ruby
code that is doing something bizarre because someone thought they were
clever and added something inadvisable to some core class somewhere. I
have seen this kind of thing way too often (I have seen, for example,
standard C library header files in /usr/include modified to make
something work in a project, then the whole application stop working
when the header file was overwritten when the OS (I think it was AIX)
got a patch kit.)

</rant>

···

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

unknown wrote:

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.

   harp:~ > irb
   irb(main):001:0> Array.freeze
   => Array

   irb(main):002:0> class << Array; def each() 'ha-ha'; end; end
   TypeError: can't modify frozen object
           from (irb):4
           from :0

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?

what if people start coding in c and leave dangling pointers lying
around,
double free pointers, corrupt the heap in their lib, forget the clean-up
resources in at_exit handlers, or don't prefix each and every
var/function/macro with something like my_lib_XXX?

where would we be? :wink:

i can hear people thinking 'java' out there already - but those guys are
manipulating byte code to subvert their fist-cuffs already! anyone know
a
thing or two about boost::any? on a related note, it seems the most
useful
ocaml code uses the type system in a way that makes the promise of
'safe'
programs more difficult or impossible for the compiler to ensure...

history has shown that there is exactly __one__ re-usable component of
code:
the shared library. at least in the *nix world, nearly all of them are
written
in c and it is plagued by issues at least two orders of magnitude, imho,
worse
than clobbering Array#each! yet, the internet continues to be powered
by *nix
servers running said c libraries :wink:

(ducking)

-a

Ah, but here's the difference. You have to know a fair amount of C to
even build a shared library, using malloc() and friends for memory
(mis)management. You have to compile and link the code.

It's a lot more work than writing
class Array
  def clobbersomething
  end
end

In Java, it's not trivial to manipulate bytecode. It's usually done by
experts, although there are frameworks out there that make it easier.

It's a lot more work than writing
class Array
  def clobbersomething
  end
end

You are not going to get rank beginners to use Boost::anything. It
doesn't even compile on all major compilers (e.g. Only the most recent
versions of HPUX aCC support partial template specialization), and I
defy any average intern to decipher C++ compile-time error messages
relating to template problems.

It sure is a lot more work than writing
class Array
  def clobbersomething
  end
end

Please, I am not Ruby-bashing. I know there are far worse languages out
there from the point of view of shooting yourself in the foot (I've used
enough of them that I'm lucky even to have any feet left :). Any
language that provides a lot of power can be misused. Ruby simply makes
this one thing so easy to do, with such potentially dire consequences.
If anything, I'd just want an optional way (besides .freeze) to control
what can and can't be extended at run-time, to prevent accidental,
ill-advised, or even malicious tampering, or to help identify it). Hey,
maybe there's a way to do it already?

···

On Tue, 5 Dec 2006, Edwin Fine wrote:

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

Such shameless self promotion... Go to Gifts - CafePress
as penance :wink:

Fred
(well... Guilty as charged :wink: )

···

On 12/4/06 6:13 PM, "James Britt" <james.britt@gmail.com> wrote:

Edwin Fine wrote:

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.

Ruby: You'll Shoot Your Eye Out!

http://www.cafepress.com/rubyshootout.46707105

(Yes, a shameless plug. But hey; Christmas is coming! )

--
Frederic Jean
fred@fredjean.net
http://typo.fredjean.net/

Hi,

···

In message "Re: Question about Ruby philosophy" on Tue, 5 Dec 2006 17:20:10 +0900, Robert Klemme <shortcutter@googlemail.com> writes:

I believe I remember that "1 / 2" used to return "Rational(1, 2)" with
'rational' loaded. Is my memory wrong here?

Perhaps, you've confused 'rational' and 'mathn'.

              matz.

Christian Neukirchen writes:

Do you consider Ruby a good language for teaching people that haven't
programmed yet? Just wondering.

Sorry for answering the question addressed not to me,
but I'm an aged professional programmer who programmed in many languages and for a long time was a lecturer and trainer of OOP.
Compared to other programming languages Ruby has many attracting features. It is clear in understanding, pure OO, lightweight and elegant, pragmatic and powerful, cross-platform, was deriveded from good parent languages, absorbed modern programming ideas, supports different programming paradigms.
So Ruby is almost ideally suitable for students and teachers, and I strongly recommend for beginner programmers to start with Ruby.

Mike Shock
www.shokhirev.com/mikhail/

Christian Neukirchen wrote:

Do you consider Ruby a good language for teaching people that haven't
programmed yet? Just wondering.

I personally consider teaching programming in any language without a
REPL as Cruel and Unusual (tm) torture. Compiler-wrestling is a skill of
much value, but should be kept out of introductory courses and put into
language-specific seminars, IMO.

Disclaimer: That's from the position of a "victim" of having an
introductory course in (Borland Turbo) C, not an actual instructor.

David Vallner

You either trust the programmer or you don't. There's no in between,
no way to trust some programmers. Last I checked, no compiler or
interpretter has an IQ test during the installation.

If you think the computer is smarter than you or your coworkers, than
Ruby isn't for you. If you're smarter than the computer, then it's
probably a good match.

Pat

···

On 12/4/06, Edwin Fine <efine145-nospam01@usa.net> wrote:

James Gray wrote:
> I'm with Ruby's natural tendency on this issue: trust the programmer.

Sorry, but I don't think it's enough to trust the programmer - at least,
most of them. For every thoughtful, careful, circumspect programmer out
there, there are 100 or more clueless, undisciplined, lazy, and/or just
plain stupid programmers (of course none of the people on this forum
fall into this category :slight_smile:

Ah, but here's the difference. You have to know a fair amount of C to
even build a shared library, using malloc() and friends for memory
(mis)management. You have to compile and link the code.

It's a lot more work than writing
class Array
def clobbersomething
end
end

gcc -shared a.c

??

not too hard. but i understand your point. still, i disagree that the people
releasing rubygems are of any lower quality than the people releasing shared
libraries. remember, if the code is not available the question is rather moot
and, in any language, you'll notice only 1% of coders releasing libraries.
this works in our favour with respect to robustness.

In Java, it's not trivial to manipulate bytecode. It's usually done by
experts, although there are frameworks out there that make it easier.
It's a lot more work than writing

class Array
def clobbersomething
end
end

the same can be said of meta-programming and manipulating built-ins in ruby.
i've spoken on both subjects a few times and have many libraries out there
that do some of each or both - my perception has never been that the even
above average ruby hacker is doing tons of either, especially without thinking
about it.

You are not going to get rank beginners to use Boost::anything. It
doesn't even compile on all major compilers (e.g. Only the most recent
versions of HPUX aCC support partial template specialization), and I
defy any average intern to decipher C++ compile-time error messages
relating to template problems.

no argument there. the point though, was that boost and many other powerful
tools do indeed subvert the safety systems of their respective languages. as
in ruby, great power is dangerous.

It sure is a lot more work than writing
class Array
def clobbersomething
end
end

on thing to consider, however, is also how easy it would be to debug such an
error. it'd literally be

   Array.freeze
   require 'clobbersomething.rb' #=> beautiful stack-trace

this is no small point. as someone who doesn't even write c code without
firing up gcc i can assure you that, in 6 years of full-time ruby hacking,
i've never pulled those week long
sinking-feeling-in-the-pit-of-your-stomach-marathon-gdb-sessions i used to
routinely pull when i worked with c-- and c more often!

we've all corrupted the heap before... :wink:

Please, I am not Ruby-bashing. I know there are far worse languages out
there from the point of view of shooting yourself in the foot (I've used
enough of them that I'm lucky even to have any feet left :). Any language
that provides a lot of power can be misused. Ruby simply makes this one
thing so easy to do, with such potentially dire consequences. If anything,
I'd just want an optional way (besides .freeze) to control what can and
can't be extended at run-time, to prevent accidental, ill-advised, or even
malicious tampering, or to help identify it). Hey, maybe there's a way to do
it already?

i think everyone is on the same page with you here, and you comments are
certainly well taken. i'll leave to others to comment on potential solutions.

kind regards.

-a

···

On Tue, 5 Dec 2006, Edwin Fine wrote:
--
if you want others to be happy, practice compassion.
if you want to be happy, practice compassion. -- the dalai lama

Edwin Fine wrote:

If anything, I'd just want an optional way (besides .freeze) to control what can and can't be extended at run-time, to prevent accidental, ill-advised, or even malicious tampering, or to help identify it). Hey, maybe there's a way to do it already?

Unfortunately, Ruby's killer app makes use of pretty much every one of these hacks -- and rake freeze:edge throws its source code right in your own directory tree. What's more, development mode is constantly meta-mucking at every http request. How's a poor interpreter to know what's trusted and what's not?

(Or: what Pat said.)

Devin

>I believe I remember that "1 / 2" used to return "Rational(1, 2)" with >'rational' loaded. Is my memory wrong here?

Perhaps, you've confused 'rational' and 'mathn'.

Exactly!

>> 1 / 2
=> 0
>> require 'mathn'
=> true
>> 1 / 2
=> 1/2
>> (1 / 2).class
=> Rational

I just notice a strange inconsistency:

>> 12:25:18 [~]: irbs
>> require 'rational'
=> true
>> 1.to_r / 2
=> Rational(1, 2)
>> require 'mathn'
=> true
>> 1 / 2
=> 1/2
>> 1.to_r / 2
=> 1/2

The output of Rational's inspect method seems to change depending on whether "rational" or "mathn" is required.

Thank you, Matz!

  robert

···

On 05.12.2006 10:03, Yukihiro Matsumoto wrote:

In message "Re: Question about Ruby philosophy" > on Tue, 5 Dec 2006 17:20:10 +0900, Robert Klemme <shortcutter@googlemail.com> writes:

Aha! I was making the same mistake.

martin

···

On 12/5/06, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

Hi,

In message "Re: Question about Ruby philosophy" > on Tue, 5 Dec 2006 17:20:10 +0900, Robert Klemme <shortcutter@googlemail.com> writes:

>I believe I remember that "1 / 2" used to return "Rational(1, 2)" with
>'rational' loaded. Is my memory wrong here?

Perhaps, you've confused 'rational' and 'mathn'.

Years ago I posted this, to overwhelming silence:

You shoot yourself in the foot and make a really quick, clean job of
it because the gun didn't get in the way.

You try to shoot yourself in the foot but miss because you chose the
wrong type of bullet. It's less hassle than checking the bullet when
you load the gun.

You shoot yourself in the foot with a string of multi-part bullets.
This method is really popular in Japan.

Shoot yourself in the foot. Don't worry how big the indentation is,
it doesn't matter. Not like some guns we could mention.

Load the gun with anything you like and shoot yourself in the foot.
Everything's a bullet, you see.

···

On 2006-12-05, Edwin Fine <efine145-nospam01@usa.net> wrote:

How about a Ruby Quiz for the funniest way to shoot yourself in the
foot with Ruby?

What is a REPL?

···

On 2006-12-08, David Vallner <david@vallner.net> wrote:

Christian Neukirchen wrote:

Do you consider Ruby a good language for teaching people that haven't
programmed yet? Just wondering.
=20

I personally consider teaching programming in any language without a
REPL as Cruel and Unusual (tm) torture. Compiler-wrestling is a skill of

Jeremy Henty wrote:

How about a Ruby Quiz for the funniest way to shoot yourself in the
foot with Ruby?

Years ago I posted this, to overwhelming silence:

Thanks for responding - this time there's a bit of noise at least!
Let me try one.

class Myself
  def shoot_in_foot
    foot = Foot.new(:side => :right)
    hand = Hand.new(:side => :right)
    gun = Gun.new(:make => "Freedom Arms",
                  :type => :revolver, :action => :single,
                  :caliber => ".454 Casull Magnum")
    hand.grasp(gun)
    hand.grasped_object do |gun|
      gun.load
      gun.cock
      gun.aim(:at => foot)
      gun.pull_trigger # => "Bang!"
    end
    hand.drop_object # => Thump!
    self.scream
    foot.inspect
  end
  def scream
    "Arghhhhhhhhhhhhhhhhhhhhhhhh!!!!"
  end
end

myself = Myself.new # I feel like a new man!
myself.shoot_in_foot

=> "Bang!"
=> "Thump!"
=> "Arghhhhhhhhhhhhhhhhhhhhhhhh!!!!"
=> NameError: undefined local variable or method `foot' for
#<Myself:0xb7573ee4>
# Oops, blew it clean off!

···

On 2006-12-05, Edwin Fine <efine145-nospam01@usa.net> wrote:

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

Jim Cochrane wrote:

···

On 2006-12-08, David Vallner <david@vallner.net> wrote:

Christian Neukirchen wrote:

Do you consider Ruby a good language for teaching people that haven't
programmed yet? Just wondering.
=20

I personally consider teaching programming in any language without a
REPL as Cruel and Unusual (tm) torture. Compiler-wrestling is a skill of

What is a REPL?

Read-eval-print-loop. For example, irb.

David Vallner

The short tale of a ruby warrior:

self.shoot(foot) and yield

martin

···

On 12/7/06, Edwin Fine <efine145-nospam01@usa.net> wrote:

Jeremy Henty wrote:
> On 2006-12-05, Edwin Fine <efine145-nospam01@usa.net> wrote:
>
>> How about a Ruby Quiz for the funniest way to shoot yourself in the
>> foot with Ruby?
>
> Years ago I posted this, to overwhelming silence:
>
Thanks for responding - this time there's a bit of noise at least!
Let me try one.

#!/bin/ruby -w

me = File.read( __FILE__)
open( __FILE__, 'w') do |f|
   f.syswrite( me.sub( /ruby -w/, 'sh'))
end

Although this works fairly well too...

#!/bin/ruby -w

me = File.read( __FILE__)
open( __FILE__, 'w') do |f|
   f.syswrite( me.sub( /-w/, 'sh'))
end

John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand

···

On Thu, 7 Dec 2006, Edwin Fine wrote:

Jeremy Henty wrote:

On 2006-12-05, Edwin Fine <efine145-nospam01@usa.net> wrote:

How about a Ruby Quiz for the funniest way to shoot yourself in the
foot with Ruby?

Thanks!

···

On 2006-12-08, David Vallner <david@vallner.net> wrote:

...
Jim Cochrane wrote:

On 2006-12-08, David Vallner <david@vallner.net> wrote:

Christian Neukirchen wrote:

Do you consider Ruby a good language for teaching people that haven't=

programmed yet? Just wondering.
=3D20

I personally consider teaching programming in any language without a
REPL as Cruel and Unusual (tm) torture. Compiler-wrestling is a skill =

of

=20
What is a REPL?
=20

Read-eval-print-loop. For example, irb.

Thats cute.

How about this?
Object.constants.each do |x| eval( "#{x} = nil" ) end

Seems to shoot irb in the foot, for various values of foot, like head.

(:,
-Harold

···

On 12/7/06, John Carter <john.carter@tait.co.nz> wrote:

On Thu, 7 Dec 2006, Edwin Fine wrote:

> Jeremy Henty wrote:
>> On 2006-12-05, Edwin Fine <efine145-nospam01@usa.net> wrote:
>>
>>> How about a Ruby Quiz for the funniest way to shoot yourself in the
>>> foot with Ruby?

#!/bin/ruby -w

me = File.read( __FILE__)
open( __FILE__, 'w') do |f|
   f.syswrite( me.sub( /ruby -w/, 'sh'))
end

Although this works fairly well too...

#!/bin/ruby -w

me = File.read( __FILE__)
open( __FILE__, 'w') do |f|
   f.syswrite( me.sub( /-w/, 'sh'))
end

eval? please!

Object.constants.each do |c| Object.send :remove_const, c end

···

On Dec 6, 2006, at 18:11 , Harold Hausman wrote:

On 12/7/06, John Carter <john.carter@tait.co.nz> wrote:

On Thu, 7 Dec 2006, Edwin Fine wrote:

> Jeremy Henty wrote:
>> On 2006-12-05, Edwin Fine <efine145-nospam01@usa.net> wrote:
>>
>>> How about a Ruby Quiz for the funniest way to shoot yourself in the
>>> foot with Ruby?

#!/bin/ruby -w

me = File.read( __FILE__)
open( __FILE__, 'w') do |f|
   f.syswrite( me.sub( /ruby -w/, 'sh'))
end

Although this works fairly well too...

#!/bin/ruby -w

me = File.read( __FILE__)
open( __FILE__, 'w') do |f|
   f.syswrite( me.sub( /-w/, 'sh'))
end

Thats cute.

How about this?
Object.constants.each do |x| eval( "#{x} = nil" ) end

Seems to shoot irb in the foot, for various values of foot, like head.

--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net

I LIT YOUR GEM ON FIRE!