RFC - One word alias for require_relative

On 12 juin 2011, at 20:50, Ilias L. wrote:

include ‘lib/alter’ # the commonly known “include”
require ‘alibrary’

You do know that ‘include’ is already used in Ruby. Right?

Right?!??

On Sunday, June 12, 2011 04:59:57 AM Josh C. wrote:

What if, instead of having CWD in the load path, we had
File.dirname(__FILE__)? Essentially, CWD of the file that the require
statement is originated through.

Close, but no. When I call ‘require’ in, say, lib/foo/bar.rb, I want
“require
‘foo/baz’” to work, but “require ‘baz’” should not, and it especially
should
not have lib/foo/baz.rb mask lib/baz.rb.

So, if this is going to be a default, I’d much rather it apply to the
original
file only – that is, the file in which Ilias’ Kernel#executed? (or
whatever)
returns true.

Then again, how many points of entry does a typical application have? I
think
the worst-case structure might be something like:

bin/
bunch of scripts
lib/
bunch of library stuff that should be in the load path

Worst case, I might put an init.rb or something in the project root, so
that
each script starts off with:

require_relative ‘…/init’

Then, init.rb includes something like this:

$: << File.join(File.dirname(FILE), ‘lib’)

Ugly, but it’s only in one place. Or, if you’re likely to deal with
enough
other pathnames to make it worthwhile:

require ‘pathname’
$: << Pathname(FILE).parent.join(‘lib’)

Slightly prettier, and FILE is contained to one place inside your
project.
I don’t like it either, but it just doesn’t seem that critical to me.

Then the old interface would work again,
it would be simpler to think about, security risks of CWD in the load path
would be addressed, and most importantly, I could write beautiful code
again (I die a little bit inside each time I write FILE).

I tend to agree that it reduces the security risks. I can see myself
putting a
Ruby script in my PATH and running it as a command in an unsafe
directory. I
can’t often see a case where CWD in the path would be more useful than
the
root of the project. I really can’t see a case where I would drop a Ruby
script in an unsafe directory and then execute it – it seems like if
the
directory is unsafe, no attempt to make the script safe is going to get
me
anywhere.

Still, as I said, it doesn’t seem that critical to me. It seems like
require_relative, Pathname, and FILE all do the trick.

Of course, I have no idea if it’s even possible, and it’s not immediately
clear to me how it would affect gems.

I’m not sure how it would affect them, but it seems like gems would need
this
even less. With a gem, your $: is pretty much set up for you, so long as
you
follow the conventions about putting scripts in bin and libraries in
lib.

So it’s again something that doesn’t seem to matter much – how many
applications do we have, in comparison to gems?

On 12 , 22:18, Luc H. [email protected] wrote:

On 12 juin 2011, at 20:50, Ilias L. wrote:

include ‘lib/alter’ # the commonly known “include”
require ‘alibrary’

You do know that ‘include’ is already used in Ruby. Right?

Right?!??

yes, to describe “mixing”

I realize that this would lead to confusion (or even collisions).

Any other word?

.

On Jun 15, 2011, at 3:10 PM, Ilias L. wrote:

No.

require_relative ‘lib/alter’
require File.join(File.dirname(FILE), ‘lib/alter’)

those two are the same.

Michael E.
[email protected]
http://carboni.ca/

On 11 , 20:35, Ilias L. [email protected] wrote:

Which name would you select and for what reasons?

Requirements
must:

  • one word

optional:

  • ideally a 7 letter word

require_relative ‘lib/alter’
require ‘./lib/alter’

To my understanding, both should do the same thing.

Is this right?

.

On 15 , 22:26, Florian G. [email protected] wrote:

On Jun 15, 2011, at 9:10 PM, Ilias L. wrote:

require_relative ‘lib/alter’
require ‘./lib/alter’

To my understanding, both should do the same thing.

Is this right?

No, the first is relative to the file, the second is relative to “Dir.pwd”, the
process working directory.

I understand.

Thus the first works for the main file, and for included files which
can use again require_relative.

The second works only for the main file (usually executed from it’s
location).

So it looks I can’t drop require_relative.

And so I still need a shorter name.

.

On Jun 15, 2011, at 3:55 PM, Ilias L. wrote:

And so I still need a shorter name.

If you need a shorter name for some absurd reason, then you can
simply do the
following:

module Kernel
alias locally require_relative
end

Where “locally” can be any name you wish!

Problem solved!

Michael E.
[email protected]
http://carboni.ca

Afternoon,

On Wed, Jun 15, 2011 at 12:58 PM, Michael E. [email protected]
wrote:

On Jun 15, 2011, at 3:55 PM, Ilias L. wrote:

And so I still need a shorter name.

If you need a shorter name for some absurd reason, then you can simply
do the
following:

Michael, you clearly didn’t read the first message here… Ilias
wouldn’t
ever need something this absurd - it’s a “project manager” that needs
this
alias.

Why would you ever think Ilias would need something foolish? Are you
aware
of any past history that the rest of us are not?

John

On Jun 15, 2011, at 9:10 PM, Ilias L. wrote:

require_relative ‘lib/alter’
require ‘./lib/alter’

To my understanding, both should do the same thing.

Is this right?

No, the first is relative to the file, the second is relative to
“Dir.pwd”, the process working directory.

Regards,
Florian

On Jun 15, 2011, at 4:17 PM, John W Higgins wrote:

Michael, you clearly didn’t read the first message here… Ilias wouldn’t
ever need something this absurd - it’s a “project manager” that needs this
alias.

Why would you ever think Ilias would need something foolish? Are you aware
of any past history that the rest of us are not?

While I guess I deserve a (honestly delightfully) sarcastic reply for
responding to
him, I was mainly picking on how he slipped up and said “I still need a
shorter name.”

Michael E.
[email protected]
http://carboni.ca/

On Wednesday, June 15, 2011 02:55:31 PM Ilias L. wrote:

“Dir.pwd”, the process working directory.

I understand.

Thus the first works for the main file, and for included files which
can use again require_relative.

The second works only for the main file (usually executed from it’s
location).

Not really, no.

More like, the first works wherever I’d normally be hacking around with
FILE to get a decent require path.

The second doesn’t work at all, unless it’s actually what you intend.
For
instance, if I add a ruby script to my PATH as a command, and then run
it,
what directory I happen to be in when I run it is what determines what
the
second is relative to.

Even on Windows, the working directory isn’t always where the main file
is.

On 15 , 22:58, Michael E. [email protected] wrote:

On Jun 15, 2011, at 3:55 PM, Ilias L. wrote:

And so I still need a shorter name.

If you need a shorter name for some absurd reason,

If something is absurd, than it’s the fact that the name

“require_relative”

has made it into the core. For sure this was kind of an accident,
because everyone was busy or tired or something else.

Either it should be corrected soon to be a keyword.

or at least, if multi-word, then it should be written more clearly:

“require_relative_to_this_file”

There are many ways to ruin a language.

Step by step, silently.

then you can simply do the following:

module Kernel
alias locally require_relative
end

I am aware of this mechanism.

Where “locally” can be any name you wish!

But still, I need a concise name.

Problem solved!

.

On Wednesday, June 15, 2011 04:15:29 PM Ilias L. wrote:

has made it into the core. For sure this was kind of an accident,
because everyone was busy or tired or something else.

Of course, because the only reason anyone would ever disagree with you
is
because they’re busy, tired, stupid, or the wrong “kind” of person.

Either it should be corrected soon to be a keyword.

It’s not a keyword, it’s a method. It’s also far from the only two-word
method
– consider define_method or instance_variable_set.

or at least, if multi-word, then it should be written more clearly:

“require_relative_to_this_file”

At a certain point, you have to assume that if it isn’t obvious from the
context what something does, people are willing to look it up. ‘locally’
isn’t
any better in this regard – in fact, it’s significantly worse, since at
least
we know what ‘require’ usually means.

The alternative is Java-like madness, where define_method is actually
define_method_on_this_class_with_this_block_I_pass_in_here.

There are many ways to ruin a language.

Dramatic much?

require_relative couldn’t ruin a language – it barely even touches the
language, and can trivially be renamed or removed at runtime:

Kernel.send :remove_method, :require_relative

Oh, sorry, I guess that should be:

Kernel.send_method_call :remove_method_from_this_class
:require_relative

On 15 , 23:22, Michael E. [email protected] wrote:

him, I was mainly picking on how he slipped up and said “I still need a shorter
name.”
“I still need a shorter name” for the project-manager.

(I’m unemployed, the project-manager is a fictional one, just to have
a more realistic use-case)

.

On 16 Ιούν, 00:27, David M. [email protected] wrote:

Even on Windows, the working directory isn’t always where the main file is.
Yes, you’re right.

I forgot those cases.

What is sure for me now is:

I need the functionality that “require_relative” provides.

.

On 16 , 00:36, David M. [email protected] wrote:
[…]

I’ve read everything, but I’ll not comment.

Do me a favour, please.

Can you please try to find one word (ideally with 7 chars),
independent of you think about the need.

Just as an exercise.

I have too cook now!

.

http://lazaridis.com

On Thu, Jun 16, 2011 at 06:36:59AM +0900, David M. wrote:

It’s not a keyword, it’s a method. It’s also far from the only two-word
method – consider define_method or instance_variable_set.

. . . or method_missing.

I’m not sure what you hope to gain by responding to the assertion by
Ilias that a multi-word method is necessarily bad if it is not a
complete
sentence.

On 15/06/2011 22:30, Ilias L. wrote:

I’m unemployed

How very suprising, given your invaluable work “auditing” many
languages.

On Thu, Jun 16, 2011 at 12:05 AM, John W Higgins [email protected]
wrote:

Too easy, simply too easy…

John

Well, Ilias’ grasp of the English language isn’t the best, so he
probably meant “I’m not employed by a company, but am self-employed”.

And now I have to shower…


Phillip G.

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
– Leibnitz

2011/6/15 Ilias L. [email protected]:

or at least, if multi-word, then it should be written more clearly:

“require_relative_to_this_file”

There are many ways to ruin a language.

Step by step, silently.

I can only assume that these two pairs of lines being next to each
other is a joke.