IDEA: Use Unix-style chmod values for const and invariant

Chad J gamerChad at _spamIsBad_gmail.com
Thu Nov 29 11:19:51 PST 2007


Russell Lewis wrote:
> Ok, I was pondering, trying to figure out some sort of syntax which 
> would allow us to communicate "const" and "invariant" in a way that's 
> easy to learn & remember.  Maybe we could learn from UNIX file 
> permissions, where you can see both the owner's permissions to the file, 
> and "other's" permissions.  In that case, we have these comparisons:
> 
> const:        rw-r--r--
> invariant:    r--r--r--
> 
> Which leads me to this concept for alternative keywords:
> 
> const:        const_wr
> invariant:    const_rr
> 
> Sure, the first time that a C++ programmer sees this, he won't know 
> exactly what it means, but it is (IMHO) easy to learn & remember.

I think I like where this is going.  Of course, I like any attempt to 
generalize const into something more useful and maybe not so horribly 
named.

I am having a bit of a problem making sure I understand the analogy 
though.  So who is the "owner"?  I'm guessing it's the variable being 
declared.  Then who is "user" and "group"?  I'm guessing those are 
subsumed into one entity who is other variables that reference this data.

I suppose 'w' means read-write, not write only.  Also, 'r' means 
read-only.  The one on the left is the owner/decl, the one on the right 
is the user/group/others.

Now just drop the horribly misleading term "const".  Also, the 
underscore doesn't jive with me.

const     -> accesswr
invariant -> accessrr

Perhaps better can be done than "access".  Maybe we can resurrect the 
notion of head and tail constness.

const     -> tailwr
invariant -> tailrr

More rambling (by me) is possible as well.  ;)



More information about the Digitalmars-d mailing list