Const and enum optimizations

Jonathan M Davis jmdavisProg at gmx.com
Thu Jan 3 13:46:48 PST 2013


On Thursday, January 03, 2013 13:34:16 Ali Çehreli wrote:
> On 01/03/2013 07:58 AM, Phil Lavoie wrote:
> > header.c:
> > #define MY_CONST 1
> > ...
> > module.d:
> > enum {
> > MY_CONST = 1
> > }
> 
> Further, there is no need for that anonymous scope in D:
> 
> enum MY_CONST = 1;
> 
> Even further, I am one of those who reserve all capitals to macros.
> Since there are no macros in D, this is my choice:
> 
> enum myConst = 1;
> 
> I know that there are others who use all capitals for manifest constants
> but I fail to see the benefit of doing that. Nobody wants to or able to
> modify constants anyway. :)

Phobos's style guidelines prohibit all caps. Manifest constants are camelCased 
just like variables and functions are. So, the standard library doesn't have 
anything which is all caps unless it's old code and doesn't follow Phobos' 
current style guidelines.

Personally, I think that all caps is hideous. It makes sense in C/C++ for 
macros due to how the preprocessor works, but it's completely unnecessary in 
D. I'm sure that some people still use all caps though.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list