What is the current state of scope and member functions?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Sep 12 09:52:58 UTC 2023


On Tuesday, September 12, 2023 3:26:02 AM MDT Dennis via Digitalmars-d wrote:
> On Monday, 11 September 2023 at 00:12:29 UTC, Jonathan M Davis
> > AFAIK, no other attributes magically disappear like that.
>
> __gshared and shared disappear on immutable variables.

That's only because they're redundant given that immutable is implicitly
shared. It would be like how const disappears on a template parameter when
the type itself is already const - e.g. const(T) being const(int) when T is
const(int). So, they don't really disappear, and what's happening is very
obvious based on the types. This is in stark contrast to scope just outright
disappearing even though it's explicitly used just because the compiler
decided that there were no indirections. There is logic to it disappearing
when there are no indirections, since it doesn't really do anything, but
it's not at all intuitively obvious that that's how things would work,
whereas with double consts or shared immutable, the redundant attribute
basically has to go away, so it's far less surprising or confusing.

> > DIP 1000 is already arguably overly complicated for what it
> > buys us, and I'd think that removing unnecessary complexity
> > with regards to what's going on with scope would be a good
> > thing.
>
> We could try remove it.

Given the incredible complexity that DIP 1000 has, I really think that
inconsistencies like this should be removed. Honestly, I have a hard time
believing that DIP 1000 is going to go over well in the long run if it stays
anywhere near as complex as it is. IMHO, it's currently well beyond what the
average programmer is going to reasonably be able to understand, and my gut
reaction is that it would be better to just slap @trusted in a bunch of
places to shut the compiler up about scope than it would be to try to
actually make it work - though unfortunately, that's not going to work very
well with templated code (particularly in libraries), which is precisely
where I'm seeing the compiler complain about scope even though I'm not doing
stuff like taking the address of local variables.

So, anything that can be done to reduce the complexity (particularly
unnecessary complexity) and reduce the number of special cases is likely to
be a good thing. And having parameters and this parameters behave
differently with regards to scope seems unnecessarily confusing.

- Jonathan M Davis





More information about the Digitalmars-d mailing list