Sharp knives and glue

On 5/6/06, Leslie V. [email protected] wrote:

The other thing is that a gem or library should not be loaded unless I
“require” it. This was the Glue problem. So unless I say “require”,
what is not listed in the “built in classes and modules” part of the
Ruby manual should not be part of my environment.

This is already the way it is done. No libraries are loaded until
required. Not even from the standard library. The only ones there
without an explicit require are the core libraries. (Standard library
only means that the library is always present, ready to be required,
without you needing to install anything – unless you’re on some older
flavors of debian/ubuntu).

If the library’s being loaded, it’s because someone is requiring it.
Obviously, in the case mentioned, it wasn’t the end user; not
directly, anyways. But some library the was included directly was
including Glue for them. Probably with some fancy logic that says,
“Well, if Glue’s not available, we can do it ourself, no need to make
them install it… but if Glue is available, let’s use it!” So the
application worked without Glue being installed, but as soon as Glue
was installed, it got required into the project automatically. Not
because Ruby sucked it in automatically, but because some other
library did.

Jacob F.

On 5/6/06, Jacob F. [email protected] wrote:

without you needing to install anything – unless you’re on some older
because Ruby sucked it in automatically, but because some other
library did.

I guess Rails did it. There’s this ticket:
http://dev.rubyonrails.org/ticket/2255
which may give a clue to the problem, but I don’t understand it.
I previously had the discussion about Glue and Rails here:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/164440

On Kubuntu I have Ruby 1.8.3 installed and if I print out $" I get
nothing,
indicating no “features” have been loaded. On windows, Ruby 1.8.4 and
the 1-click installer, I get 25 files, including a lot from rubygems,
forwardable.rb, time.rb, parsedate.rb, format.rb, rational.rb,
openssl.rb,
and fcntl.rb. Where did all that come from? How did those files get
loaded?

indicating no “features” have been loaded. On windows, Ruby 1.8.4 and
the 1-click installer, I get 25 files, including a lot from rubygems,
forwardable.rb, time.rb, parsedate.rb, format.rb, rational.rb, openssl.rb,
and fcntl.rb. Where did all that come from? How did those files get loaded?

hmm, I remember asking for ruby gems to be enabled when I installed. I
suppose it’s possible that ruby gems pulled in all 25 of those files?

On May 6, 2006, at 12:30 PM, Leslie V. wrote:

end

str points at, but not all Strings in the universe.

I’ve been thinking about this recently.

#curlify and friends aren’t really instance methods for strings, but
the functuality isn’t dramatically different enough to create a
subclass. What curlify really is, is a function that we want to be
able to call like str.curlify instead of curlify(str). Ruby already
has a mechanism for declaring ‘functions’, private methods on object.
Why not use that? You don’t even have to write it
def curlify(str)
“{#{str}}”
end

you can do this:

public
def curlify
“{#{self}}”
end

This has many advantages over monkeying about in other classes.

first, as a general rule people expect you to add methods to Object
(it’s how ruby does top level functions after all)

Secondly, it won’t kill any pre-existing definition of curlify. Any
other class that does it’s own curlify is going to override it, so
it’s safe from your meddling. Consider the case that curlify is added
to core, but does some thing else, some thing else useful to other
String methods, and is used in the new implementations of many of
them. You won’t have broken String since your curlify is higher in
the inheritance chain, the only thing that will have been broken is
your curlify, which will probably be easier to spot, since there’s a
good chance you wrote unit tests for your curlify (but probably not
for every method in the String class).

Now, I know it looks funny not having this method inside a class, but
it doesn’t realy belong in String anyway, and in pretty much any
other language you would have made it a function ( curlify(str) ) or
sub-classed String. It’s only because of ruby’s openn classes that
people get encouraged to change core classes to make life easier. I
figure
public
def meth(…)
end

is even easier, and less typing than

class SomeClass
def meth(…)
end
end

and it puts it in the same territory as top-level functions (e.g.
this is for this particular program’s convenience.)

Plus if you want to avoid namespace pollution just stick this
methods in a module and include the module

e.g.

module Curlify
def curlify
“{#{self}}”
end
end

include Curlify

On 5/6/06, Leslie V. [email protected] wrote:

indicating no “features” have been loaded. On windows, Ruby 1.8.4 and
the 1-click installer, I get 25 files, including a lot from rubygems,
forwardable.rb, time.rb, parsedate.rb, format.rb, rational.rb, openssl.rb,
and fcntl.rb. Where did all that come from? How did those files get loaded?

hmm, I remember asking for ruby gems to be enabled when I installed. I
suppose it’s possible that ruby gems pulled in all 25 of those files?

It’s very possible. I know from experience with other questions on
this list that requiring rubygems (e.g. the -rubygems switch on the
command line) will pull in rational.rb through a lengthy dependency
chain. I wouldn’t be surprised if those other libraries are all pulled
in by rubygems (several of them indirectly, same as rational.rb).

Jacob F.

Re-opening classes is one of the things that makes ruby great. We
frequently re-open classes on public libraries and frameworks to wrap
methods with our own methods to add in-house functionality while not
altering the core functioning of those libraries.

If you write your code you want to be unmodifiable in an interpreted
language you need your head examined. This isn’t at all ruby-like and
unless you lock out compiled extensions (bye bye native database
drivers, etc) then you can’t stop people circumventing any protection
mechanism you come up with either.

Why so precious? If you don’t want people to modify your code say so.
If they go ahead and it blows up it’s their fault. If you really did
write your secure important application you wished to be tamper-
resistant in ruby then you demanded to host it on your own secure
servers when you made the contract. If you didn’t, you should have.

Think about it…

include Curlify

Awesome! Problem easily solved, as usual.
I guess the only downside is that I can now “3.curlify”. But then I
can also curlify anything that behaves like a string, which is what
duck typing is all about.

On 5/11/06, rob [email protected] wrote:

Re-opening classes is one of the things that makes ruby great. [snip]

Why so precious? If you don’t want people to modify your code say so.
If they go ahead and it blows up it’s their fault.

Not to take any sides, but I think I’ve heard the argument go: if
you’re working on a team on a large project, and all of a sudden
“your” class breaks, management doesn’t want to hear about someone
else opening your class… they’ll just see your name on the class
causing the hold-up and then it becomes your problem.

In the typical “enterprise scale” cubicle farm environment, team
leaders are constantly looking to find someone to blame for the
project being behind. B&D languages like Java lend themselves to rigid
compartmentalization that yields paper trails.

It’s interesting to think about the dynamic there – between the
language and the cube farm.

Then they just need run ‘svn ann’ or equivalent for whatever RCS they
are using to clearly see which user created the the problem.

If employees constantly cause problems by doing this then tell them
to stop it. If they won’t then they’re bad employees.

I don’t think we should cripple a language because a couple of
companies may have shoddy management and bad communication.

The reason I’m strongly against this is that publicly available
libraries will may end up freezing their classes “to keep everything
standardized” which would cause us headaches, and in particular me
since I’d end up writing the circumvention mechanism.

A proper revision control system yields a grand paper trail. Leave
tracking of revisions and who-wrote-what to the proper service, the RCS.

None the less, it was enlightening to learn some people thought this.

On 5/11/06, Ryan L. [email protected] wrote:

if the unit tests for a class break, they won’t “blame” the original
author of that class, but whoever did the last submit.

Point well taken.

leaders on their crap.
Sorry. I’ve got a pretty small sample size and shouldn’t have written
“typical”.

It’s interesting to think about the dynamic there – between the
language and the cube farm.

What I hope we’ll see is all those “enterprise” companies and their
cube farms and Java code eaten alive by small, dynamic, happy teams of
Ruby coders who don’t have to deal with all that nonsense.

Agreed.

On 5/11/06, John G. [email protected] wrote:

Not to take any sides, but I think I’ve heard the argument go: if
you’re working on a team on a large project, and all of a sudden
“your” class breaks, management doesn’t want to hear about someone
else opening your class… they’ll just see your name on the class
causing the hold-up and then it becomes your problem.

Oh come on now, if that company is using Ruby they will be using unit
tests and I would hope, continuous integration and testing. Therefore
if the unit tests for a class break, they won’t “blame” the original
author of that class, but whoever did the last submit.

Even in any decent Java shop, the same would apply. It is absurd to
have such strict “code-ownership” to such a level that a random
breaking of a class gets blamed on the “owner” of that class.

In the typical “enterprise scale” cubicle farm environment, team
leaders are constantly looking to find someone to blame for the
project being behind. B&D languages like Java lend themselves to rigid
compartmentalization that yields paper trails.

Only bad team leaders or managers pull crap like that, and unless the
whole company is rotten with bad management (which means it probably
wouldn’t last long), at some point someone is going to call those team
leaders on their crap.

It’s interesting to think about the dynamic there – between the
language and the cube farm.

What I hope we’ll see is all those “enterprise” companies and their
cube farms and Java code eaten alive by small, dynamic, happy teams of
Ruby coders who don’t have to deal with all that nonsense.

Ryan

What I hope we’ll see is all those “enterprise” companies and their
cube farms and Java code eaten alive by small, dynamic, happy teams of
Ruby coders who don’t have to deal with all that nonsense.

+1 for the most part.

I don’t think it necessarily needs to be language specific, but that
the juggernaut should give way to more agile and sensible approaches.

good points though.