[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: symbols vs strings vs ?

e

2/3/2005 1:54:00 AM

> Lähettäjä: Joe Van Dyk <joevandyk@gmail.com>
> Aihe: Re: symbols vs strings vs ?
>
> 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.

Always use a Symbol rather than a String, except if you
need to be able to print the string to file/screen/etc.

E



1 Answer

James Gray

2/3/2005 2:41:00 AM

0

On Feb 2, 2005, at 7:53 PM, E S wrote:

> Always use a Symbol rather than a String, except if you
> need to be able to print the string to file/screen/etc.

Hmm, don't think I agree with that. What it you need to modify its
contents? What if you want to use some of String's many helper
methods?

James Edward Gray II