Using closure in function scope to make "real" private class members
forkit
forkit at gmail.com
Wed Jun 8 11:04:45 UTC 2022
On Wednesday, 8 June 2022 at 10:30:59 UTC, Ola Fosheim Grøstad
wrote:
>
> Anything simple is better than @keyword, private(this), private
> class etc. Such syntax screams "amateur project" and I wouldn't
> even consider downloading a language like that. When I first
> tried D it was because the syntax looked clean (way before the
> @madness caught on).
It can't be: 'private this()' because that conflicts with the use
of the word 'this' that is associated with a constructor.
'private (this)' makes perfect sense to me.
First, the word 'this' is already associated "to the object,
class, or other entity of which the currently running code is a
part." - https://en.wikipedia.org/wiki/This_(computer_programming)
Second. The exact same syntax can be used for class or struct.
One could argue that 'private (this)' and 'private this()' are
too close syntactically, and could cause confusion. I wouldn't
disagree. But I'd be fine with it, since I'd be using it so
often, it'll be programmed into my muscle memory ;-)
More information about the Digitalmars-d
mailing list