Declaring a single const: enum vs const vs immutable

monkyyy crazymonkyyy at gmail.com
Wed Sep 10 17:15:16 UTC 2025


On Wednesday, 10 September 2025 at 16:52:51 UTC, Brother Bill 
wrote:
> Is there any reason to pick one of these vs. another one, or 
> are they all equivalent?
>
> If equivalent, it would seem that immutable appears to be the 
> 'strongest', whereas enum has fewer keystrokes.
>
> Is there a D 'best practice' for this?
>
> ```
> 	const int foo1 = 42;
> 	enum foo2 = 42;
> 	immutable int foo3 = 42;
>
> 	const string str1 = "Any difference";
> 	enum str2 = "Any difference";
> 	immutable string str3 = "Any difference";
>
> ```

I just do always enum; going all in on compile time abstractions


More information about the Digitalmars-d-learn mailing list