tags:

views:

133

answers:

1

Some time ago I had a look into Ruby and one of the things which stood out most for me was the way of using symbols.

While you to use defines or strings like in C++ or Python as an alternative, in Ruby you just write :mySymbol and the interpreter takes over the enumeration for you.

  • I can't see any disadvantage this feature has, so why is it missing in say, PHP and Python?
A: 

One reason is that it's not as straightforward to implement in a compiled language such as C++.

Another one is that non-predefined symbols make it difficult to validate values on compile time. Having to pre-define the values prevents typos later, because they produce a compile-time error.

Matti Virkkunen
Why do you answer the question, if you vote to close it as subjective and argumentative?
3lectrologos
Maybe he expected to even gain some rep for it?
dada
@3lectrologos: I'm sorry, my hand must've slipped. Nah, to be honest, I just wanted to mention a few reasons why it's technically difficult to implement those features in e.g. C++, which is not really subjective. @dada: I can't get any more today :(
Matti Virkkunen