[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

What a language!

benny

2/10/2005 12:11:00 AM

just another ruby gotcha:

to prevent namespace pollution from abitrary loaded files with code in it, I
had the idea to evaluate the code in anonymous modules, that are saved in a
hash (key is the filename/path).

worked so far, no problem.

then I tried to include the anonymous modules to have comfortable access to
the classes and methods of the corresponding files and guess what... it
worked!

include anonymous modules! whow! I am really impressed!
this language let me try things I would not think about in other languages.

thank you matz and the other developers for this great language!

benny





--
---------------------------------------------------------------------------------------------------
Don't crash when a filter changes the subject of a message which results
in the attempt to remove it from the tree of subject threading messages
failing and the detached child looking for a new parent finding the old
parent as the new parent, which in turn results in the child being deleted
with the old (and new) parent, which is not a good idea, since it is
still referenced.

(Till Adams commit on kdepim/kmail/kmheaders.cpp in HEAD, 6. Jan. 2005)
11 Answers

Joao Pedrosa

2/10/2005 12:31:00 AM

0

Hi,

On Thu, 10 Feb 2005 09:15:04 +0900, benny <listen@marcrenearns.de> wrote:
> just another ruby gotcha:
>
> to prevent namespace pollution from abitrary loaded files with code in it, I
> had the idea to evaluate the code in anonymous modules, that are saved in a
> hash (key is the filename/path).
>
> worked so far, no problem.
>
> then I tried to include the anonymous modules to have comfortable access to
> the classes and methods of the corresponding files and guess what... it
> worked!
>
> include anonymous modules! whow! I am really impressed!
> this language let me try things I would not think about in other languages.

It's great to see that the creativity isn't capped with Ruby. It is
always surprising to find out what people like you can come up with. I
haven't freed up my mind like that yet. :-)

> thank you matz and the other developers for this great language!

Indeed. Big thanks. He saw a lot of this 10 years ago, can you imagine
how lucky we are? :-) hehe

Matz 1.0 was great already. :-)

Cheers,
Joao


Nikolai Weibull

2/10/2005 12:39:00 AM

0

* benny (Feb 10, 2005 01:30):
> Don't crash when a filter changes the subject of a message which results
> in the attempt to remove it from the tree of subject threading messages
> failing and the detached child looking for a new parent finding the old
> parent as the new parent, which in turn results in the child being deleted
> with the old (and new) parent, which is not a good idea, since it is
> still referenced.

> (Till Adams commit on kdepim/kmail/kmheaders.cpp in HEAD, 6. Jan. 2005)

Totally off topic, but what a comment!
nikolai

--
::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


Douglas Livingstone

2/10/2005 12:45:00 AM

0

On Thu, 10 Feb 2005 09:38:50 +0900, Nikolai Weibull
<mailing-lists.ruby-talk@rawuncut.elitemail.org> wrote:
> * benny (Feb 10, 2005 01:30):
> > Don't crash when a filter changes the subject of a message which results
> > in the attempt to remove it from the tree of subject threading messages
> > failing and the detached child looking for a new parent finding the old
> > parent as the new parent, which in turn results in the child being deleted
> > with the old (and new) parent, which is not a good idea, since it is
> > still referenced.
>
> > (Till Adams commit on kdepim/kmail/kmheaders.cpp in HEAD, 6. Jan. 2005)
>
> Totally off topic, but what a comment!
>

Bets that there are nocomments like that in any production Ruby app?


Eric Hodel

2/10/2005 12:54:00 AM

0

On 09 Feb 2005, at 16:15, benny wrote:

> just another ruby gotcha:
>
> to prevent namespace pollution from abitrary loaded files with code in
> it, I
> had the idea to evaluate the code in anonymous modules, that are saved
> in a
> hash (key is the filename/path).
>
> worked so far, no problem.
>
> then I tried to include the anonymous modules to have comfortable
> access to
> the classes and methods of the corresponding files and guess what... it
> worked!
>
> include anonymous modules! whow! I am really impressed!
> this language let me try things I would not think about in other
> languages.
>
> thank you matz and the other developers for this great language!

If you don't need to do anything with the anonymous namespace:

$ ri Kernel#load
------------------------------------------------------------ Kernel#load
load(filename, wrap=false) => true
------------------------------------------------------------------------
Loads and executes the Ruby program in the file _filename_. If the
filename does not resolve to an absolute path, the file is searched
for in the library directories listed in +$:+. If the optional
_wrap_ parameter is +true+, the loaded script will be executed
under an anonymous module, protecting the calling program's global
namespace. In no circumstance will any local variables in the
loaded file be propagated to the loading environment.

$ cat x.rb
Foo = 5

puts "x here, is there a Foo? #{defined? Foo}"

$ cat y.rb
load 'x.rb', true

puts "y here, is there a Foo? #{defined? Foo}"

$ ruby y.rb
x here, is there a Foo? constant
y here, is there a Foo?

--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Navindra Umanee

2/10/2005 1:16:00 AM

0

Douglas Livingstone <rampant@gmail.com> wrote:
> > > Don't crash when a filter changes the subject of a message which
> > > results in the attempt to remove it from the tree of subject
> > > threading messages failing and the detached child looking for a
> > > new parent finding the old parent as the new parent, which in
> > > turn results in the child being deleted with the old (and new)
> > > parent, which is not a good idea, since it is still referenced.
> > > > > (Till Adams commit on kdepim/kmail/kmheaders.cpp in HEAD,
> > > 6. Jan. 2005)
>
> > Totally off topic, but what a comment!
> >
>
> Bets that there are nocomments like that in any production Ruby app?

Instead we get huge mysterious memory leaks. :-)

Cheers,
Navin.


Joao Pedrosa

2/10/2005 1:31:00 AM

0

Hi,

On Thu, 10 Feb 2005 10:16:20 +0900, Navindra Umanee
<navindra@cs.mcgill.ca> wrote:
> Douglas Livingstone <rampant@gmail.com> wrote:
> > > > Don't crash when a filter changes the subject of a message which
> > > > results in the attempt to remove it from the tree of subject
> > > > threading messages failing and the detached child looking for a
> > > > new parent finding the old parent as the new parent, which in
> > > > turn results in the child being deleted with the old (and new)
> > > > parent, which is not a good idea, since it is still referenced.
> > > > > > (Till Adams commit on kdepim/kmail/kmheaders.cpp in HEAD,
> > > > 6. Jan. 2005)
> >
> > > Totally off topic, but what a comment!
> > >
> >
> > Bets that there are nocomments like that in any production Ruby app?
>
> Instead we get huge mysterious memory leaks. :-)

This is a problem with all the languages, even with the garbage
collected ones. :-) "More creativity + More done" is the real cause of
the memory leaks in languages like Ruby. :-) But Java too has such
problems, mind you. It's good to bring up this because reality is
usually a little bit harder in every language.

Regards,
Joao


benny

2/10/2005 11:57:00 PM

0

Eric Hodel wrote:

>
> If you don't need to do anything with the anonymous namespace:
>
> $ ri Kernel#load

yes I know, but I needed to reuse the modules later

benny

--
---------------------------------------------------------------------------------------------------
Don't crash when a filter changes the subject of a message which results
in the attempt to remove it from the tree of subject threading messages
failing and the detached child looking for a new parent finding the old
parent as the new parent, which in turn results in the child being deleted
with the old (and new) parent, which is not a good idea, since it is
still referenced.

(Till Adams commit on kdepim/kmail/kmheaders.cpp in HEAD, 6. Jan. 2005)

benny

2/11/2005 12:02:00 AM

0

Nikolai Weibull wrote:

> * benny (Feb 10, 2005 01:30):
>> Don't crash when a filter changes the subject of a message which results
>> in the attempt to remove it from the tree of subject threading messages
>> failing and the detached child looking for a new parent finding the old
>> parent as the new parent, which in turn results in the child being
>> deleted with the old (and new) parent, which is not a good idea, since it
>> is still referenced.
>
>> (Till Adams commit on kdepim/kmail/kmheaders.cpp in HEAD, 6. Jan. 2005)
>
> Totally off topic, but what a comment!
> nikolai
>
I saw this commit message on the kde cvs-digest and wanted to use it as
signature. so I asked Mr. Adams if I may. He was amused and gave me the ok.

its a bit long for the usenet so I will replace it as soon as I made my
first ruby-onliner poem

:)

benny
--
---------------------------------------------------------------------------------------------------
Don't crash ...

dblack

2/11/2005 12:53:00 AM

0

Dave Burt

2/11/2005 7:50:00 AM

0

"Nikolai Weibull" <mailing-lists.ruby-talk@rawuncut.elitemail.org> wrote:
>* benny (Feb 10, 2005 01:30):
>> Don't crash when a filter changes the subject of a message which results
>> in the attempt to remove it from the tree of subject threading messages
>> failing and the detached child looking for a new parent finding the old
>> parent as the new parent, which in turn results in the child being
>> deleted
>> with the old (and new) parent, which is not a good idea, since it is
>> still referenced.
>
>> (Till Adams commit on kdepim/kmail/kmheaders.cpp in HEAD, 6. Jan. 2005)

It needs parentheses and syntax highlighting (colour verb-like bits red)...

Don't crash when ((a filter changes (the subject of a message)) which
results
in (the attempt to remove it from (the tree of subject threading messages)
failing) and ((the detached child looking for a new parent) finding the old
parent as the new parent), which in turn results in (the child being deleted
with (the old \(and new\) parent), (which is not a good idea, since it is
still referenced))).

Hope this helps :))

Dave