From: Marek Janukowicz Date: 2003-06-03T02:07:38+09:00 Subject: Re: Advantages of Symbols over constants On Mon, 2 Jun 2003 10:23:16 +0900, Jim Weirich wrote: >> One advantage of symbols is that they know how to print themselves, but >> you can of course get this advantage with constants that refer to symbols: >> >> UP = :up >> DOWN = :down >> >> x = UP >> puts "You are going #{x}" >> >> Another advantage with constants is that, if you want to change the >> value, there's only one spot in the code to change and you don't break >> the API. > Well, yes ... but I imagine that in the cases we are talking about the > actual value of the constant is irrelevant. In fact, if I were to use > constants, I would consider doing ... > > UP = Object.new > DOWN = Object.new Isn't it better to do eg. UP = 1 DOWN = 2 This way you don't create new (and in fact unnecessary) objects. > Now I can't accidently use :up or :down in my code. I _must_ use the > constant. > > Since the value is unimportant, changing the value is unlikely. > However, it is possible that I later decide the constants should be > named TOP and BOTTOM instead of UP and DOWN. And this is a problem for > both symbols and constants equally. I read what you and the others wrote and I am now even more convinced I should use constants in my program. Thanks for all answers -- Marek Janukowicz