Question about Ruby philosophy

R

Robert Klemme

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

I was surprised myself, too:

irb(main):001:0> 1 / 2
=> 0
irb(main):002:0> 1.quo 2
=> 0.5
irb(main):003:0> require 'rational'
=> true
irb(main):004:0> 1 / 2
=> 0
irb(main):005:0> 1.quo 2
=> Rational(1, 2)
irb(main):006:0> RUBY_VERSION
=> "1.8.5"

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

Kind regards

robert
 
R

Robert Klemme

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?

I guess so.
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.

Actually there are two significant differences between this and modified
Ruby core classes: C is compiled and CPP macros are gone by the time the
error shows up (it may be that modern C/C++ compilers take care of this
when compiling debug code, dunno). You can more easily debug a Ruby lib
(provided it has no native parts) than a C lib where you might not have
the source code.

Also, I believe Ruby more easily encourages the use of unit tests and it
avoids a lot other errors (famous buffer overruns) which IMHO makes up
for the potential danger of core class modifications.
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.

Maybe a bit. But I think the community will take care of this.
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 think evolution will take care pretty well. :)

Kind regards

robert
 
M

Martin DeMello

Hi,

In message "Re: Question about Ruby philosophy"

|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'.

Aha! I was making the same mistake.

martin
 
J

Jeremy Henty

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:


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.
 
E

Edwin Fine

Jeremy said:
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.****
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!
 
M

Martin DeMello

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

The short tale of a ruby warrior:

self.shoot(foot) and yield

martin
 
J

John Carter

#!/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 : (e-mail address removed)
New Zealand
 
H

Harold Hausman

#!/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.

:),
-Harold
 
E

Eric Hodel

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.

eval? please!

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

x1

As close to being shot in the foot as I could get:

irb(main):008:0> puts ENV['OS']
Windows_NT
 
M

Max Muermann

As close to being shot in the foot as I could get:

irb(main):008:0> puts ENV['OS']
Windows_NT

That's missing your foot altogether and shooting yourself in the head instead...

max
 
M

M. Edward (Ed) Borasky

Paul said:
M. Edward (Ed) Borasky wrote:

/ ...



Gee, I hope the newbies don't try this just to see what happens. If they
"succeed", they might then try for the more concise, powerful form, which I
won't post an example of.
I'm just a curmudgeon. My example wasn't in Ruby, either. It's really an
example of how to shoot yourself in the foot *without* Ruby. :)
 
D

David Vallner

--------------enigEBC7AC7CC241807A9A80AD7F
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Max said:
As close to being shot in the foot as I could get:

irb(main):008:0> puts ENV['OS']
Windows_NT
=20
That's missing your foot altogether and shooting yourself in the head
instead...
=20

Muah.

(PS: Could have been MS Bob.)


--------------enigEBC7AC7CC241807A9A80AD7F
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD8DBQFFeaMKy6MhrS8astoRAlyGAJ4k/o2dtxHccRLOP1o5xdTGYjzLFACfVVRJ
2xsnQ1fh/GIWpwLuQf74b2g=
=SB78
-----END PGP SIGNATURE-----

--------------enigEBC7AC7CC241807A9A80AD7F--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top