[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Safe override of Class#new?

Trans

3/5/2007 7:52:00 PM


class Class
alias :create :new

def new(*a,&b)
obj = allocate
obj.extend advice
obj.send(:initialize,*a,&b)
return obj
end
end

Note #advice is a sprcisl module that provides AOP features.

Like to get the opinions of other Ruby experts on this. What kind of
potential trouble am I asking for by using this?

Thanks,
T.


9 Answers

Erik Veenstra

3/5/2007 8:39:00 PM

0

> Like to get the opinions of other Ruby experts on this. What
> kind of potential trouble am I asking for by using this?

(Not that I'm a Ruby expert, but anyway...)

You'll run into a real slowdown of your application. AFAIK,
creating objects is one of the most expensive operations in any
OO language. Even when it's implemented in C, as is done with
Ruby.

Yeah, sure, go ahead, implement it in Ruby and slow it down by
a factor of three!... :}

(Just kidding...)

gegroet,
Erik V. - http://www.erikve...

----------------------------------------------------------------

require "benchmark"

class Class
alias :create :new

def new_new(*a, &b)
obj = allocate
obj.send(:initialize, *a, &b)
obj
end
end

times = 1_000_000

Benchmark.bmbm do |bm|
bm.report("old_new") do
times.times do
Object.new
end
end

bm.report("new_new") do
times.times do
Object.new_new
end
end
end

----------------------------------------------------------------

<snip/>

user system total real
old_new 0.680000 0.010000 0.690000 ( 0.687622)
new_new 1.880000 0.010000 1.890000 ( 1.889214)

----------------------------------------------------------------


Trans

3/6/2007 12:39:00 AM

0



On Mar 5, 3:39 pm, "Erik Veenstra" <erikv...@gmail.com> wrote:
> > Like to get the opinions of other Ruby experts on this. What
> > kind of potential trouble am I asking for by using this?
>
> (Not that I'm a Ruby expert, but anyway...)
>
> You'll run into a real slowdown of your application. AFAIK,
> creating objects is one of the most expensive operations in any
> OO language. Even when it's implemented in C, as is done with
> Ruby.
>
> Yeah, sure, go ahead, implement it in Ruby and slow it down by
> a factor of three!... :}
>
> (Just kidding...)
>
> gegroet,
> Erik V. -http://www.erikve...
>
> ----------------------------------------------------------------
>
> require "benchmark"
>
> class Class
> alias :create :new
>
> def new_new(*a, &b)
> obj = allocate
> obj.send(:initialize, *a, &b)
> obj
> end
> end
>
> times = 1_000_000
>
> Benchmark.bmbm do |bm|
> bm.report("old_new") do
> times.times do
> Object.new
> end
> end
>
> bm.report("new_new") do
> times.times do
> Object.new_new
> end
> end
> end
>
> ----------------------------------------------------------------
>
> <snip/>
>
> user system total real
> old_new 0.680000 0.010000 0.690000 ( 0.687622)
> new_new 1.880000 0.010000 1.890000 ( 1.889214)
>

Ouch. Sigh, any way I seem to slice it, AOP in pure Ruby sucks.

T.


Pit Capitain

3/6/2007 7:56:00 AM

0

Trans schrieb:
> Ouch. Sigh, any way I seem to slice it, AOP in pure Ruby sucks.

Welcome to the club :-(

Regards,
Pit

Paolo Nusco Perrotta

3/6/2007 11:09:00 PM

0

On Mar 6, 1:38 am, "Trans" <transf...@gmail.com> wrote:
> Ouch. Sigh, any way I seem to slice it, AOP in pure Rubysucks.

OTOH, do you really want to AOP-ify all Ruby classes? Maybe you can
apply the advice to a limited subset of classes. The performance hit
might be acceptable in the end.

Trans

3/7/2007 8:40:00 PM

0



On Mar 6, 6:10 pm, "Paolo Nusco Perrotta"
<paolo.nusco.perro...@gmail.com> wrote:
> On Mar 6, 1:38 am, "Trans" <transf...@gmail.com> wrote:
>
> > Ouch. Sigh, any way I seem to slice it, AOP in pure Rubysucks.
>
> OTOH, do you really want to AOP-ify all Ruby classes? Maybe you can
> apply the advice to a limited subset of classes. The performance hit
> might be acceptable in the end.

Thank you. I think that will indeed be enough.

T.


suzeeq

7/2/2012 2:45:00 PM

0

Dano wrote:
> "suzeeq" wrote in message news:jsq495$vhf$3@dont-email.me...
>
> Dano wrote:
>> "suzeeq" wrote in message news:jsptou$qb6$2@dont-email.me...
>>
>> Adam H. Kerman wrote:
>>> Obveeus <Obveeus@aol.com> wrote:
>>>> "suzeeq" <suzee@imbris.com> wrote:
>>>>> Adam H. Kerman wrote:
>>>>>> Henry reveals that the pot is a strain from Afghanistan (seriously?)
>>>>>> and
>>>>> Yep, they grow a lot in the region.
>>>> Yep. Afghanistan used to be all about the opium trade, but ever since
>>>> the US military went in to support the local farmers, marijuana
>>>> cultivation has really taken off.
>>> How the fuck would you know this?
>> It's in the news...?
>>
>> =========================================
>>
>> What?!? You READ? The news even? That is grotesquely off topic.
>
> Most news I watch on tv. Very on topic.
>
> ===================================
>
> Yeah...I know. I was being facetious. A statement on the whining of the
> head-in-the-sand whiners who hate the OT posts.

I knew you were joking...

Anim8rFSK

7/2/2012 4:21:00 PM

0

In article <jssc5r$gsv$1@dont-email.me>, suzeeq <suzee@imbris.com>
wrote:

> Dano wrote:
> > "suzeeq" wrote in message news:jsq495$vhf$3@dont-email.me...
> >
> > Dano wrote:
> >> "suzeeq" wrote in message news:jsptou$qb6$2@dont-email.me...
> >>
> >> Adam H. Kerman wrote:
> >>> Obveeus <Obveeus@aol.com> wrote:
> >>>> "suzeeq" <suzee@imbris.com> wrote:
> >>>>> Adam H. Kerman wrote:
> >>>>>> Henry reveals that the pot is a strain from Afghanistan (seriously?)
> >>>>>> and
> >>>>> Yep, they grow a lot in the region.
> >>>> Yep. Afghanistan used to be all about the opium trade, but ever since
> >>>> the US military went in to support the local farmers, marijuana
> >>>> cultivation has really taken off.
> >>> How the fuck would you know this?
> >> It's in the news...?
> >>
> >> =========================================
> >>
> >> What?!? You READ? The news even? That is grotesquely off topic.
> >
> > Most news I watch on tv. Very on topic.
> >
> > ===================================
> >
> > Yeah...I know. I was being facetious. A statement on the whining of the
> > head-in-the-sand whiners who hate the OT posts.
>
> I knew you were joking...

You misspelled "I knew you were a joke..."

--
"Every time a Kardashian gets a TV show, an angel dies."

suzeeq

7/2/2012 5:43:00 PM

0

anim8rFSK wrote:
> In article <jssc5r$gsv$1@dont-email.me>, suzeeq <suzee@imbris.com>
> wrote:
>
>> Dano wrote:
>>> "suzeeq" wrote in message news:jsq495$vhf$3@dont-email.me...
>>>
>>> Dano wrote:
>>>> "suzeeq" wrote in message news:jsptou$qb6$2@dont-email.me...
>>>>
>>>> Adam H. Kerman wrote:
>>>>> Obveeus <Obveeus@aol.com> wrote:
>>>>>> "suzeeq" <suzee@imbris.com> wrote:
>>>>>>> Adam H. Kerman wrote:
>>>>>>>> Henry reveals that the pot is a strain from Afghanistan (seriously?)
>>>>>>>> and
>>>>>>> Yep, they grow a lot in the region.
>>>>>> Yep. Afghanistan used to be all about the opium trade, but ever since
>>>>>> the US military went in to support the local farmers, marijuana
>>>>>> cultivation has really taken off.
>>>>> How the fuck would you know this?
>>>> It's in the news...?
>>>>
>>>> =========================================
>>>>
>>>> What?!? You READ? The news even? That is grotesquely off topic.
>>> Most news I watch on tv. Very on topic.
>>>
>>> ===================================
>>>
>>> Yeah...I know. I was being facetious. A statement on the whining of the
>>> head-in-the-sand whiners who hate the OT posts.
>> I knew you were joking...
>
> You misspelled "I knew you were a joke..."

No. I didn't.

Anim8rFSK

7/2/2012 6:48:00 PM

0

In article <jssmje$ldo$1@dont-email.me>, suzeeq <suzee@imbris.com>
wrote:

> anim8rFSK wrote:
> > In article <jssc5r$gsv$1@dont-email.me>, suzeeq <suzee@imbris.com>
> > wrote:
> >
> >> Dano wrote:
> >>> "suzeeq" wrote in message news:jsq495$vhf$3@dont-email.me...
> >>>
> >>> Dano wrote:
> >>>> "suzeeq" wrote in message news:jsptou$qb6$2@dont-email.me...
> >>>>
> >>>> Adam H. Kerman wrote:
> >>>>> Obveeus <Obveeus@aol.com> wrote:
> >>>>>> "suzeeq" <suzee@imbris.com> wrote:
> >>>>>>> Adam H. Kerman wrote:
> >>>>>>>> Henry reveals that the pot is a strain from Afghanistan (seriously?)
> >>>>>>>> and
> >>>>>>> Yep, they grow a lot in the region.
> >>>>>> Yep. Afghanistan used to be all about the opium trade, but ever since
> >>>>>> the US military went in to support the local farmers, marijuana
> >>>>>> cultivation has really taken off.
> >>>>> How the fuck would you know this?
> >>>> It's in the news...?
> >>>>
> >>>> =========================================
> >>>>
> >>>> What?!? You READ? The news even? That is grotesquely off topic.
> >>> Most news I watch on tv. Very on topic.
> >>>
> >>> ===================================
> >>>
> >>> Yeah...I know. I was being facetious. A statement on the whining of the
> >>> head-in-the-sand whiners who hate the OT posts.
> >> I knew you were joking...
> >
> > You misspelled "I knew you were a joke..."
>
> No. I didn't.

You didn't know Dano's a joke?

--
"Every time a Kardashian gets a TV show, an angel dies."