On Monday, 2 December 2013 at 07:31:56 UTC, Sergei Nosov wrote:
On Monday, 2 December 2013 at 05:57:33 UTC, CJS wrote:
I was reading the enum page of Ali Çehreli's (excellent) D book (http://ddili.org/ders/d.en/enum.html), and I'm confused by an enum value (not enum type), such as
  enum secondsPerDay = 60 * 60 * 24;
In that situation I would have used an immutable variable. Is there any reason to prefer enum vs. immutable when defining constants?

enum is a compile-time constant and an immutable variable is not.

As an example, in order to create a enum variable you have to know it's value at compile time, e.g. you can't read it from file. On the contrary, you can read a string from file and string is the same thing as immutable(char) in D.

Typo - "the string is the same thing as immutable(char)[]" in D (note the rectangular braces)

Reply via email to