[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: namespace pollution in ruby

Logan Capaldo

9/1/2006 1:30:00 AM


On Aug 31, 2006, at 9:03 PM, Hemant . wrote:

> Recently while coding in rails, i had a column called in one of the
> tables
> and hence was wrapped up by ActiveRecord.
> Guess, what it broke entire of the code, because quote is a already
> defined
> method somewhere in rails. I had trouble in finding out the root of
> the
> problem.
>
> Another example, as a newbie to ruby and rails I was using
> login_engine in
> my rails code. I have a table called messages in my database. Now,
> login_engine controller code is like this:
>
[snip code]
> Guess, what User.transaction was behaving oddly because it was
> throwing
> warning "Messages already defined constant". The error was shown in
> web
> server logs and hence again was a little difficult to track.
>
> Now, how as a new guy to ruby and rails, how do i know , i
> shouldn't have a
> column called quote and i shouldn't have a table called messages.
>
> I am a Qt/C++ programmer also, and the namespace issue is mostly
> non-existent there.First of all, its because all the Qt classes
> begin with Q
> and hence you know.But Ruby library authors seems a little lax on
> this, and
> open classes make the entire thing a little nifty and difficult to
> debug if
> you are caught on the wrong foot.Either library authors should avoid
> writting classes like Messages or ruby should give option of
> importing only
> certain methods from a module.
> Something like:
>
> using std::cout;
>
>
>
> But still i am new to ruby(3 months precisely), so if you wish you
> can take
> my assertions with a grain of salt.

This is in some ways more of a Rails problem than ruby problem and
involves the way rails works, with you inheriting from Rails'
classes. That particular problem would actually not be solved by C++
style namespaces or even Q-prefixes. A potential solution to the
problems you've experienced are the idea of selector namespaces which
have been tossed around on the ML before.

9 Answers

Logan Capaldo

9/1/2006 1:55:00 AM

0


On Aug 31, 2006, at 9:41 PM, Hemant . wrote:

> Why not, if rails would have been coded to have proper prefixes in the
> classes/modules, I would have avoided that trouble?
>

class RailsPrefixActiveRecord
def hello
... does something useful ...
end
end

class YourClass < RailsPrefixActiveRecord
belongs_to :hello
end

Do you see the issue now? Prefixes still wouldn't have helped your
problem, unless you wanted to prefix every method call, which is I
think we can agree ridiculous.

(P.S.: Please don't top-post)


Dave Howell

9/5/2006 11:32:00 PM

0


On Aug 31, 2006, at 18:54, Logan Capaldo wrote:

>
> On Aug 31, 2006, at 9:41 PM, Hemant . wrote:
>
>> Why not, if rails would have been coded to have proper prefixes in the
>> classes/modules, I would have avoided that trouble?
>>
>
> class RailsPrefixActiveRecord
> def hello
> ... does something useful ...
> end
> end
>
> class YourClass < RailsPrefixActiveRecord
> belongs_to :hello
> end
>
> Do you see the issue now?

<raise hand> Um, I don't. Since he said "prefixes IN the
classes/modules" and not "prefixes OF the classes/modules", I would
expect something like

> class RRActiveRecord
> def rrhello
> ... does something useful ...
> end
> end

Yes? No? On the other hand, I have no idea what "belongs_to" does, so
maybe that's why this doesn't make any sense to me...

> Prefixes still wouldn't have helped your problem, unless you wanted to
> prefix every method call, which is I think we can agree ridiculous.

Hmm. I've somehow not found that ridiculous in the case of Macintosh
OSX/Cocoa et al., where just about every imaginable object begins with
NS (for NextStep, as it happens). I collect NSEvents from my NSWindow
with its NSView with an NSTextField that gives me an NSString. That's
really worked pretty well for me so far.



Logan Capaldo

9/5/2006 11:50:00 PM

0


On Sep 5, 2006, at 7:32 PM, Dave Howell wrote:

>
>> Prefixes still wouldn't have helped your problem, unless you
>> wanted to prefix every method call, which is I think we can agree
>> ridiculous.
>
> Hmm. I've somehow not found that ridiculous in the case of
> Macintosh OSX/Cocoa et al., where just about every imaginable
> object begins with NS (for NextStep, as it happens). I collect
> NSEvents from my NSWindow with its NSView with an NSTextField that
> gives me an NSString. That's really worked pretty well for me so far.
>
>
>

I said prefix every method. Every Cocoa/NextSTEP method is not
prefixed with NS. You don't say [@"one.two.three"
NScomponentsSeparatedByString:@"."] you say [@"one.two.three"
componentsSeparatedByString: @"."]. Maybe I over-generalized when I
said we could agree that it was ridicolous, but NextSTEP / Cocoa is
not an example of prefixing every method call.

Yoorghis

8/18/2012 7:22:00 PM

0

On Sat, 18 Aug 2012 09:01:25 -0700, George Plimpton <george@si.not>
wrote:

>
>> Why?
>
>It's their money.

It's only "their money" if the tax code says it is. Point being is
that THEY cause the tax code to favor them---not you.

>
>> They don't work, the money isn't earned, it's merely "acquired"
>
>Irrelevant. It's their money.

No, that money comes from YOU

When taxes are cut on them---they are PAID FOR by you.

(except since rayguns days, the debt grows because they aren't)

Harold Burton

8/18/2012 7:27:00 PM

0

In article <uoqv28d30ko00l56s2cbpktq4gj7appcrq@4ax.com>,
Yoorghis@Jurgis.net wrote:

> On Sat, 18 Aug 2012 09:01:25 -0700, George Plimpton <george@si.not>
> wrote:
>
> >
> >> Why?
> >
> >It's their money.
>
> It's only "their money" if the tax code says it is. Point being is
> that THEY cause the tax code to favor them---

Doesn't everyone? Or at least try?

snicker

George Plimpton

8/18/2012 7:29:00 PM

0

On 8/18/2012 12:22 PM, Yoorghis@Jurgis.net wrote:
> On Sat, 18 Aug 2012 09:01:25 -0700, George Plimpton <george@si.not>
> wrote:
>
>>
>>> Why?
>>
>> It's their money.
>
> It's only "their money" if the tax code says it is.

No, it isn't. It's their money - period. The politicized tax code
might say they have to give up their money, but it's their money.


>>> They don't work, the money isn't earned, it's merely "acquired"
>>
>> Irrelevant. It's their money.
>
> No, that money comes from YOU

No, it doesn't. They earn it in commerce and as returns on investment.

Scout

8/18/2012 8:12:00 PM

0



<Yoorghis@Jurgis.net> wrote in message
news:uoqv28d30ko00l56s2cbpktq4gj7appcrq@4ax.com...
> On Sat, 18 Aug 2012 09:01:25 -0700, George Plimpton <george@si.not>
> wrote:
>
>>
>>> Why?
>>
>>It's their money.
>
> It's only "their money" if the tax code says it is. Point being is
> that THEY cause the tax code to favor them---not you.

Really? They are now in charge of our legislation, and specifically the
legislation concerning the tax code?

Seems to me that Congress and the President are in charge of that.


>>> They don't work, the money isn't earned, it's merely "acquired"
>>
>>Irrelevant. It's their money.
>
> No, that money comes from YOU

Are you accusing them of theft?

You realize that a crime, and if you can prove it that means they go to
jail.

----> insert your proof of theft here


> When taxes are cut on them---they are PAID FOR by you.

No. I don't pay their taxes before or after any cuts.

The only taxes I have to pay are my own.


> (except since rayguns days, the debt grows because they aren't)

Really? He was in charge back in 1957?


Scout

8/21/2012 4:20:00 AM

0



<Yoorghis@Jurgis.net> wrote in message
news:omb538dekpk6c46ukfa1tf0k6h8flq8r0s@4ax.com...
> On Mon, 20 Aug 2012 08:56:38 -0700, George Plimpton <george@si.not>
> wrote:
>
>>>>>> Yes, it is. They earned it. They engaged in the economic activity
>>>>>> that
>>>>>> produced it. It's their money.
>>>>>
>>>>> "THey" did nothing
>>>>
>>>> They earned the money. It's their money.
>>>
>>> Money on wealth/income is taxable.
>>
>>Taxes should be at a very low and flat rate.
>
> Why?
>
> Low tax rates create massive problems.

Not if government limits it's spending to the things it's suppose to be
doing.


George Plimpton

8/23/2012 2:39:00 AM

0

On 8/20/2012 2:42 PM, Yoorghis@Jurgis.net wrote:
> On Mon, 20 Aug 2012 08:56:38 -0700, George Plimpton <george@si.not>
> wrote:
>
>>>>>> Yes, it is. They earned it. They engaged in the economic activity that
>>>>>> produced it. It's their money.
>>>>>
>>>>> "THey" did nothing
>>>>
>>>> They earned the money. It's their money.
>>>
>>> Money on wealth/income is taxable.
>>
>> Taxes should be at a very low and flat rate.
>
> Why?

Because people don't exist and engage in productive endeavor in order to
fork it over to deadbeats.


> Low tax rates create massive problems.

Wrong.