ACLs for variables - lock / unlock idea
Cecil Ward
d at cecilward.com
Fri Sep 29 13:42:42 UTC 2017
On Friday, 29 September 2017 at 13:07:32 UTC, Atila Neves wrote:
> auto modifiable = foo();
> {
> const nonModifiable = modifiable;
> //...
> }
I had already thought about using two names.
I don’t think that using a kind of ‘const-alias’ mechanism (or
‘const reference’, in the C++ var& sense) would be a good idea at
all. By this I mean something where a modifiable variable has two
names, only of of them permitting write access. The reason why
this wouldn’t be good enough is that there would be nothing much
stopping me from forgetting what I’m doing and going back to
using the wrong name at some point, without any warnings. Slight
mitigation would be if the original declaration was something
like myvar_writeable and the const alias for it was called simply
myvar, so that the default brain-free form would be the safe one
and you would have to go out of your way to get write access. It
still wouldn’t be that strong though.
Iirc you get told off if you block access to variables by using
‘shadowing’, declaring an exactly matching name using an alias
declaration in a normal basic block scope. (I suspect you can do
so inside function bodies, I don’t think d moans about you
blocking access to matching variables that are in global or
outer, non-global, non-local scopes if you write ‘shadowing’
local variable declarations - not sure.) Anyway, couldn’t use
that either and it’s no way usable enough for me.
More information about the Digitalmars-d
mailing list