[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

symbols vs strings vs ?

Joe Van Dyk

2/3/2005 12:27:00 AM

Any rules or guidelines on when to use symbols vs strings? I'm not
sure as to the advantages of using symbols.

Thanks,
Joe


2 Answers

Assaph Mehr

2/3/2005 12:33:00 AM

0


Joe Van Dyk wrote:
> Any rules or guidelines on when to use symbols vs strings? I'm not
> sure as to the advantages of using symbols.

Symbols are immutable strings. Every occurence of the same symbol
correspondes to the same single object, while every occurence of the
same string is a different object (with the same value). Thus symbols
are a bit faster and cheaper to use in things like case statements,
hash keys etc.
It's also usually a bit nicer to read in the code, as it signifies that
what you're looking it at is a unique identifier, rather than something
that can have a dynamic content.

HTH,
Assaph

Joe Van Dyk

2/3/2005 12:44:00 AM

0

On Thu, 3 Feb 2005 09:35:41 +0900, Assaph Mehr <assaph@gmail.com> wrote:
>
> Joe Van Dyk wrote:
> > Any rules or guidelines on when to use symbols vs strings? I'm not
> > sure as to the advantages of using symbols.
>
> Symbols are immutable strings. Every occurence of the same symbol
> correspondes to the same single object, while every occurence of the
> same string is a different object (with the same value). Thus symbols
> are a bit faster and cheaper to use in things like case statements,
> hash keys etc.
> It's also usually a bit nicer to read in the code, as it signifies that
> what you're looking it at is a unique identifier, rather than something
> that can have a dynamic content.
>
> HTH,
> Assaph

It did help! Thanks.