Ask a Question related to Ruby, Design and Development.
-
Wesley J Landaker #1
"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
-
"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... -
"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... -
"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... -
"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... -
"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: #... -
David A. Black #2
Re: "stereotyping" thread
Hi --
On Thu, 20 Nov 2003, Wesley J Landaker wrote:
Because class/module ancestry doesn't tell you about type. See the> Why not just use empty modules for all this type-checking? This isn't
previous 120 messages or so :-)
David
--
David A. Black
[email]dblack@wobblini.net[/email]
David A. Black Guest
-
Simon Kitching #3
Re: "stereotyping" thread
On Thu, 2003-11-20 at 18:05, Wesley J Landaker wrote:
ROFL!!!> 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):
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
-
Hal Fulton #4
Re: "stereotyping" thread
David A. Black wrote:
Ehh, I swore I'd stay out of this. But here I am.> 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 :-)
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
-
Austin Ziegler #5
Re: "stereotyping" thread
On Thu, 20 Nov 2003 14:05:37 +0900, Wesley J Landaker wrote:
This was suggested early on. Fundamentally, it's not much different than> 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):
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
-
Wesley J Landaker #6
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:Yeah, maybe I should have stayed out of it too. ;)> 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.
That's right, Hal; I read through the previous 120 messages or so, and=20> 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.
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. ;)
(Completely off-topic, but more interesting to me):> 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.
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)
"This is the thread that never ends! ...> "The thread goes ever, ever on,
> Down from the post where it began...."
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
-
Bill Kelly #7
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!!
I'm definitely eager to try it out !> Ah, I need to package that up for release, it's lots of fun. =)
Regards,
Bill
Bill Kelly Guest
-
Yukihiro Matsumoto #8
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
-
Austin Ziegler #9
Re: "stereotyping" thread
On Thu, 20 Nov 2003 16:38:13 +0900, Yukihiro Matsumoto wrote:
It's on RubyGarden. It took me a while to figure out it was there, too :)> 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.
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
-
Wesley J Landaker #10
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:I wrote it specifically for use in a project, but I need to clean it up=20> 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!!
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!)
I'd actually almost forgotten about it. I'll dig it back up, clean it=20>> > Ah, I need to package that up for release, it's lots of fun. =3D)
> I'm definitely eager to try it out !
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



Reply With Quote

