Fighting Ruby's bad fame

can you elaborate? Ruby has namespaces defined by modules.

Yes, but not good enough.
Compared to Perl or Python, include is missing the ability of Perl’s use or
Python’s import command to just bring only certain parts of the module into the
current namespace.
In perl, you can do:
use Module (:func1 :func2);
and in python:
from Module import :func1, :func2

And only those two functions/classes/variables get imported into the current
namespace. Ruby’s include seems to be an all or nothing proposition,
unfortunately.

As far as modifying builtin classes goes, we’re hearing a lot in
this thread about how this is a problem. Personally, I don’t see it as
long as you’re not redefining predefined methods

Correct. I do see this as a benefit of ruby, too, but not without some form of
leash in the language to have the ability to keep the addition/modification
local or under the programmer’s control.
I’ve been using ruby for about 1 week & 1/2 and already run into that. I
created String#expand_tabs() function in a module of mine only to find a
similar (but less efficient implementation) of that function in another popular
ruby library. Freezing the class is no use as I WANT to be able to do that for
my own class.
This to me already points out the huge issue of name clashes. In this case, it
is not biggie as both functions do the same, but… it already sent shivers
down my spine.
While you can do such things in perl or python, too; those things are usually
discouraged while in the ruby way, they are not. And as I mentioned before,
the include’s of the other languages are better than ruby’s as the coder can
load the modifications selectively, too.
Personally I like this phisolophy of ruby, but I NEED to have the ability to
easily keep changes to base classes local to my class or in an easy way to
revert them.
Otherwise, it IS a deal breaker.

Perhaps, but I’ve written lots of cross-platform scripts. How hard is it
to do:

case PLATFORM
when /win/
#do Windows things
when /nix/
#do Unix things
else
#whatever
end

Well, that’s the issue isn’t it? What is #whatever?
Quick! Can you tell me how do I get the terminal’s screen size in all these
platforms: win32, dos, linux, HP, sun, irix, ming32, cygwin, osx, mac9?
You know? Great! Now, can you tell me how ruby defines PLATFORM on each OS,
as I don’t have each of those machines handy?
Now, better yet, can you tell me how can I distinguish the OS name and version
in ruby, since PLATFORM does not tell me that?
Those are the things missing from libraries and having at least ONE library
where all possible alternatives are listed would be nice.
In the case of perl, this is handled more or less as bad as ruby, but there are
a bunch of libraries that have been tested along the years that have a huge
list of these possibilities for you to learn from.
In the case of python, PLATFORM is much more simplified, as os.name can be only
one of ‘posix’, ‘nt’, ‘dos’, ‘os2’, ‘mac’, ‘ce’ or ‘riscos’. No surprises
there and no need for any regex’es. Nothing weird like “i386-win32”.

This works in vim. I’m not an emacs user, but if they could get it
working with a vim script, I’m sure it can be done in emacs lisp.

Yes, I’ll take a look at writting an emacs macro for this. But still,
refactoring tools would be much more useful.

SWIG and Ruby

Yes, been playing with swig1.3. Like it a lot, but it is missing some needed
stuff for ruby.
For example, ALL #define constants are translated to ruby. Even those that are
invalid ruby constants like those starting with underscores (and there does not
seem to be a way to ignore those, as with methods).
There seems no way to have swig automatically expose protected methods, which
is quite needed.
There is no %rubycode available like the %pythoncode directive in python mode
to create additional .rb code files.
And I’m not sure mixin’s really can deal with multiple inheritance 100%
properly. Sure, methods are easy. I am concerned more about dealing with
variables (both class and instance), thou, as from my quick glance at it,
modules seem to be somewhat limited in this aspect.

hi lothar,

I don’t think that the freedom you get with the syntax (and some
semantic) in ruby is really a plus for application development.

but yet, it quite obviously is a plus.

if you are annoyed with the freedom you just
lack the ability to control your coding style.

And i completely disagree with Matz that programming languages and natural
languages have something in common.

We need strict languages and redirect the programmers creativity to
the design phase not the implementation hacks.

ruby is flexible enough to provide much more of this so called “strictness”.

in any case. mostly the need for “strictness” is just a way of making up for a
lack of good api’s, api documentation, and thorough system wide tests.

mvg,
Alex

···

On Friday 16 January 2004 20:13, Lothar Scholz wrote:


From Sharp minds come… pointed heads.
– Bryan Sparrowhawk

Quoteing tibbetts@acm.org, on Sat, Jan 17, 2004 at 05:38:27AM +0900:

Quoting gabriele renzi <surrender_it@rc1.vip.ukl.yahoo.com>:
As for wider adoption, I'd like to find a Ruby-to-GUI binding not just for Tk,
but for gtk, MFC, or (the holy grail) Aqua on OS X.

Doesn't ruby/cocoa "bind" to Aqua? Or at least use the same obj-c apis
that Aqua apps are using?

Sam

Hello gabriele,

Friday, January 16, 2004, 9:35:05 PM, you wrote:

please forgive me, I'm dumb.
What's wrong with adding features to base classes?
Possibly the problem is ovverriding methods, I suppose,
but you'll get a warning for that..

It's simply the danger of a namespace clash. At least if short and
simple names are used as i have seen as a suggestion in a ruby book.

At least library developer should avoid this as hell.

···

--
Best regards,
Lothar mailto:mailinglists@scriptolutions.com

— Phil Tomson ptkwt@aracnet.com wrote:

TCL/TK gets used a lot in the EDA (Electronic Design Automation)
industry.
It’s a postitively awful language, yet there are some fairly good sized
GUIs written with it.

Oh, what is wrong with it? Certainly, I think it is nice fast means of
generating a GUI. If you’re that unhappy with it, try looking at the
bindings to fltk.

If TCL can be used for such things, surely Ruby can be with great
improvements in productivity, OOness, even speed (TCL is very slow).

It’s only slow if you try writing an implementation of say “mozilla”.

– Thomas Adam

···

=====
“The Linux Weekend Mechanic” – http://linuxgazette.net
“TAG Editor” – http://linuxgazette.net

“ We’ll just save up your sins, Thomas, and punish
you for all of them at once when you get better. The
experience will probably kill you. :)”

– Benjamin A. Okopnik (Linux Gazette Technical Editor)


Yahoo! Messenger - Communicate instantly…“Ping”
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html

As for wider adoption, I’d like to find a Ruby-to-GUI binding not just for Tk,
but for gtk,

ruby-gnome2.sourceforge.jp, wonderful Gtk bindings

MFC,
I suppose Swin/vruby is what you may like

or (the holy grail) Aqua on OS X.
I think there are cocoa and carbon bindings. just not tried :wink:

···

il Sat, 17 Jan 2004 05:38:27 +0900, jason r tibbetts tibbetts@acm.org ha scritto::

In article 20040118210240.21921.00000154@mb-m22.aol.com,

can you elaborate? Ruby has namespaces defined by modules.

Yes, but not good enough.
Compared to Perl or Python, include is missing the ability of Perl’s use or
Python’s import command to just bring only certain parts of the module into the
current namespace.
In perl, you can do:
use Module (:func1 :func2);

You can do this. Remembering back to my Perl days (a distant, fading
memory), I never did this. It was always just ‘use Module’. (but that’s
not to say that being able to limit which functions are brought in isn’t
useful and often warrented).

and in python:
from Module import :func1, :func2

And only those two functions/classes/variables get imported into the current
namespace. Ruby’s include seems to be an all or nothing proposition,
unfortunately.

Perhaps this warrants an RCR. Right now, Matz is very open to RCR’s
and he’s asking for a lot of them to be submitted for Ruby 2.
http://rcrchive.net/

Perhaps there could be optional arguments to require and include so that
methods can be listed (as you show above):

require “foo”, :func1, :func2

include Foo, :func1, :func2

It’s probably possible to do something like this now, I’d have to play
with it a bit to see what I can come up with.

As far as modifying builtin classes goes, we’re hearing a lot in
this thread about how this is a problem. Personally, I don’t see it as
long as you’re not redefining predefined methods

Correct. I do see this as a benefit of ruby, too, but not without some form of
leash in the language to have the ability to keep the addition/modification
local or under the programmer’s control.
I’ve been using ruby for about 1 week & 1/2 and already run into that. I
created String#expand_tabs() function in a module of mine only to find a
similar (but less efficient implementation) of that function in another popular
ruby library. Freezing the class is no use as I WANT to be able to do that for
my own class.
This to me already points out the huge issue of name clashes. In this case, it
is not biggie as both functions do the same, but… it already sent shivers
down my spine.
While you can do such things in perl or python, too; those things are usually
discouraged while in the ruby way, they are not. And as I mentioned before,
the include’s of the other languages are better than ruby’s as the coder can
load the modifications selectively, too.
Personally I like this phisolophy of ruby, but I NEED to have the ability to
easily keep changes to base classes local to my class or in an easy way to
revert them.

This is kind of what David Black’s Ruby behaviors does.
http://uweb.superlink.net/~dblack/ruby/behaviors/

Perhaps, but I’ve written lots of cross-platform scripts. How hard is it
to do:

case PLATFORM
when /win/
#do Windows things
when /nix/
#do Unix things
else
#whatever
end

Well, that’s the issue isn’t it? What is #whatever?

Whatever is whatever else you think your script might run on. Practically
speaking, you mainly need to cover: Windows, MacOSX, Linux and *BSD.

Now, better yet, can you tell me how can I distinguish the OS name and version
in ruby, since PLATFORM does not tell me that?
Those are the things missing from libraries and having at least ONE library
where all possible alternatives are listed would be nice.
In the case of perl, this is handled more or less as bad as ruby, but there are
a bunch of libraries that have been tested along the years that have a huge
list of these possibilities for you to learn from.
In the case of python, PLATFORM is much more simplified, as os.name can be only
one of ‘posix’, ‘nt’, ‘dos’, ‘os2’, ‘mac’, ‘ce’ or ‘riscos’. No surprises
there and no need for any regex’es. Nothing weird like “i386-win32”.

But what if new OS’s are developed? And how do I distinguish between OSX
and OS9 if all I get is ‘mac’? Do they have an os.version as well?
Given that OS9 and OSX are such different beasts, I don’t want them lumped
together.

PLATFORM is set at compile time in Ruby (as in compile time of the Ruby
sources). I suppose it would be nice if there were some way to actually
query the OS in such a way as to determine the OS name and version.
(perhaps another RCR is in order). How does Python setup the os
datastructure?

This works in vim. I’m not an emacs user, but if they could get it
working with a vim script, I’m sure it can be done in emacs lisp.

Yes, I’ll take a look at writting an emacs macro for this. But still,
refactoring tools would be much more useful.

Sure, but as you say Python and Perl don’t have those sorts of tools
either. I guess this is one place where static typing make it easier for
the editor: it provides some idea about types of variables for
refactoring. But consider: Refactoring is already a lot easier in
dynamically typed languages like Ruby (or Python or Perl). The FreeRIDE
folks are planning some support for refactoring ASAIK.

SWIG and Ruby

Yes, been playing with swig1.3. Like it a lot, but it is missing some needed
stuff for ruby.
For example, ALL #define constants are translated to ruby. Even those that are
invalid ruby constants like those starting with underscores (and there does not
seem to be a way to ignore those, as with methods).

I wonder how hard this would be to fix.

There seems no way to have swig automatically expose protected methods, which
is quite needed.
There is no %rubycode available like the %pythoncode directive in python mode
to create additional .rb code files.
And I’m not sure mixin’s really can deal with multiple inheritance 100%
properly. Sure, methods are easy. I am concerned more about dealing with
variables (both class and instance), thou, as from my quick glance at it,
modules seem to be somewhat limited in this aspect.

Definately some limitations to this method of emulating MI. I’m not sure
these differences can ever be completely bridged. Ruby supports single
inheritance with mixins, whereas C++ supports multiple inheritance with
all of the associated problems that come with it. Swig makes a good
attempt to bridge the gap, but of course there will never be a perfect
bridge between the two.

Phil

···

GGarramuno ggarramuno@aol.com wrote:

I’ve been using ruby for about 1 week & 1/2 and already run into that. I
created String#expand_tabs() function in a module of mine only to find a
similar (but less efficient implementation) of that function in another popular
ruby library.

Could you send me the efficient implementation? :slight_smile:

This to me already points out the huge issue of name clashes. In this case, it
is not biggie as both functions do the same, but… it already sent shivers
down my spine.

You DO test code before deploying it into a critical productiohn
system, don’t you? What’s so bad about name clashes? You find them,
fix them, and move on. Same as any other kind of coding error. And,
short of clashing with a library whose explicit purpose is to extend
the built-in classes, I bet you don’t even find any name clashes. :slight_smile:

While you can do such things in perl or python, too; those things are usually
discouraged while in the ruby way, they are not.

Not true. Some people like them, some don’t. Good libraries take
care not to impinge on public namespaces unreasonably. Experimenting
with modified classes is quite encouraged in Ruby. Overdoing it is
not.

And as I mentioned before, the include’s of the other languages are
better than ruby’s as the coder can load the modifications
selectively, too.

I don’t like the sound of that “feature”. A well-designed library
should be loaded in full. In OO languages especially, you either load
a class or you don’t; you don’t pick and choose methods.

Larger libraries may have several classes in a module, which can be
selectively loaded by loading different files (require “foo/a”,
require “foo/b”).

Selective importing of pure module functions may have some benefit,
but still sounds pretty average.

Personally I like this phisolophy of ruby, but I NEED to have the ability to
easily keep changes to base classes local to my class or in an easy way to
revert them.

At the risk of re-igniting an old flamewar, no you don’t. Not until
you prove that you need it anyway. At the moment it’s mere paranoia.
No offense intended; we’ve all been there I’m sure.

I don’t rule out the possibility of you proving that you need the
feature. And I think that namespaces/behaviours would be nice. You
have certainly hit on a controversial Ruby feature, and interesting
discussion on it is always … well, interesting.

Otherwise, it IS a deal breaker.

Take responsibility for your own code, and scrutinise third party code
you use. Run RDoc on them and see if any built-in classes appear.
Use Ruby to prototype a solution and then ask what’s wrong with it.

Cheers,
Gavin

···

On Monday, January 19, 2004, 1:05:02 PM, GGarramuno wrote:

can you elaborate? Ruby has namespaces defined by modules.
Yes, but not good enough.

An opinion.

Compared to Perl or Python, include is missing the ability of
Perl’s use or Python’s import command to just bring only certain
parts of the module into the current namespace. In perl, you can
do:
use Module (:func1 :func2);
and in python:
from Module import :func1, :func2

I personally see no reason for this. I’ve never used this
so-called “feature” in Perl, and I don’t see the point of it,
either.

And only those two functions/classes/variables get imported into
the current namespace. Ruby’s include seems to be an all or
nothing proposition, unfortunately.

Why unfortunately? When you’re using many other languages, it’s also
an all-or-nothing proposition. If I’m using Delphi (Object Pascal),
I can’t select which methods I’m importing from a module. Same with
C, C++, Java, and C# (as far as I know).

-austin

···

On Mon, 19 Jan 2004 11:05:02 +0900, GGarramuno wrote:

austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2004.01.20
* 13.58.37

“It’s a language for smart wannabe (i.e people trying to be
smart).” - matz

:wink:

···

On Sun, Jan 18, 2004 at 11:40:02AM +0900, Dave Brown wrote:

: It’s simply the danger of a namespace clash. At least if short and
: simple names are used as i have seen as a suggestion in a ruby book.
:
: At least library developer should avoid this as hell.

Smart developers know when this kind of thing is appropriate and
when it isn’t. Ruby is a language for smart people, and one of
the facets of its design is letting the Ruby programmer make that
judgement call.


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Q: How does a Unix guru have sex?
A: unzip;strip;touch;finger;mount;fsck;more;yes;umount;sleep
– unknown source

Gavin Sinclair gsinclair@soyabean.com.au wrote in message news:33606556942.20040120002034@soyabean.com.au

I’ve been using ruby for about 1 week & 1/2 and already run into that. I
created String#expand_tabs() function in a module of mine only to find a
similar (but less efficient implementation) of that function in another popular
ruby library.

Could you send me the efficient implementation? :slight_smile:

Sure, here it is. This implementation will perform a tiny bit slower
on short documents that are mainly separated by a single tab, but it
should perform dramatically faster in longer documents, specially
those with multiple contiguous tabs (last test, being the most
pathologial one). Of course, the best thing would be to move these
methods from ruby onto C, if you ask me:

require “benchmark”

class String

Return new string with all tabs set to spaces

def new_expand_tabs(n=8)
n = n.to_int
raise ArgumentError, “n must be >= 0” if n < 0
return gsub(/\t/, ‘’) if n == 0
return gsub(/\t/, ’ ‘) if n == 1
h = self.dup
while h.gsub!(/^([^\t\n]*)(\t+)/) { |f|
val = ( n * $2.size - ($1.size % n) )
$1 << (’ ’ * val)
}
end
h
end

def old_expand_tabs(n=8)
n = n.to_int
raise ArgumentError, “n must be >= 0” if n < 0
return gsub(/\t/, “”) if n == 0
return gsub(/\t/, " “) if n == 1
str = self.dup
while str =~ /\t/
str.gsub!(/(^.*?)\t/) { |s|
# Our match starts at the beginning of a line, so we count the
# characters before the tab, and expand the tab to the next multiple
# of N spaces.
width = $1.size
gap = n - (width % n)
# Replace the tab with ‘gap’ spaces.
$1 + (” " * gap)
}
end
str
end

end

Dummy tests

n = 100000
s1 = “\t\t\t\t\t\tadssaa\t\t\t\t\t” * 1000
s2 = “\t\t\t\t\t\tadssaa\t\t\t\t\t\n\n\t\t\n” * n
s3 = “adssaa\t\t\t\t\t\nxxxxxxx\t\t\nyy\n” * n
s4 = “adssaa\t\t\t\t\txxxxxxx\n” * n
s5 = “\na\ta\t\a\ta\t\a\n” * n
s6 = “\na\tthis\t\is\ta\t\test\tof\thow\tgood\ttabulation\tis.\n” * n

t1 = ‘’
t3 = ‘’

Benchmark.bm { |x|
x.report("n ") { t3 = s2.new_expand_tabs(); }
x.report("o ") { t1 = s2.old_expand_tabs(); }
}

if ( t3 != t1 )
t3.gsub!(/\t/,‘-’)
t1.gsub!(/\t/,‘-’)
puts “new error!”,t3,“.”,t1
end

Benchmark.bm { |x|
x.report("n ") { t3 = s3.new_expand_tabs(); }
x.report("o ") { t1 = s3.old_expand_tabs(); }
}

puts “new error!” if ( t3 != t1 )

Benchmark.bm { |x|
x.report("n ") { t3 = s4.new_expand_tabs(); }
x.report("o ") { t1 = s4.old_expand_tabs(); }
}

puts “new error!” if ( t3 != t1 )

Benchmark.bm { |x|
x.report("n ") { t3 = s5.new_expand_tabs(); }
x.report("o ") { t1 = s5.old_expand_tabs(); }
}

puts “new error!” if ( t3 != t1 )

Benchmark.bm { |x|
x.report("n ") { t3 = s6.new_expand_tabs(); }
x.report("o ") { t1 = s6.old_expand_tabs(); }
}

puts “new error!” if ( t3 != t1 )

Benchmark.bm { |x|
x.report("n ") { t3 = s1.new_expand_tabs(); }
x.report("o ") { t1 = s1.old_expand_tabs(); }
}

puts “new error!” if ( t3 != t1 )

On my system:

  user     system      total        real

n 8.422000 0.080000 8.502000 ( 8.602000)
o 53.096000 0.420000 53.516000 ( 53.858000)
user system total real
n 4.807000 0.050000 4.857000 ( 4.887000)
o 20.560000 0.151000 20.711000 ( 20.830000)
user system total real
n 2.423000 0.050000 2.473000 ( 2.483000)
o 13.049000 0.080000 13.129000 ( 13.270000)
user system total real
n 9.293000 0.060000 9.353000 ( 9.403000)
o 9.324000 0.080000 9.404000 ( 9.434000)
user system total real
n 26.097000 0.250000 26.347000 ( 26.498000)
o 40.969000 0.391000 41.360000 ( 41.529000)
user system total real
n 14.721000 5.678000 20.399000 ( 20.570000)
o 228.529000 3.365000 231.894000 (235.588000)

What’s so bad about name clashes?

Nothing much. Just that it is something I wouldn’t be giving any
thought with python or perl, but that you tell me I may have to watch
out it for in ruby.

And,
short of clashing with a library whose explicit purpose is to extend
the built-in classes, I bet you don’t even find any name clashes. :slight_smile:

Not sure I agree. Do you know how many vector, matrix and so forth
libraries are out there? All of them more or less incompatible with
each other?

I don’t like the sound of that “feature”. A well-designed library
should be loaded in full. In OO languages especially, you either load
a class or you don’t; you don’t pick and choose methods.

Personally, I’m not too interested in choosing methods, but I am in
choosing classes.
Also, think of it negatively, as I do. What if the library you have
to use was not well designed? What if this is found out only in the
middle of the project? What if the person maintaining the library has
no time on their hands to fix it (or worse, refuses to change it for
some other reason)? Do I just hack into the library and start
maintaining my own incompatible version which I would then have to
keep updating every time a new update to the master library is
released?
Between being tied and just going on my own tangent, I’d rather take
the comprise of just picking and choosing what I want to use…
without hacking into the original code.
Will I’ll be using that feature often? Heck, I hope never! But I’ll
sleep well at nights knowing that if I ever HAVE to, that feature is
already there.

Personally I like this phisolophy of ruby, but I NEED to have the ability to
easily keep changes to base classes local to my class or in an easy way to
revert them.

At the risk of re-igniting an old flamewar, no you don’t. Not until
you prove that you need it anyway. At the moment it’s mere paranoia.

Paranoia is good in programming. Keeps you sane later on.
And this fear must be a plague, as searching for solutions in the ruby
world, I’ve seen at least 3 or 4 proposals trying to address this same
issue, including:

  • behaviors
  • matz’s namespaces
  • profile method visibility

That tells me that: a) it is a problem already or b) it is enough of a
potential future problem to merit a solution.

Personally, I prefer the namespaces approach, but any of them standard
in the language would likely be better than having none if you ask me.

···

On Monday, January 19, 2004, 1:05:02 PM, GGarramuno wrote:

Compared to Perl or Python, include is missing the ability of
Perl’s use or Python’s import command to just bring only certain
parts of the module into the current namespace. In perl, you can
do:
use Module (:func1 :func2);
and in python:
from Module import :func1, :func2

I personally see no reason for this. I’ve never used this
so-called “feature” in Perl, and I don’t see the point of it,
either.

i have to agree, use of this ‘feature’, i feel, is a sign of bad design.
If there is a need to be selective, then the module should surely be
split up, right? A module should constitute some logically related
methods or some such that should be treated as a single unit, namely a
module.
nikolai

···


::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux[“\021%six\012\0”],(linux)[“have”]+“fun”-97);}

I can’t select which methods I’m importing from a module. Same with
C, C++, Java, and C# (as far as I know).

I also thought of what you said and why it did not bother me as much in those.
Not sure about Java or C# as i have not used them.
I think the reason is two-fold. On those languages I don’t expect int, char*,
or the STL to have modifications, for one.
And also because C and C++ also have a more powerful way around pretty much any
conflict.
The existance of the pre-processor and the ability to define/undefine macros of
anything is your way around any issue of integrating two libraries with
elements that share the same signature, class, function or constant. Not
pretty at all nor would I recommend it, but functional if the need arises.

Why unfortunately? When you’re using many other languages, it’s also
an all-or-nothing proposition. If I’m using Delphi (Object Pascal),
I can’t select which methods I’m importing from a module. Same with
C, C++, Java, and C# (as far as I know).

-austin

Oh, yes, I forgot another reason why it does not bother me in C++.
The other benefit in C++ is that the ‘using’ construct can also be
local to a particular block.
That is, you can have something like:
void myfunc()
{
using namespace Mine;
// functions
}
without effecting the outer scope (ie. what’s outside the function).

In ruby, if you do:

def myfunc()
include Mine
end

Your outer scope will also get effected.

Hi,

···

In message “Re: Fighting Ruby’s bad fame” on 04/01/20, GGarramuno GGarramuno@aol.com writes:

And this fear must be a plague, as searching for solutions in the ruby
world, I’ve seen at least 3 or 4 proposals trying to address this same
issue, including:

  • behaviors
  • matz’s namespaces
  • profile method visibility

That tells me that: a) it is a problem already or b) it is enough of a
potential future problem to merit a solution.

Or c) it is a good puzzle for your brains. :wink: At least, my namespace
idea is originally not for the problem you’ve described.

						matz.

Gavin Sinclair gsinclair@soyabean.com.au wrote in message
news:33606556942.20040120002034@soyabean.com.au

I’ve been using ruby for about 1 week & 1/2 and already run into that. I
created String#expand_tabs() function in a module of mine only to find a
similar (but less efficient implementation) of that function in another popular
ruby library.

Could you send me the efficient implementation? :slight_smile:

Sure, here it is. […]

Thanks. That’ll make 0.3.

What’s so bad about name clashes?

Nothing much. Just that it is something I wouldn’t be giving any
thought with python or perl, but that you tell me I may have to watch
out it for in ruby.

That’s right: nothing much. And many of the things you have to watch
out for in P* are not an issue in R*. There’s no perfect language,
just different sets of compromises.

And,
short of clashing with a library whose explicit purpose is to extend
the built-in classes, I bet you don’t even find any name clashes. :slight_smile:

Not sure I agree. Do you know how many vector, matrix and so forth
libraries are out there? All of them more or less incompatible with
each other?

Even if that’s true, how many are you going to use at once?

I don’t like the sound of that “feature”. A well-designed library
should be loaded in full. In OO languages especially, you either load
a class or you don’t; you don’t pick and choose methods.

Personally, I’m not too interested in choosing methods, but I am in
choosing classes.
Also, think of it negatively, as I do.

I prefer to think positively when programming, and Ruby rewards that!

What if the library you have to use was not well designed? What if
this is found out only in the middle of the project? What if the
person maintaining the library has no time on their hands to fix it
(or worse, refuses to change it for some other reason)? Do I just
hack into the library and start maintaining my own incompatible
version which I would then have to keep updating every time a new
update to the master library is released?

An ugly situation, but that’s a LOT of what-ifs.

Between being tied and just going on my own tangent, I’d rather take
the comprise of just picking and choosing what I want to use…
without hacking into the original code.
Will I’ll be using that feature often? Heck, I hope never! But I’ll
sleep well at nights knowing that if I ever HAVE to, that feature is
already there.

Like I said before, since Ruby is missing a few features you look for
in an ultimate solution (especially in a particular domain), try it as
a prototyping solution. I’d be interested to see what problems you
hit and how you deal with them.

Personally I like this phisolophy of ruby, but I NEED to have the ability to
easily keep changes to base classes local to my class or in an easy way to
revert them.

At the risk of re-igniting an old flamewar, no you don’t. Not until
you prove that you need it anyway. At the moment it’s mere paranoia.

Paranoia is good in programming. Keeps you sane later on.
And this fear must be a plague, as searching for solutions in the ruby
world, I’ve seen at least 3 or 4 proposals trying to address this same
issue, including:

  • behaviors
  • matz’s namespaces
  • profile method visibility

That tells me that: a) it is a problem already or b) it is enough of a
potential future problem to merit a solution.

It tells you what you want to hear. Likewise for me :slight_smile:

[…]

Cheers,
Gavin

···

On Tuesday, January 20, 2004, 6:45:01 AM, GGarramuno wrote:

On Monday, January 19, 2004, 1:05:02 PM, GGarramuno wrote:

s/effect/affect/

That is a feature I would definitely like to see in Ruby (‘include’
having an effect local to the enclosing block, or whatever the
terminology should be). Must remember to raise an RCR.

Gavin

···

On Thursday, January 22, 2004, 8:29:58 AM, GGarramuno wrote:

Oh, yes, I forgot another reason why it does not bother me in C++.
The other benefit in C++ is that the ‘using’ construct can also be
local to a particular block.
That is, you can have something like:
void myfunc()
{
using namespace Mine;
// functions
}
without effecting the outer scope (ie. what’s outside the function).

In ruby, if you do:

def myfunc()
include Mine
end

Your outer scope will also get effected.

That is a feature I would definitely like to see in Ruby (‘include’
having an effect local to the enclosing block, or whatever the

Would the ‘new include’ work like the current one, i.e. using a proxy class
(so that the return value of Module#ancestors changes), or are you rather
thinking of a way to use singleton methods from another module/object?

That is, is the feature you’re thinking of only related to the namespace
in a scope or does it involve something more complex such as several
per-object namespaces?

terminology should be). Must remember to raise an RCR.

batsman@tux-chan:/tmp$ expand -t2 c.rb
require ‘test/unit’

scoped singleton method import

···

On Thu, Jan 22, 2004 at 10:04:51AM +0900, Gavin Sinclair wrote:

using(ModWithSingletons, someobject) do

blah # runs ModWithSingletons.blah or someobject.blah if it cannot be

# resolved with self

end

can be nested but is not thread-safe

def using(*modules)

this doesn’t propagate the block :frowning:

#klass = class << self; self end
#klass.module_eval{ alias_method :method_missing, :method_missing }
#klass.send(:define_method,:method_missing) do |meth,*args|

begin

method_missing meth, *args

rescue NameError

modules.each do |m|

return m.send(meth, *args) if m.respond_to? meth

end

raise

end

#end
@using_modules ||=
@level ||= 0
@level += 1
old = @using_modules
@using_modules = modules + @using_modules
if @level == 1
class << self
alias_method :method_missing, :method_missing
def method_missing(meth, *args, &block)
begin
method_missing meth, *args, &block
rescue NameError
@using_modules.each do |m|
return m.send(meth, *args, &block) if m.respond_to? meth
end
raise
end
end
end
end
begin
yield
ensure
@level -= 1
if @level == 0
class << self
alias_method :method_missing, :method_missing
end
end
@using_modules = old
end
end

class TC_using < Test::Unit::TestCase

module Blah; def self.foo; “Blah.foo” end end
module Foo; def self.foo; “Foo.foo” end end
module Bar
def self.bar; “Bar.bar” end
def self.baz; yield end
end

def test_single_module
assert_equal(“Foo.foo”, using(Foo){ foo })
assert_equal(“Blah.foo”, using(Blah){ foo })
end

def test_several_modules
assert_equal(“Foo.foo”, using(Foo,Blah){foo})
assert_equal(“Blah.foo”, using(Blah,Foo){foo})
end

def test_call_with_block
assert_equal(“Bar.baz”, using(Bar){baz{“Bar.baz”}})
end

def test_nested
assert_equal(“Blah.foo”, using(Foo){using(Blah){foo}})
using(Foo) do
assert_equal(“Blah.foo”, using(Blah){foo})
assert_equal(“Foo.foo”, foo)
end
end

def test_namerror
assert_raises(NameError) { using(Foo){ jurl } }
end
end

batsman@tux-chan:/tmp$ ruby c.rb
Loaded suite c
Started

Finished in 0.003045 seconds.

5 tests, 9 assertions, 0 failures, 0 errors


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Apples have meant trouble since eden.
– MaDsen Wikholm, mwikholm@at8.abo.fi

Mauricio Fernández batsman.geo@yahoo.com wrote in message news:20040122095123.GA18582@student.ei.uni-stuttgart.de

That is a feature I would definitely like to see in Ruby (‘include’
having an effect local to the enclosing block, or whatever the

Would the ‘new include’ work like the current one, i.e. using a proxy class
(so that the return value of Module#ancestors changes), or are you rather
thinking of a way to use singleton methods from another module/object?

That is, is the feature you’re thinking of only related to the namespace
in a scope or does it involve something more complex such as several
per-object namespaces?

terminology should be). Must remember to raise an RCR.

batsman@tux-chan:/tmp$ expand -t2 c.rb
require ‘test/unit’

scoped singleton method import

using(ModWithSingletons, someobject) do

blah # runs ModWithSingletons.blah or someobject.blah if it cannot be

# resolved with self

end

can be nested but is not thread-safe

def using(*modules)

this doesn’t propagate the block :frowning:

#klass = class << self; self end
#klass.module_eval{ alias_method :method_missing, :method_missing }
#klass.send(:define_method,:method_missing) do |meth,*args|

begin

method_missing meth, *args

rescue NameError

modules.each do |m|

return m.send(meth, *args) if m.respond_to? meth

end

raise

end

#end
@using_modules ||=
@level ||= 0
@level += 1
old = @using_modules
@using_modules = modules + @using_modules
if @level == 1
class << self
alias_method :method_missing, :method_missing
def method_missing(meth, *args, &block)
begin
method_missing meth, *args, &block
rescue NameError
@using_modules.each do |m|
return m.send(meth, *args, &block) if m.respond_to? meth
end
raise
end
end
end
end
begin
yield
ensure
@level -= 1
if @level == 0
class << self
alias_method :method_missing, :method_missing
end
end
@using_modules = old
end
end

class TC_using < Test::Unit::TestCase

module Blah; def self.foo; “Blah.foo” end end
module Foo; def self.foo; “Foo.foo” end end
module Bar
def self.bar; “Bar.bar” end
def self.baz; yield end
end

def test_single_module
assert_equal(“Foo.foo”, using(Foo){ foo })
assert_equal(“Blah.foo”, using(Blah){ foo })
end

def test_several_modules
assert_equal(“Foo.foo”, using(Foo,Blah){foo})
assert_equal(“Blah.foo”, using(Blah,Foo){foo})
end

def test_call_with_block
assert_equal(“Bar.baz”, using(Bar){baz{“Bar.baz”}})
end

def test_nested
assert_equal(“Blah.foo”, using(Foo){using(Blah){foo}})
using(Foo) do
assert_equal(“Blah.foo”, using(Blah){foo})
assert_equal(“Foo.foo”, foo)
end
end

def test_namerror
assert_raises(NameError) { using(Foo){ jurl } }
end
end

batsman@tux-chan:/tmp$ ruby c.rb
Loaded suite c
Started

Finished in 0.003045 seconds.

5 tests, 9 assertions, 0 failures, 0 errors

Cool. A good example of how just about any new feature that someone
thinks of can often be implemented in Ruby without requiring a change
to the language itself.

Oh, and I also thought it was about time to change the subject name on
this thread: I don’t think Ruby has ‘bad fame’ (as in “The Infamous
Ruby”). I find that those who have heard of Ruby usually have heard
good things about it and if they have heard negatives those
perceptions are often out of date.

Phil

···

On Thu, Jan 22, 2004 at 10:04:51AM +0900, Gavin Sinclair wrote: