symbols vs strings vs ?

J

Joe Van Dyk

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

Thanks,
Joe
 
A

Assaph Mehr

Joe said:
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
 
J

Joe Van Dyk

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top