IronRuby and XNA. Super and Generics

I like Tomas’s idea the best. Generics are not native to Ruby, so most
people using them will likely have a C#/VB background, which means
Tomas’s
syntax would be more familiar.

The “_of” syntax isn’t bad, but forcing a “.do” or “.call” at the end
isn’t
ideal, even if it does have a bit of a Ruby flavor.

Adding a “.of()” to the class is okay, but many classes may have generic
methods even when the class itself is not a generic. (I’m thinking
primarily
of static and extension method classes here.)

Passing the generic types as the first parameters seems the most
explicit
and understandable translation to me.

~ Ryan

On Fri, Jan 9, 2009 at 3:12 PM, Jimmy S. <


Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core

Let’s let Tomas implement
content.method(:load).of(Texture2D).call(“mytexture”) … and then we
can play around with the different syntax in context. Then it’s
pick-the-syntax-you-want =)

From: [email protected]
[mailto:[email protected]] On Behalf Of Ryan R.
Sent: Friday, January 09, 2009 1:51 PM
To: [email protected]
Subject: Re: [Ironruby-core] Generic method synxtax

I like Tomas’s idea the best. Generics are not native to Ruby, so most
people using them will likely have a C#/VB background, which means
Tomas’s syntax would be more familiar.

The “_of” syntax isn’t bad, but forcing a “.do” or “.call” at the end
isn’t ideal, even if it does have a bit of a Ruby flavor.

Adding a “.of()” to the class is okay, but many classes may have generic
methods even when the class itself is not a generic. (I’m thinking
primarily of static and extension method classes here.)

Passing the generic types as the first parameters seems the most
explicit and understandable translation to me.

~ Ryan
On Fri, Jan 9, 2009 at 3:12 PM, Jimmy S.
<[email protected]mailto:[email protected]>
wrote:

Here are the ideas that stand out to me:

I like Tomas’s idea, since it reads like C#/VB, but adding an argument
to the front urks me:

content.load of(Texture2D), “mytexture”

Shri, having the “_of” appended to a generic method name and requiring a
“.do” after it is how you would work with lambdas (except you do
“.call”), but since we’re talking about .NET methods, not .NET
delegates. So, I’d like the syntax to look more like a method call.
Also, as Tomas says, mangling gets more complicated …

content.load_of(Texture2D).call “mytexture”

How about adding an “of” method to the class/object, to put the class in
a generic “mode”? The method probably shouldn’t be called “of”, but you
get the idea. It reads different than C#, but seems the most Rubyesk
without changing the arguments.

content.of(Texture2D).load “mytexture”

Thoughts? If no one likes my idea, I think Tomas’s is a fine compromise.

~js


Ryan R.
[email protected]mailto:[email protected]
http://panesofglass.org/
http://wizardsofsmart.net/

How would this look for instantiating a generic object?

my_object = Foo.method(:new).of(Bar).call

That seems strange. Perhaps we need to possibilities: the above for
generic
methods and the following for generic classes:

my_object = Foo.of(Bar).new

where Foo would be defined as Foo in C#

my_clone = my_object.clone

where clone would have a C# signature of T Clone()

or should that be:

my_clone = my_object.method(:clone).of(Bar).call?

and allow my_object.clone to have an overloaded

C# signature of object Clone()?

~Ryan

On Fri, Jan 9, 2009 at 3:45 PM, Tomas M.
<[email protected]

Generic types already work:

List = List.of(Object).new

Tomas

From: [email protected]
[mailto:[email protected]] On Behalf Of Ryan R.
Sent: Friday, January 09, 2009 2:33 PM
To: [email protected]
Subject: Re: [Ironruby-core] Generic method synxtax

How would this look for instantiating a generic object?

my_object = Foo.method(:new).of(Bar).call

That seems strange. Perhaps we need to possibilities: the above for
generic methods and the following for generic classes:

my_object = Foo.of(Bar).new

where Foo would be defined as Foo in C#

my_clone = my_object.clone

where clone would have a C# signature of T Clone()

or should that be:

my_clone = my_object.method(:clone).of(Bar).call?

and allow my_object.clone to have an overloaded

C# signature of object Clone()?

~Ryan
On Fri, Jan 9, 2009 at 3:45 PM, Tomas M.
<[email protected]mailto:[email protected]>
wrote:

Mine has also an issue that just occurred to me. If you do:

class C

content.load of(Texture2D), “foo”

end

“of” resolves to Module#of which would return a C if C was a
generic type or throws an exception.

So that’s not good either. We would need a different method name for
generic method constructor than for generic type. Maybe “method_of”?

As for your idea:

content.of(T).load

is looks backwards. The content is not of T… the load is. I think this
would be confusing.

Until we figure out some nice clean solution that works in 100% cases, I
would implement the following as the first step for generic method
support:

content.method(:load).of(Texture2D).call(“mytexture”)

(Note, you can do the same in Ruby for regular methods:
“foo”.method(:center).call(100))

anything else is just a convenience and anyone could define it via
standard Ruby means.

Tomas


Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core

Foo.of(Bar).new works today … since it’s about instantiating generic
types … this discussion was only about generic methods.

From: [email protected]
[mailto:[email protected]] On Behalf Of Ryan R.
Sent: Friday, January 09, 2009 2:33 PM
To: [email protected]
Subject: Re: [Ironruby-core] Generic method synxtax

How would this look for instantiating a generic object?

my_object = Foo.method(:new).of(Bar).call

That seems strange. Perhaps we need to possibilities: the above for
generic methods and the following for generic classes:

my_object = Foo.of(Bar).new

where Foo would be defined as Foo in C#

my_clone = my_object.clone

where clone would have a C# signature of T Clone()

or should that be:

my_clone = my_object.method(:clone).of(Bar).call?

and allow my_object.clone to have an overloaded

C# signature of object Clone()?

~Ryan
On Fri, Jan 9, 2009 at 3:45 PM, Tomas M.
<[email protected]mailto:[email protected]>
wrote:

Mine has also an issue that just occurred to me. If you do:

class C

content.load of(Texture2D), “foo”

end

“of” resolves to Module#of which would return a C if C was a
generic type or throws an exception.

So that’s not good either. We would need a different method name for
generic method constructor than for generic type. Maybe “method_of”?

As for your idea:

content.of(T).load

is looks backwards. The content is not of T… the load is. I think this
would be confusing.

Until we figure out some nice clean solution that works in 100% cases, I
would implement the following as the first step for generic method
support:

content.method(:load).of(Texture2D).call(“mytexture”)

(Note, you can do the same in Ruby for regular methods:
“foo”.method(:center).call(100))

anything else is just a convenience and anyone could define it via
standard Ruby means.

Tomas

Oops! Sorry for being a bit behind!

On Fri, Jan 9, 2009 at 5:37 PM, Jimmy S. <