From: Intransition Date: 2012-04-21T11:24:39+09:00 Subject: Re: Why must I know whether I extend a class or a module? ------=_Part_1853_27728722.1334975076203 Content-Type: multipart/alternative; boundary="----=_Part_1854_32690021.1334975076203" ------=_Part_1854_32690021.1334975076203 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On Friday, April 20, 2012 8:12:37 PM UTC-4, Matthew Kerwin wrote: > > On 20 April 2012 13:53, Intransition wrote: > > The forced distinction only serves to take that flexibility away from the > > programmer. > > Is there not overhead associated with that distinction? I haven't > actually looked into it, but I'd assume that Modules are a lot more > light-weight than Classes, because of the things that can't be done > with them. > The Class class is subclass of Module and is almost devoid of it's own methods. > > There are other benefits too in that removing the distinction would allow > > auto instantiation, e.g. > > > > class Foo::Bar > > end > > > > Would work just fine, even though no `Foo` has been defined separately. > This > > can be especially nice when requiring sub-files. > > I can see that this would be convenient, but it also makes me cringe. > You're defining a namespace Foo without ever explicitly defining it. > Why? What's its purpose? How and where is it documented? I can't > make my gut instinct accept this as anything but a bad idea. > Typically that would be the case -- the encasing module/class would be defined *ultimately*. This way it just doesn't have to be done prior to classes/module internal to it. For example in project I often need adapters. class MyApp::Adapters::Foo class MyApp::Adapters::Bar ... In the myapp/adapters.rb I've would like to write: require 'myapp/adapters/foo' require 'myapp/adapters/bar' module MyApp::Adapters ... end But instead I have to do: module MyApp::Adapters ... end require 'myapp/adapters/foo' require 'myapp/adapters/bar' I don't like requires at the bottom. Even so, there are times when it doesn't really matter. If for instance my MyApp::Adapters module had no contents other then the adapter classes, then it really makes no difference. ------=_Part_1854_32690021.1334975076203 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

On Friday, April 20, 2012 8:12:37 PM UTC-4, Matthew Kerwin wrote:On 20 April 2012 13:53, Intransi= tion <transfire= @gmail.com> wrote:
> The forced distinction only serves to tak= e that flexibility away from the
> programmer.

Is there not overhea= d associated with that distinction? I haven't
actually looked into it, b= ut I'd assume that Modules are a lot more
light-weight than Classes, bec= ause of the things that can't be done
with them.

Th= e Class class is subclass of Module and is almost devoid of it's own method= s.
 
<= p>> There are other benefits too in that removing the distinction would = allow
> auto instantiation, e.g.
>
>     class = Foo::Bar
>     end
>
> Would work just fine, ev= en though no `Foo` has been defined separately. This
> can be especia= lly nice when requiring sub-files.

I can see that this would be conve= nient, but it also makes me cringe.
You're defining a namespace Foo with= out ever explicitly defining it.
Why? What's its purpose?  How and = where is it documented?  I can't
make my gut instinct accept this a= s anything but a bad idea.

Typically that would be the= case -- the encasing module/class would be defined *ultimately*. This way = it just doesn't have to be done prior to classes/module internal to it.

For example in project I often need adapters.

  class MyApp::Adapters::Foo
  class = MyApp::Adapters::Bar
  ...

In t= he myapp/adapters.rb I've would like to write:

&nb= sp; require 'myapp/adapters/foo'
  require 'myapp/adapters/b= ar'

  module MyApp::Adapters
&n= bsp;   ...
  end

But instead I= have to do:

  module MyApp::Adapters
    ...
=
  end

  requir= e 'myapp/adapters/foo'
  require= 'myapp/adapters/bar'

<= /div>
I don't like requires at the bottom.<= /div>

Even so, there are times when it doesn't really matter. If for instan= ce my MyApp::Adapters module had no contents other then the adapter classes= , then it really makes no difference.

------=_Part_1854_32690021.1334975076203-- ------=_Part_1853_27728722.1334975076203--