"stereotyping" thread

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):

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
regard…

···


Wesley J. Landaker - wjl@icecavern.net
OpenPGP FP: 4135 2A3B 4726 ACC5 9094 0097 F0A9 8A4C 4CD6 E3D2

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 :slight_smile:

David


David A. Black
dblack@wobblini.net

ROFL!!!

It’s nice to see minds thinking alike :slight_smile: 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

···

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):

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

···

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):


austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.11.20
* 00.58.21

David A. Black wrote:

Hi –

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 :slight_smile:

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

···

On Thu, 20 Nov 2003, Wesley J Landaker wrote:

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.

David A. Black wrote:

Hi –

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 :slight_smile:

Ehh, I swore I’d stay out of this. But here I am.

Yeah, maybe I should have stayed out of it too. :wink:

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
thought “I really don’t want that, but for the people who do, and say
they want features x, y, and z, why don’t they just do this?”.

Bah, well, let’s just pretend I didn’t say anything. :wink:

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
ruby in C++. Unlike other implementations I’ve seen, it’s two-way –
you can put variables in, and get them back out. :wink:

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

#include <inline_ruby.h>

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

Ah, I need to package that up for release, it’s lots of fun. =)

“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! …”

···

On Wednesday 19 November 2003 10:33 pm, Hal Fulton wrote:

On Thu, 20 Nov 2003, Wesley J Landaker wrote:


Wesley J. Landaker - wjl@icecavern.net
OpenPGP FP: 4135 2A3B 4726 ACC5 9094 0097 F0A9 8A4C 4CD6 E3D2

It’s on RubyGarden. It took me a while to figure out it was there, too :slight_smile:
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

···

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.


austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.11.20
* 03.11.33

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. :wink:
[…]
string s = “fooxar”;
printf(“My favorite words are %s.\n”,
inline_ruby { %{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

···

From: “Wesley J Landaker” wjl@icecavern.net

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. :wink:

[…]

string s = “fooxar”;
printf(“My favorite words are %s.\n”,
inline_ruby { %{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
so that I’m not totally embarassed when I post code. :wink: heh heh.
(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
interpreter. One possible TODO I’d perhaps like to try is to use the
same interface, but make the backend communicate with ruby in another
process. (It’s a long story, but the reason behind that would be to be
able to have multiple independant “embedded” ruby interpreters…
something that last time I tried to do I gave up fairly quickly after
seeing all the global variables!)

Ah, I need to package that up for release, it’s lots of fun. =)

I’m definitely eager to try it out !

I’d actually almost forgotten about it. I’ll dig it back up, clean it
up, and post more info here in a few days. (Err, unless I don’t get to
it before I go out of town for the thanksgiving holidy here in the
US…) Okay, so, a few weeks. :wink: I’ll probably throw it on a subversion
server here at icecavern, but I’ll put the project page on rubyforge.

···

On Thursday 20 November 2003 12:24 am, Bill Kelly wrote:


Wesley J. Landaker - wjl@icecavern.net
OpenPGP FP: 4135 2A3B 4726 ACC5 9094 0097 F0A9 8A4C 4CD6 E3D2