"stereotyping" thread

Ask a Question related to Ruby, Design and Development.

  1. #1

    Default "stereotyping" thread

    --Boundary-02=_YuEv/Tkrv4W8PF+
    Content-Type: text/plain;
    charset="utf-8"
    Content-Transfer-Encoding: quoted-printable
    Content-Description: signed data
    Content-Disposition: inline

    Why not just use empty modules for all this type-checking? This isn't=20
    very useful to me personally, but it seems to do everything that has=20
    been mentioned in this whole "stereotyping" thread (i.e. emits warnings=20
    if the passed in types haven't been manually tagged by a programmer as=20
    implementing a particular interface):

    class Object
    def typecheck(type)
    unless self.kind_of?(type)
    $stderr.puts "WARNING: expected #{type}, got #{self.class}"
    end
    end
    end

    module SomeInterface
    end

    def function_expecting_SomeInterface(var)
    var.typecheck(SomeInterface)
    end

    def function_expecting_Numeric(var)
    var.typecheck(Numeric)
    end

    class SomeClassThatClaimsToSupportSomeInterface
    include SomeInterface
    end

    class String
    #mark Strings as implementing some interface
    include SomeInterface
    end

    I'm not sure how special language syntax would help anything in this=20
    regard...

    =2D-=20
    Wesley J. Landaker - [email]wjl@icecavern.net[/email]
    OpenPGP FP: 4135 2A3B 4726 ACC5 9094 0097 F0A9 8A4C 4CD6 E3D2


    --Boundary-02=_YuEv/Tkrv4W8PF+
    Content-Type: application/pgp-signature
    Content-Description: signature

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.3 (GNU/Linux)

    iD8DBQA/vEuY8KmKTEzW49IRAnI3AJ99p2UpKRTtNBS5FajnFNEAdh0grg CggM9X
    HI/NEnImU3n3Go9WnmSMsqs=
    =Kd/0
    -----END PGP SIGNATURE-----

    --Boundary-02=_YuEv/Tkrv4W8PF+--


    Wesley J Landaker Guest

  2. Similar Questions and Discussions

    1. "stereotyping" (was: Strong Typing (Managing metadata about attribute types) )
      On Fri, 21 Nov 2003 02:20:04 +0900, Sean O'Dell wrote: Sorry, but you need to reread the type checking proponents' posts yourself if you think...
    2. "stereotyping" (was: Strong Typing (Managing metadata about attribute types) )
      Yukihiro Matsumoto wrote: ... Ruby's default argument mechanism makes it impossible to add the ``main return'' value as an extra argument of a...
    3. "stereotyping" (was: Strong Typing (Managing metadata about attribute types)
      On Fri, 21 Nov 2003 02:35:05 +0900, Sean O'Dell wrote: Forgive me for being boggled, Sean. That's typically the third thing that I do (after...
    4. "stereotyping" (was: Strong Typing (Managing metadata about attribute types) )
      On Thursday 20 November 2003 09:56 am, dblack@wobblini.net wrote: No has to just do it. But when people ask for something, it gets annoying to...
    5. "stereotyping" (was: Strong Typing (Managing metadataabout attribute types)
      Excuse that last post. It was an abandoned one that ended up getting accidentally sent. Chad On Thu, 20 Nov 2003, Chad Fowler wrote: #...
  3. #2

    Default Re: "stereotyping" thread

    Hi --

    On Thu, 20 Nov 2003, Wesley J Landaker wrote:
    > Why not just use empty modules for all this type-checking? This isn't
    Because class/module ancestry doesn't tell you about type. See the
    previous 120 messages or so :-)


    David

    --
    David A. Black
    [email]dblack@wobblini.net[/email]



    David A. Black Guest

  4. #3

    Default Re: "stereotyping" thread

    On Thu, 2003-11-20 at 18:05, Wesley J Landaker wrote:
    > Why not just use empty modules for all this type-checking? This isn't
    > very useful to me personally, but it seems to do everything that has
    > been mentioned in this whole "stereotyping" thread (i.e. emits warnings
    > if the passed in types haven't been manually tagged by a programmer as
    > implementing a particular interface):
    ROFL!!!

    It's nice to see minds thinking alike :-) My suggestion of exactly that
    sort of kicked off this thread! [Well, Sean O'Dell clearly had ideas
    that were much more thought out than mine].

    There are some flaws to it, though.

    The question "what interfaces does object Foo implement" can be answered
    by the "include module" approach, and that is a step forward - but just
    not big enough to go all the way.

    The fact that a method expects something obeying SomeInterface isn't in
    the method declaration, so it isn't easy for someone browsing the code
    to see. Nor is it easy to put into the rdoc-generated documentation. Nor
    can it be queried at runtime, ie "what interfaces are the parameters to
    this method expected to implement?".


    And the typing is enforced "hard". Austin has made a good case that Ruby
    type-checking should always be bypassable. Well, he actually suggests we
    are mad for wanting it at all, but I'll grant him this part of the
    argument at least.

    I suggested a command-line option to the ruby interpreter (or similar
    mechanism) control how "strictly" checks are done, with the default
    being "not at all". This cannot be done directly with the code you
    suggested. Yes some method like
    assert_implements(foo, SomeInterface)
    could go off and check the "strictness" level to determine whether to
    raise an exception or not, but that would have a significant performance
    hit even when typechecking is disabled.

    Some people also felt that "typing" should not be related to "class
    inheritance". I'm not so sure about that.

    So here I am rebutting my own suggestion proposed independently by
    someone else :-). I'm still hoping for someone to make a suggestion for
    a type info mechanism, though, by whatever approach.


    Cheers,

    Simon



    Simon Kitching Guest

  5. #4

    Default Re: "stereotyping" thread

    David A. Black wrote:
    > Hi --
    >
    > On Thu, 20 Nov 2003, Wesley J Landaker wrote:
    >
    >
    >>Why not just use empty modules for all this type-checking? This isn't
    >
    >
    > Because class/module ancestry doesn't tell you about type. See the
    > previous 120 messages or so :-)
    Ehh, I swore I'd stay out of this. But here I am.

    I think what Wesley is talking about is different. He's proposing (or
    not really proposing, since he's only asking "Why don't the people
    who want this do that?") -- as I understand it -- creating modules
    whose sole purpose is to identify the high-level properties of an
    object.

    And someone will say, "Yes, but I could mix in that module even if
    the object didn't have those properties."

    And someone else will say, "Yes, but that would be a BUG."

    And the never-ending thread goes on.

    "The thread goes ever, ever on,
    Down from the post where it began...."

    Hal




    Hal Fulton Guest

  6. #5

    Default Re: "stereotyping" thread

    On Thu, 20 Nov 2003 14:05:37 +0900, Wesley J Landaker wrote:
    > Why not just use empty modules for all this type-checking? This isn't
    > very useful to me personally, but it seems to do everything that has been
    > mentioned in this whole "stereotyping" thread (i.e. emits warnings if the
    > passed in types haven't been manually tagged by a programmer as
    > implementing a particular interface):
    This was suggested early on. Fundamentally, it's not much different than
    Sean O'Dell's RCR, and I think that it's as fragile.

    But your post does point out -- as does the existence of types.rb and
    StrongTyping -- that this need not be in the core of Ruby. It also
    demonstrates that even if it were in the core of Ruby, if it's not used,
    it's about as useful as pinkies on a Penguin.

    -austin
    --
    austin ziegler * [email]austin@halostatue.ca[/email] * Toronto, ON, Canada
    software designer * pragmatic programmer * 2003.11.20
    * 00.58.21



    Austin Ziegler Guest

  7. #6

    Default Re: "stereotyping" thread

    --Boundary-02=_DkFv/zVOHWsCwhV
    Content-Type: text/plain;
    charset="utf-8"
    Content-Transfer-Encoding: quoted-printable
    Content-Description: signed data
    Content-Disposition: inline

    On Wednesday 19 November 2003 10:33 pm, Hal Fulton wrote:
    > David A. Black wrote:
    > > Hi --
    > >
    > > On Thu, 20 Nov 2003, Wesley J Landaker wrote:
    > >>Why not just use empty modules for all this type-checking? This
    > >> isn't
    > >
    > > Because class/module ancestry doesn't tell you about type. See the
    > > previous 120 messages or so :-)
    >
    > Ehh, I swore I'd stay out of this. But here I am.
    Yeah, maybe I should have stayed out of it too. ;)
    > I think what Wesley is talking about is different. He's proposing (or
    > not really proposing, since he's only asking "Why don't the people
    > who want this do that?") -- as I understand it -- creating modules
    > whose sole purpose is to identify the high-level properties of an
    > object.
    That's right, Hal; I read through the previous 120 messages or so, and=20
    thought "I really don't want that, but for the people who do, and say=20
    they want features x, y, and z, why don't they just do this?".=20

    Bah, well, let's just pretend I didn't say anything. ;)
    > And someone will say, "Yes, but I could mix in that module even if
    > the object didn't have those properties."
    >
    > And someone else will say, "Yes, but that would be a BUG."
    >
    > And the never-ending thread goes on.
    (Completely off-topic, but more interesting to me):

    Sometime I'll have to post about my C++ preprocessor that lets you embed=20
    ruby in C++. Unlike other implementations I've seen, it's two-way --=20
    you can put variables in, and get them back out. ;)=20

    #include <stdio.h>
    #include <string>
    #include <iostream>
    using std::string;
    using std::cout;

    #include <inline_ruby.h>

    int main() {
    int x =3D 9;
    int y =3D 12;
    string s =3D "fooxar";
    printf("My favorite words are %s.\n",
    inline_ruby<string> { %{s}.sub('x','b') + " and " + "bar" });
    int z =3D inline_ruby<int> { %{x} + %{y} };
    inline_ruby { %{s} =3D "Hello, World!\n" }
    cout << s;
    Ruby::Value v =3D inline_ruby { Object.new }
    inline_ruby { p %{v} }
    }

    Ah, I need to package that up for release, it's lots of fun. =3D)
    > "The thread goes ever, ever on,
    > Down from the post where it began...."
    "This is the thread that never ends! ...
    Yes it goes on and on my friends! ..."

    =2D-=20
    Wesley J. Landaker - [email]wjl@icecavern.net[/email]
    OpenPGP FP: 4135 2A3B 4726 ACC5 9094 0097 F0A9 8A4C 4CD6 E3D2


    --Boundary-02=_DkFv/zVOHWsCwhV
    Content-Type: application/pgp-signature
    Content-Description: signature

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.3 (GNU/Linux)

    iD8DBQA/vFkD8KmKTEzW49IRApXVAJ0eIXa3Ebfei4WnnY7GYJr6Z6TjDw CfXEot
    2ugl4FMR47286sTCRE67fmU=
    =E07/
    -----END PGP SIGNATURE-----

    --Boundary-02=_DkFv/zVOHWsCwhV--

    Wesley J Landaker Guest

  8. #7

    Default inline_ruby (was: Re: "stereotyping" thread)

    From: "Wesley J Landaker" <wjl@icecavern.net>
    >
    > Sometime I'll have to post about my C++ preprocessor that lets you embed
    > ruby in C++. Unlike other implementations I've seen, it's two-way --
    > you can put variables in, and get them back out. ;)
    [...]
    > string s = "fooxar";
    > printf("My favorite words are %s.\n",
    > inline_ruby<string> { %{s}.sub('x','b') + " and " + "bar" });

    Wow! That's really neat!!

    > Ah, I need to package that up for release, it's lots of fun. =)
    I'm definitely eager to try it out !


    Regards,

    Bill




    Bill Kelly Guest

  9. #8

    Default Re: "stereotyping" thread

    Hi,

    In message "Re: "stereotyping" thread"
    on 03/11/20, Austin Ziegler <austin@halostatue.ca> writes:

    |This was suggested early on. Fundamentally, it's not much different than
    |Sean O'Dell's RCR, and I think that it's as fragile.

    Can you tell me where I can read his RCR? Probably I missed that.

    matz.

    Yukihiro Matsumoto Guest

  10. #9

    Default Re: "stereotyping" thread

    On Thu, 20 Nov 2003 16:38:13 +0900, Yukihiro Matsumoto wrote:
    > In message "Re: "stereotyping" thread"
    > on 03/11/20, Austin Ziegler <austin@halostatue.ca> writes:
    > |This was suggested early on. Fundamentally, it's not much different than
    > |Sean O'Dell's RCR, and I think that it's as fragile.
    > Can you tell me where I can read his RCR? Probably I missed that.
    It's on RubyGarden. It took me a while to figure out it was there, too :)
    I'm not in the habit of checking RG but a couple of times a day and then
    quickly skimming and closing the tab in Mozilla.

    -austin
    --
    austin ziegler * [email]austin@halostatue.ca[/email] * Toronto, ON, Canada
    software designer * pragmatic programmer * 2003.11.20
    * 03.11.33



    Austin Ziegler Guest

  11. #10

    Default Re: inline_ruby (was: Re: "stereotyping" thread)

    --Boundary-02=_AWMv/4LtVw5qNzf
    Content-Type: text/plain;
    charset="utf-8"
    Content-Transfer-Encoding: quoted-printable
    Content-Description: signed data
    Content-Disposition: inline

    On Thursday 20 November 2003 12:24 am, Bill Kelly wrote:
    > From: "Wesley J Landaker" <wjl@icecavern.net>
    >
    > > Sometime I'll have to post about my C++ preprocessor that lets you
    > > embed ruby in C++. Unlike other implementations I've seen, it's
    > > two-way -- you can put variables in, and get them back out. ;)
    >
    > [...]
    >
    > > string s =3D "fooxar";
    > > printf("My favorite words are %s.\n",
    > > inline_ruby<string> { %{s}.sub('x','b') + " and " + "bar" });
    >
    > Wow! That's really neat!!
    I wrote it specifically for use in a project, but I need to clean it up=20
    so that I'm not totally embarassed when I post code. ;) heh heh.=20
    (Actually, it works well, but I haven't used it in a while.)

    It really is cool, though. Right now it uses an embedded ruby=20
    interpreter. One possible TODO I'd perhaps like to try is to use the=20
    same interface, but make the backend communicate with ruby in another=20
    process. (It's a long story, but the reason behind that would be to be=20
    able to have multiple independant "embedded" ruby interpreters...=20
    something that last time I tried to do I gave up fairly quickly after=20
    seeing all the global variables!)
    > > Ah, I need to package that up for release, it's lots of fun. =3D)
    >
    > I'm definitely eager to try it out !
    I'd actually almost forgotten about it. I'll dig it back up, clean it=20
    up, and post more info here in a few days. (Err, unless I don't get to=20
    it before I go out of town for the thanksgiving holidy here in the=20
    US...) Okay, so, a few weeks. ;) I'll probably throw it on a subversion=20
    server here at icecavern, but I'll put the project page on rubyforge.

    =2D-=20
    Wesley J. Landaker - [email]wjl@icecavern.net[/email]
    OpenPGP FP: 4135 2A3B 4726 ACC5 9094 0097 F0A9 8A4C 4CD6 E3D2


    --Boundary-02=_AWMv/4LtVw5qNzf
    Content-Type: application/pgp-signature
    Content-Description: signature

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.3 (GNU/Linux)

    iD8DBQA/vMWA8KmKTEzW49IRAsUrAJ9Ytm5TQj+aBy8ikHbo8aBWOV3dng CcD/Ip
    YyvRb/xUcYVC3dP+CI2SWkE=
    =OG6n
    -----END PGP SIGNATURE-----

    --Boundary-02=_AWMv/4LtVw5qNzf--

    Wesley J Landaker Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139