Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > why doesn't ruby have generics?

Reply
Thread Tools

why doesn't ruby have generics?

 
 
thufir
Guest
Posts: n/a
 
      04-19-2008
Is it because Ruby is dynamic, or something else?


-Thufir


 
Reply With Quote
 
 
 
 
Arlen Cuss
Guest
Posts: n/a
 
      04-19-2008
[Note: parts of this message were removed to make it a legal post.]

Hi,

On Sat, Apr 19, 2008 at 7:58 PM, thufir <(E-Mail Removed)> wrote:

> Is it because Ruby is dynamic, or something else?



Well.. there's no explicit typing anywhere, so the concept of a `generic'
makes no sense. *Everything* is generic, as far as duck-typing works.

Think of an example of a generic in C#, C++,
any-other-language-that-has-them-I-don't-know -- the code works generically
in Ruby, too! Look up `duck typing' to get an idea about it.

Cheers,
Arlen

 
Reply With Quote
 
 
 
 
Florian Gilcher
Guest
Posts: n/a
 
      04-19-2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Apr 19, 2008, at 11:58 AM, thufir wrote:

> Is it because Ruby is dynamic, or something else?
>
>
> -Thufir
>
>


Why would you bind to a type in a language that doesn't really
care about types? Otherwise, it is easy to implement such
functionality - just build a new kind of array that has to be
constructed with a class. Check for this class on insertion.
I don't see the use, though.

Regards,
Florian Gilcher
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkgJxCEACgkQJA/zY0IIRZYhXQCcDqUzhMN7cWJoYivpAXjx8s22
ZnwAn2VxHriGauNMTNod/uNtZNh76a9+
=JY6m
-----END PGP SIGNATURE-----

 
Reply With Quote
 
Marc Heiler
Guest
Posts: n/a
 
      04-19-2008
> Is it because Ruby is dynamic, or something else?

Maybe it first needs to be described which specific advantage a
'generic' type has (or would have).
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      04-19-2008
On 19.04.2008 12:06, Florian Gilcher wrote:
> On Apr 19, 2008, at 11:58 AM, thufir wrote:
>
>> Is it because Ruby is dynamic, or something else?


> Why would you bind to a type in a language that doesn't really
> care about types? Otherwise, it is easy to implement such
> functionality - just build a new kind of array that has to be
> constructed with a class. Check for this class on insertion.
> I don't see the use, though.


That would be a type restricted Array but not a generic Array. You
cannot have generics in a language whose variables are typeless as Arlen
pointed out.

Cheers

robert
 
Reply With Quote
 
Florian Gilcher
Guest
Posts: n/a
 
      04-19-2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Apr 19, 2008, at 1:45 PM, Robert Klemme wrote:

> On 19.04.2008 12:06, Florian Gilcher wrote:
>> On Apr 19, 2008, at 11:58 AM, thufir wrote:
>>> Is it because Ruby is dynamic, or something else?

>
>> Why would you bind to a type in a language that doesn't really
>> care about types? Otherwise, it is easy to implement such
>> functionality - just build a new kind of array that has to be
>> constructed with a class. Check for this class on insertion.
>> I don't see the use, though.

>
> That would be a type restricted Array but not a generic Array. You
> cannot have generics in a language whose variables are typeless as
> Arlen pointed out.
>
> Cheers
>
> robert
>


Yeah, thats why I was talking about "such functionality". It would
serve the same purpose. I was not clear enough about that.

Greetings,

Florian Gilcher
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkgJ38sACgkQJA/zY0IIRZYWqACfaOXjJxZ1XqBjiTRLdQgQKjYp
ObQAoMiQmOh2xnbJPvi9bRPcxpaM3MJo
=CQU6
-----END PGP SIGNATURE-----

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      04-19-2008
On 19.04.2008 14:04, Florian Gilcher wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> On Apr 19, 2008, at 1:45 PM, Robert Klemme wrote:
>
>> On 19.04.2008 12:06, Florian Gilcher wrote:
>>> On Apr 19, 2008, at 11:58 AM, thufir wrote:
>>>> Is it because Ruby is dynamic, or something else?
>>> Why would you bind to a type in a language that doesn't really
>>> care about types? Otherwise, it is easy to implement such
>>> functionality - just build a new kind of array that has to be
>>> constructed with a class. Check for this class on insertion.
>>> I don't see the use, though.

>> That would be a type restricted Array but not a generic Array. You
>> cannot have generics in a language whose variables are typeless as
>> Arlen pointed out.

>
> Yeah, thats why I was talking about "such functionality". It would
> serve the same purpose. I was not clear enough about that.


For practical purposes you are probably right. But strictly speaking
there is a difference: Java Generics basically are a mechanism for
automated casting. This is something else than restricting the type of
items you put into a collection. (You can sneak an Integer into a
List<String> in Java.)

C++ templates are a completely different story - although they "look"
pretty similar to Java's Generics. C++ templates allow for generic
programming which is something different altogether.

In Ruby you can do neither: you cannot cast because variables are
typeless. And you cannot have generic algorithms for the same reason.

Kind regards

robert
 
Reply With Quote
 
Pascal Bourguignon
Guest
Posts: n/a
 
      04-19-2008
thufir <(E-Mail Removed)> writes:

> Is it because Ruby is dynamic, or something else?


Mu.

All the methods of Ruby are generic.


--
__Pascal Bourguignon__ http://www.informatimago.com/

THIS IS A 100% MATTER PRODUCT: In the unlikely event that this
merchandise should contact antimatter in any form, a catastrophic
explosion will result.
 
Reply With Quote
 
Joseph Lenton
Guest
Posts: n/a
 
      04-19-2008
thufir wrote:
> Is it because Ruby is dynamic, or something else?
>
>
> -Thufir


As far as I've understood it, in Ruby it's not about what the type is
but what the type can do. i.e. does it respond to a specific method. So
maybe generics in Ruby would make sense if you could restrict objects
based on what they can do. For example an array which can only hold
obejct that respond to the to_str method.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
thufir
Guest
Posts: n/a
 
      04-20-2008
On Sun, 20 Apr 2008 07:49:02 +0900, Joseph Lenton wrote:

> As far as I've understood it, in Ruby it's not about what the type is
> but what the type can do. i.e. does it respond to a specific method. So
> maybe generics in Ruby would make sense if you could restrict objects
> based on what they can do. For example an array which can only hold
> obejct that respond to the to_str method.


Right; I'm taking a Java course which will be covering Generics and, in
Java, this a big part of the point of Generics:

an array which can only hold objects which implement a specified
interface.


-Thufir


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I have tabs in ff enabled. Why won't it let me have more than R. audit2 Firefox 1 09-25-2011 03:10 AM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Why I have error message "not have an entry point defined"? =?Utf-8?B?ZGF2aWQ=?= ASP .Net 6 08-18-2005 11:09 AM



Advertisments