[#383997] CORE - Alternative Variable Substitution — Ilias Lazaridis <ilias@...>

ruby 1.9

21 messages 2011/06/01

[#384051] CORE - Replace "if __FILE__ == $0" with "executed?" — Ilias Lazaridis <ilias@...>

The construct to detect execution of the file (in order to launch main

12 messages 2011/06/02

[#384104] CORE - Altering Behaviour of "each do" (default param "item") — Ilias Lazaridis <ilias@...>

1.9

76 messages 2011/06/04
[#384111] Re: CORE - Altering Behaviour of "each do" (default param "item") — James Gray <james@...> 2011/06/04

On Sat, Jun 4, 2011 at 6:50 AM, Ilias Lazaridis <ilias@lazaridis.com> wrote:

[#384154] Re: CORE - Altering Behaviour of "each do" (default param "item") — Yukihiro Matsumoto <matz@...> 2011/06/05

Hi,

[#384168] Re: CORE - Altering Behaviour of "each do" (default param "item") — Ilias Lazaridis <ilias@...> 2011/06/06

On 6 撫, 01:11, Yukihiro Matsumoto <m...@ruby-lang.org> wrote:

[#384228] a little challenge - reproduce this error — Intransition <transfire@...>

Want to see a really amazing error I got this week? Okay... but to

24 messages 2011/06/08
[#384230] Re: a little challenge - reproduce this error — Steve Klabnik <steve@...> 2011/06/08

throw NameError.new("uninitialized constant X::Foo::X")

[#384231] Re: a little challenge - reproduce this error — John Feminella <johnf@...> 2011/06/08

This is a pretty trivial error to generate. Just reference the

[#384232] Re: a little challenge - reproduce this error — Intransition <transfire@...> 2011/06/08

[#384235] Re: a little challenge - reproduce this error — Christopher Dicely <cmdicely@...> 2011/06/08

On Wed, Jun 8, 2011 at 6:43 AM, Intransition <transfire@gmail.com> wrote:

[#384279] CORE - Literal Instantiation breaks Object Model — Ilias Lazaridis <ilias@...>

class String

14 messages 2011/06/09

[#384280] BARRIER - require "rubygems" — Ilias Lazaridis <ilias@...>

ruby 1.9.2p180 Windows 7

30 messages 2011/06/09

[#384283] Classic Computer Science Books — Stu <stu@...>

I wanted to start a thread discussion on classic computer science

38 messages 2011/06/09
[#384288] Re: Classic Computer Science Books — Josh Cheek <josh.cheek@...> 2011/06/10

On Thu, Jun 9, 2011 at 5:18 PM, Stu <stu@rubyprogrammer.net> wrote:

[#384289] Re: Classic Computer Science Books — Chad Perrin <code@...> 2011/06/10

On Fri, Jun 10, 2011 at 09:22:58AM +0900, Josh Cheek wrote:

[#384291] Re: Classic Computer Science Books — Stu <stu@...> 2011/06/10

Thank you for the responses. I look forward to reading others.

[#384346] Re: Classic Computer Science Books — Anurag Priyam <anurag08priyam@...> 2011/06/11

> queue to read Meyers C++ books and Crockford's Javascript: The Good

[#384349] Re: Classic Computer Science Books — Stu <stu@...> 2011/06/11

Hello Anurag

[#384430] Re: Classic Computer Science Books — Anurag Priyam <anurag08priyam@...> 2011/06/13

Hey Stu,

[#384464] Re: Classic Computer Science Books — Vin兤ius <undvinicius@...> 2011/06/14

Wow, those are a lot of books, as a beginner programmer, I don't have

[#384322] PSA: Ilias is Crazy — Ryan Davis <ryand-ruby@...>

I guess I have to post this periodically since our population is growing and changing so much.

18 messages 2011/06/10

[#384363] RFC - One word alias for require_relative — Ilias Lazaridis <ilias@...>

This is a simple Request for Comments.

161 messages 2011/06/11
[#384368] Re: RFC - One word alias for require_relative — Intransition <transfire@...> 2011/06/11

[#384654] Re: RFC - One word alias for require_relative — Ilias Lazaridis <ilias@...> 2011/06/17

On 11 撫, 20:35, Ilias Lazaridis <il...@lazaridis.com> wrote:

[#384676] Re: RFC - One word alias for require_relative — Yukihiro Matsumoto <matz@...> 2011/06/17

Hi,

[#384633] Re: RFC - One word alias for require_relative — Ilias Lazaridis <ilias@...> 2011/06/17

On 17 撫, 21:17, Gary Wright <gwtm...@mac.com> wrote:

[#384432] commit message conventions — Intransition <transfire@...>

When I write commit messages I add a "team" prefix to the message,

14 messages 2011/06/13
[#384433] Re: commit message conventions — John Feminella <johnf@...> 2011/06/13

I greatly dislike that style, to be frank. My commit messages usually

[#384467] A way to find out when a constant gets defined? — Josh Cheek <josh.cheek@...>

Hi, I'd like to be able to find out when a constant gets defined. I think I

14 messages 2011/06/14

[#384490] Messages to Ruby List/Forum/etc. not arriving equally? — Markus Fischer <markus@...>

Hi,

11 messages 2011/06/15

[#384500] CORE - Inconsistent Handling of Uninitialized Variables — Ilias Lazaridis <ilias@...>

puts "\n== Testin in MAIN Context =="

18 messages 2011/06/15

[#384617] get execution name of program — Chad Perrin <code@...>

Either $0 or __FILE__ will return a filename to give context for how a

13 messages 2011/06/17

[#384634] default config file location — Chad Perrin <code@...>

Is there a "better" way to specify a default config file location than

16 messages 2011/06/17
[#384637] Re: default config file location — "Matthew K. Williams" <matt@...> 2011/06/17

On Sat, 18 Jun 2011, Chad Perrin wrote:

[#384648] celluloid 0.0.3: a concurrent object framework for Ruby — Tony Arcieri <tony.arcieri@...>

Celluloid is a concurrent object framework for Ruby inspired by Erlang

12 messages 2011/06/17

[#384763] MIDASWAD - Matz is Dumb and so We are Dumb — Ilias Lazaridis <ilias@...>

(public draft)

46 messages 2011/06/20
[#384765] Re: MIDASWAD - Matz is Dumb and so We are Dumb — Chad Perrin <code@...> 2011/06/20

Before anyone engages this nonsense . . .

[#384772] Re: MIDASWAD - Matz is Dumb and so We are Dumb — Adam Prescott <adam@...> 2011/06/20

On 20 Jun 2011 20:32, "Chad Perrin" <code@apotheon.net> wrote:

[#384774] Re: MIDASWAD - Matz is Dumb and so We are Dumb — Sam Duncan <sduncan@...> 2011/06/20

Five posts in on this thread, and four of them are the self appointed

[#384779] Re: MIDASWAD - Matz is Dumb and so We are Dumb — David Masover <ninja@...> 2011/06/20

A quick, lazy response, because I shouldn't feed trolls anyway, and I simply

[#384788] Re: MIDASWAD - Matz is Dumb and so We are Dumb — Nikolai Weibull <now@...> 2011/06/21

On Mon, Jun 20, 2011 at 23:52, David Masover <ninja@slaphack.com> wrote:

[#384790] Re: MIDASWAD - Matz is Dumb and so We are Dumb — Adam Prescott <adam@...> 2011/06/21

On Tue, Jun 21, 2011 at 11:06 AM, Nikolai Weibull <now@bitwi.se> wrote:

[#384792] Re: MIDASWAD - Matz is Dumb and so We are Dumb — Nikolai Weibull <now@...> 2011/06/21

On Tue, Jun 21, 2011 at 13:37, Adam Prescott <adam@aprescott.com> wrote:

[#384800] How to order a hash based on its keys? — Iñaki Baz Castillo <ibc@...>

Hi, I want to order a hash using itds keys:

35 messages 2011/06/21
[#384808] Re: How to order a hash based on its keys? — Robert Klemme <shortcutter@...> 2011/06/21

On Tue, Jun 21, 2011 at 4:34 PM, Iki Baz Castillo <ibc@aliax.net> wrote:

[#384813] Re: How to order a hash based on its keys? — Iñaki Baz Castillo <ibc@...> 2011/06/21

2011/6/21 Robert Klemme <shortcutter@googlemail.com>:

[#384814] Re: How to order a hash based on its keys? — Iñaki Baz Castillo <ibc@...> 2011/06/21

2011/6/21 Iñaki Baz Castillo <ibc@aliax.net>:

[#384833] Re: How to order a hash based on its keys? — Robert Klemme <shortcutter@...> 2011/06/22

On Tue, Jun 21, 2011 at 6:34 PM, Iki Baz Castillo <ibc@aliax.net> wrote:

[#384837] Re: How to order a hash based on its keys? — Iñaki Baz Castillo <ibc@...> 2011/06/22

2011/6/22 Robert Klemme <shortcutter@googlemail.com>:

[#384843] Re: How to order a hash based on its keys? — Robert Klemme <shortcutter@...> 2011/06/22

On Wed, Jun 22, 2011 at 11:50 AM, Iki Baz Castillo <ibc@aliax.net> wrote:

[#384846] Re: How to order a hash based on its keys? — Iñaki Baz Castillo <ibc@...> 2011/06/22

2011/6/22 Robert Klemme <shortcutter@googlemail.com>:

[#384847] Re: How to order a hash based on its keys? — Robert Klemme <shortcutter@...> 2011/06/22

On Wed, Jun 22, 2011 at 3:47 PM, Iki Baz Castillo <ibc@aliax.net> wrote:

[#384849] Re: How to order a hash based on its keys? — Iñaki Baz Castillo <ibc@...> 2011/06/22

2011/6/22 Robert Klemme <shortcutter@googlemail.com>:

[#384855] Re: How to order a hash based on its keys? — Robert Klemme <shortcutter@...> 2011/06/22

On Wed, Jun 22, 2011 at 4:19 PM, Iki Baz Castillo <ibc@aliax.net> wrote:

[#384819] Gateway Shutting Down — James Gray <james@...>

Rubyists:

12 messages 2011/06/21

[#384873] Explicitly setting compiler to C++ in extconf.rb... — "Darryl L. Pierce" <mcpierce@...>

I'm trying to setup a Ruby gem that bundles the Swig-generated bindings

10 messages 2011/06/23

[#384907] SPDX (and the glazing of ones eyes) — Intransition <transfire@...>

Never ceases to amaze me how complicated "enterprisey" peoples can

17 messages 2011/06/25
[#384909] Re: SPDX (and the glazing of ones eyes) — Phillip Gawlowski <cmdjackryan@...> 2011/06/25

On Sat, Jun 25, 2011 at 5:00 PM, Intransition <transfire@gmail.com> wrote:

[#384996] A movie Renamer — Mayank Kohaley <mayank.kohaley@...>

Hello Guys,

20 messages 2011/06/29
[#385007] Re: A movie Renamer — Sam Duncan <sduncan@...> 2011/06/29

Please don't steal movies.

[#385010] Re: A movie Renamer — Chad Perrin <code@...> 2011/06/29

On Thu, Jun 30, 2011 at 06:17:55AM +0900, Sam Duncan wrote:

[#385011] Re: A movie Renamer — Sam Duncan <sduncan@...> 2011/06/29

*sigh*

[#385019] A File Renamer — Mayank Kohaley <mayank.kohaley@...>

I guess this thread has spawned another issue. Let me close this and say I

18 messages 2011/06/30
[#385021] Re: A File Renamer — Jeremy Heiler <jeremyheiler@...> 2011/06/30

On Thu, Jun 30, 2011 at 1:48 AM, Mayank Kohaley

[#385027] Re: A File Renamer — Johnny Morrice <spoon@...> 2011/06/30

> Is there a pattern to the file names you are working with? The key is

Re: Kernel#autoload vs require_relative

From: David Masover <ninja@...>
Date: 2011-06-17 21:54:55 UTC
List: ruby-talk #384657
On Friday, June 17, 2011 06:06:33 AM Robert Klemme wrote:
> On Fri, Jun 17, 2011 at 9:33 AM, David Masover <ninja@slaphack.com> wrote:
> >  require 'autoloader'
> >  AutoLoader << File.dirname(__FILE__)
> > 
> >  module Foo
> >    include AutoLoader
> >  end
> > 
> > Ok, there's some __FILE__ ugliness, but in exchange, you automagically
> > get 'autoload' statements generated for everything, and you don't have
> > to modify your load path.
> 
> I think there is a cure for that:
> 
> module AutoLoader
>   def self.included(cl)
>     # "alc.rb:33:in `<class:X>'"
>     file = caller[1][%r{\A(.*?):\d+:in\s}, 1]
>     self << File.dirname(file)
>   end
> 
>   # debug:
>   def self.<<(d)
>     puts "Adding directory: #{d}"
>   end
> end

That needs some work. Dirname isn't enough, since right now, things may be 
nested arbitrarily deep -- I could have lib/foo/bar.rb which looks similar:

  module Foo
    module Bar
      include AutoLoader
    end
  end

But I clearly still want 'lib' to be the top-level directory for this magic. 
That is, I want foo/bar/baz.rb to map to Foo::Bar::Baz, not to Bar::Baz.

I really don't mind the __FILE__ ugliness, given that it only has to happen 
once, at the very top of the project. The assumption is that you'd never have 
a reason to require anything other than this top-level library, since 
everything else is included with autoload, so you'll only get the stuff you 
need -- that is, there's no advantage to:

  require 'foo/bar'
  Foo::Bar.do_something!

rather than

  require 'foo'
  Foo::Bar.do_something!

So I have no motivation to get rid of __FILE__, though maybe there should be 
some convenience version, maybe something like:

  AutoLoader.add_relative_path 'path/to/lib'   # defaults to '.'

> In Ruby land we could at least do
> 
> auto_module :Foo do
>   # no more "include" needed here
> end
> 
> or even
> 
> auto_module :Foo
> 
> if there is nothing that needs to be defined here.  But then we have a
> "require" statement and a file with a single line - that doesn't feel
> right.

Yeah, it doesn't really solve the problem. 'include' isn't the problem. The 
problem is that this library shouldn't force me to add _any_ special syntax or 
calls, let alone special files, to make it work. It should just let me pretend 
that my entire directory got slurped -- this was inspired by Rails' 
const_missing behavior, but also by Ramaze's "acquire" which just requires 
every ruby file in a given path.

> Hm, for me this generally works pretty well: I have a lib directory
> which is part of the load path and for larger libraries I have an
> initial file (e.g. "foo.rb") where the root namespace is defined
> together with a set of autoload directives which then load files like
> "foo/class1", "foo/class2" etc.

I don't mind this, except for two things:

 - I shouldn't have to modify the load path. I should be doing it anyway, 
maybe, but it shouldn't be a requirement.

 - It's annoying having to explicitly autoload everything, especially when I'm 
usually following a convention.

> Basically, as long as there is no fixed relationship between file name
> and content, there will always be a level of manual intervention
> needed.

I like convention over configuration. Not convention instead of configuration 
-- there's always manual autoload if I need them, and I suspect the first 
thing I'd change about AutoLoader at this point is being able to specify which 
files are included and which aren't. But when 99% of the time, the process is:

 - Create foo/bar.rb.
   - Create class Foo::Bar in foo/bar.rb.
   - Add autoload line to foo.rb.
 - Did I really want it called bar.rb? Maybe baz.rb is a better name.
   - git mv foo/bar.rb foo/baz.rb
   - Change Foo::Bar to Foo::Baz in foo/baz.rb
   - Change autoload line in foo.rb.
   - Update any other references.
 - Maybe I want to split it into foo/one.rb and foo/two.rb.
   - create foo/one.rb, foo/two.rb.
   - edit/move some stuff, update references.
   - git add foo/one.rb foo/two.rb
   - git rm foo/baz.rb
   - edit foo.rb and update the autoload line.

This is annoying. Sure, it's going to be annoying no matter what, but anything 
I can do to ease this pain is helpful, because I do this kind of thing a _lot_ 
in the first few hours of a project. Anytime I see a better organization, 
_now_ is the time, before I've published it to a dev team (let alone to the 
world via Github) and locked myself into an API.

It's also annoyingly redundant and menial. This is something the machine can 
do perfectly well for me, so why not let it?

Also worth mentioning: When you're autoloading everything, anything beyond the 
top-level "require 'yourgem'" is no longer part of your public API. So, any 
naming convention is entirely for your own convenience at this point. I just 
did what Rails did and made it convenient to follow that one naming 
convention. So when I actually use AutoLoader, I don't have exceptions to that 
naming convention, or, really, any reason to.

> The advantage of
> the current autoload approach is that it makes things explicit.
> Downside is still that the relativity issue (with regard to pathnames,
> not E=mc2) is still there.

Well, as you demonstrate, that's easily solved. But in my opinion, the other 
downside is that it makes things explicit, when there isn't a good reason for 
them to be.

At this point, AutoLoader isn't about solving the relativity issue, it's about 
DRYing things up a bit.

In This Thread

Prev Next