Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
What is the difference between :foo and "foo" ?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Yohanes Santoso, post: 4498933"] Well, what can I say? Symbol is really meant to represent a name/identifier. Let's stop with analogies since obviously we are not analogy-compatible, and get on with the concretes. What is 1? A way to represent the number one. You said a way, what others are there? 0x1, \001, "1". However, one does not use "1" to represent the number one even if one doesn't plan to do any arithmetic operations on that number because that representation is ambiguous. Does he mean "1" as in number one or as in the character "1"? What is :server? A way to represent the name/identifier ``server``. What others are there? "server" is another one. But it is also ambigious. Does he mean the name/identifier ``server`` or the character sequence "s","e","r","v","e","r"? I can see no way to describe 1 without involving number. Similarly, I can see no way to describe :server without involving name/identifier. Perhaps you can. I really am not sure what you are saying there. That sentence describes what a symbol is. That sentence does not describe/prescribe how to use it. Here, let me paraphrase my sentence: "[Symbol is] a means for you, the programmer, to [represent the] name/identit[y] of entities". Did I manage to preserve the meaning? Let's do word substitution. "Number is a means for you, the programmer, to represent numbers". In no way am I describing/prescribing how to use instances of Number. This is precisely the kind of explanation that I objected when explaining what a symbol is to a newcomer. Any explanation that refer to the implementation is doomed to be short-lived. There are many ways to implement the class Symbol and the concept of symbol. Do you explain what number does behind the scenes to someone asking 'What is a number?' Do you explain that ruby maps number less than 2^31-1 directly to native integer format? Quick question, then: does this still hold on a 64-bit machine? How about in ruby 2.0? Will Number behave differently and is used to represent different thing there simply because what goes on behind the scene has changed? If one is interested in how something is implemented in a specific environment, one should ask for that (and there are posts in this thread dwelving into how Symbol is implemented in current ruby VM). In any case, if someone can give me a description of what 1 is without involving number, then I'll show you a description of what symbol is without involving name/identifier. YS. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
What is the difference between :foo and "foo" ?
Top