Is it considered Harmful?

Discussion in 'Ruby' started by rolo, Jun 25, 2004.

  1. rolo

    Sean O'Dell Guest

    Do me a favor. I don't insert personal attacks here towards you during these
    discussions, so leave them out when you're addressing me.

    Sean O'Dell
     
    Sean O'Dell, Jun 28, 2004
    1. Advertisements

  2. evil.rb implements #become without traversing the entire set of live
    references; it simply alters the objects in place, I think.

    With just #become (no class=), you can't create objects whose
    #initialize is not called. It's just like swapping variables, except
    all variables that point to the pointee are affected.

    mikael
     
    Mikael Brockman, Jun 28, 2004
    1. Advertisements

  3. rolo

    Sean O'Dell Guest

     
    Sean O'Dell, Jun 28, 2004
  4. rolo

    Hal Fulton Guest

    You're missing his point.

    If I call Array.new, I certainly get an array whose #initialize
    has been called.

    But if I then do arr.class = Net::HTTP, then Net:HTTP#initialize
    does NOT get called (e.g., to set the host name or whatever).


    Hal
     
    Hal Fulton, Jun 28, 2004
  5.  
    Mikael Brockman, Jun 28, 2004
  6. No, it wouldn't work safely, and your protestations to the contrary
    won't change that -- Tempfile *expects* that by time you would call
    #write on an object of its class, the tempfile will be open. You have
    introduced a situation, with #class=, where not only is the tempfile
    not open, it simply does not exist.

    You also demonstrate a fundamental misunderstanding of the difference
    between #class= and #become; they are not related.

    foo = Object.new
    foo.class = Tempfile

    is not the same as:

    foo = Object.new
    foot = Tempfile.new("foot")
    foo.become(foot)

    All references to foo now become references to foot, and foo itself is
    released for garbage collection. It should really be quite obvious why
    one is safer than the other.

    -austin
     
    Austin Ziegler, Jun 28, 2004
  7. rolo

    rolo Guest

    I think Class and Modules in Ruby differ here. Modules are just set of
    methods but class is not. So, all that we will like to achieve by #class= ,
    we should get it by including/excluding Modules.
     
    rolo, Jun 28, 2004
  8. Please note that there's a case where it's not guaranteed to be called:
    There's already Object#allocate which creates an Object without
    initializing it.

    Regards,
    Florian Gross
     
    Florian Gross, Jun 28, 2004
  9. I can make up a quick example that has no real-world meaning:
    Does it have any use in real world code? I don't know. If anybody has an
    idea for a better example then please feel free to post it.
    I think that they are different in what they concretely do, though
    similar in what they abstractly do. (They're both about changing Objects
    in a way that you usually can't after their construction.)

    Regards,
    Florian Gross
     
    Florian Gross, Jun 28, 2004
  10. rolo

    Sean O'Dell Guest

    Ah...I see why I haven't connected with that issue now. I think of this as a
    "buyer beware" issue. If you change an existing object's class, be sure you
    change it to something that understands the object it is receiving. I think
    even #become would have these problems. Even using include could introduce
    methods to a class which didn't initialize instance data the way it expects.

    Sean O'Dell
     
    Sean O'Dell, Jun 28, 2004
  11. I think that those are one of the few persons who earned the right of
    doing more critical feedback than others, because usually that criticism
    is very, very true and enlightening.

    I'm still against personal attacks of course, (We're the Ruby community,
    we don't want to be just like the PHP and Perl communities -- we want to
    be friendly -- we want to get a long -- we want to live in a better
    world that is made possible by this wonderful language!) but I didn't
    see one in *this* posting of ts which you are referring to.

    But please, let us not argue about what is a personal nastiness and what
    isn't -- if you think that my posting didn't fit in this case then it's
    fine -- I just wanted to remind the community in general and for the future.

    Regards,
    Florian Gross
     
    Florian Gross, Jun 28, 2004
  12. rolo

    Sean O'Dell Guest

    Okay, I think I understand #become now. The object is COMPLETELY replaced by
    a totally different object. I do like that much better. Somewhere I got
    confused by the nature of #become.

    Sean O'Dell
     
    Sean O'Dell, Jun 28, 2004
  13. rolo

    Sean O'Dell Guest

    I'm not sure what that means. I have been keeping an even temper with people
    in here, despite the proddings. I think if I'm being level-headed with you,
    I deserve the same in return. If you can't post without inserting insults
    and nasty remarks, take it to private email. Keep this ML friendly and
    professional.

    Sean O'Dell
     
    Sean O'Dell, Jun 28, 2004
  14. rolo

    Sean O'Dell Guest

    Oh no, I didn't mean it was TOTALLY stable. I just meant it appeared stable
    to me and I wanted some people who knew better about the Ruby internals to
    make an assessment, which is why I brought it up in ruby-core. I didn't mean
    to imply it was completely safe under all circumstances, just that with some
    work, it COULD be. I know myself from looking at the internals, at how many
    places where code assumed the type of self, that it was likely there were
    lots of nooks and crannies that did the same thing and eventually someone
    would find a way to crash Ruby with the feature. I meant, *I* found it to be
    stable. I ran a few quick tests and couldn't find a way to crash Ruby with
    it.

    In fact, I still have the feature installed here. If someone could show me
    some Ruby code that makes Ruby crash with the #class= method I implemented, I
    would be more than happy to retract even that much. Show me code that
    crashes my #class= implementation; I already assume it can be done, now just
    show me how.

    Sean O'Dell
     
    Sean O'Dell, Jun 28, 2004
  15. You might not have noticed it, but that is exactly what ts did. And matz
    once stated that if he were to be hit by a bus that he would want ts to
    take over Ruby's development. If you ask me, ts has more than enough
    knowledge of Ruby's internals to rightly do point out errors -- and
    that's exactly what he did as far as I see the whole situation.
    I haven't tested these with your implementation, but they once were
    problematic in evil.rb.

    Object.class = Object # ?
    Class.class = Module # ?
    5.class = Object # ?
    obj = Time.new; require 'stringio'; obj.class = StringIO # ?

    Regards,
    Florian Gross
     
    Florian Gross, Jun 28, 2004
  16. rolo

    Sean O'Dell Guest

    Ah, so it was insulting when I didn't accept his word outright. I see. Well,
    I meant no harm; I didn't know Guy knew so much about the internals he could
    make a quick call like that.
    These two I would protect from #class=. Object, Class, Module and any other
    built-in, bootstrap-type classes I wouldn't even try #class= with.
    This one crashes as an integer, but as a float it does not. I'm not sure how
    to apply a type check to an integer.
    This one gave this error:

    testclass.rb:2:in `require': No such file to load -- stringio (LoadError)
    from testclass.rb:2

    ...which is exactly the direction I would keep developing #class= towards; to
    get a simple exception.

    Sean O'Dell
     
    Sean O'Dell, Jun 28, 2004
  17. It's easy to just twist a situation so that it appears different, but
    not always correct. You know that I didn't say that and I can truthfully
    tell you that it neither is or was what I thought.

    I mean exactly what I stated and that is that ts is right -- there is a
    lot of problems that you will run into when you fiddle with Ruby's
    internals which is why one ought to know what he is doing.

    I have learned that while being part of development of evil.rb -- of
    course one can't know everything and even less so everything
    immediately, but one at least has to admit that he's not all-knowing.

    But if you really can't agree with me here, then I guess it is okay. In
    that case I just feel a bit sorry that a common denominator could not be
    found; that would make all the people who didn't even try to find one
    appear in a better light than they deserve.
    StringIO is part of Ruby's Standard Library. You should have it
    available -- if it is not so then something might be wrong with your
    Ruby installation.

    Regards,
    Florian Gross
     
    Florian Gross, Jun 28, 2004
  18. rolo

    Sean O'Dell Guest

    What are we disagreeing on? I understand that Guy knows enough about Ruby
    that he can quickly determine the likelihood that #class= would ever be safe
    enough for release. I'm not sure what part of what I said you feel puts me
    in disagreement with you.

    Sean O'Dell
     
    Sean O'Dell, Jun 28, 2004
  19. rolo

    Hal Fulton Guest

    He thought you were being sarcastic in the paragraph starting "Ah..."
    I had to read it twice, but decided you were not.

    Guy (ts) is not superhuman, of course, but I would speculate that he
    knows more about Ruby internals than anyone else outside Japan (and
    quite a few or nearly all in Japan).


    Hal
     
    Hal Fulton, Jun 28, 2004
  20. rolo

    Ara.T.Howard Guest

    i strongly disagree with this statement hal.

    -a
    --
    ===============================================================================
    | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
    | PHONE :: 303.497.6469
    | A flower falls, even though we love it;
    | and a weed grows, even though we do not love it.
    | --Dogen
    ===============================================================================
     
    Ara.T.Howard, Jun 28, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.