Is there a way to enforce UFCS?

H. S. Teoh hsteoh at qfbox.info
Thu Jan 5 17:43:55 UTC 2023


On Thu, Jan 05, 2023 at 02:32:17PM +0000, Dom DiSc via Digitalmars-d-learn wrote:
[...]
> I think this is really another usecase for @property: we should forbid the
> function call syntax for them (so one needs to use them like a variable).
[...]
> Properties are not functions. If you want a function, use a function. If
> @properties would be the same as functions, they are superfluous garbage.
> Either make something useful out of them or remove them.

We have been talking about deprecating and removing @property for years
now.  Somebody just has to bite the bullet and push it through the
deprecation process...

... OR come up with a DIP that implements @property in a sane, fully
worked out way, not the half-hearted, incomplete, leaky implementation
that it is today.

//

In my own code, I've stopped bothering with @property for the most part.
Parentheses are optional for argumentless functions in general anyway,
so there's really no need to write @property on anything. This works:

	struct S {
		private int _x;
		int x() { return _x; }
	}

	S s;
	int y = s.x;

The only significant thing @property does right now is to add confusion
when the unary & operator is used or when the property function returns
a delegate.  Not worth the trouble, I say.  Just don't use @property at
all, plain old member functions work just fine.


T

-- 
Some ideas are so stupid that only intellectuals could believe them. -- George Orwell


More information about the Digitalmars-d-learn mailing list