C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Real World Programming, private = public

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sat, 2 Sep 2023 12:41:45 -0400
On Sat, Sep 2, 2023 at 12:22 PM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On Sat, Sep 2, 2023 at 4:18 PM Jason McKesson wrote:
> >
> > You keep talking about syntax as though that was the problem. It isn't.
> >
> > You are asking to be able to trivially bypass access controls. That's
> > the feature you want.
> >
> > That is not a thing the language should provide. It renders access
> > controls essentially meaningless. The syntax by which it is provided
> > is irrelevant when the *functionalty itself* is a bad idea.
>
> Computer programmers are one of very few kinds of technical worker in
> which this attitude is pervasive.
>
> You can have a tight system in place, adhere to that system and abide
> by its stipulations thoroughly, and yet _still_ provide a means to
> circumvent the system in the event of a corner case.

If you lock a door but put a sign up saying that the key is under the
mat, the door is *functionally* unlocked. Protections are only as good
as the means to circumvent them.

Features you add to the language will be used against whatever purpose
you added them to the language for. If you give everyone a trivially
accessible key to an object's privates, people *will use them*
whenever access controls make their lives even slightly more
difficult.

> You also seem to have no concept of harm reduction.

I guess that depends on how you define "harm".

When a programmer declares something private, what they're saying is
that it should not be accessed by code outside of their control. Why?
One reason is that it is *subject to change*. By declaring something
private, they're saying that they reserve the right to change it, but
in a way that is compatible with the class's public interface.

By accessing something you aren't supposed to, you are denying that
programmer the right to change it. If they change it, now everyone who
accessed those privates gets broken. Which restricts their ability to
change it. It forces people to use the Pimpl idiom just to prevent
people from inhibiting their ability to later modify their own code.

I consider that to be "harm". Therefore, your feature suggestion does
not reduce "harm"; it exacerbates it.

> C++ programmers around the world today are typing out "#define private public".

Programmers doing bad things is not a good reason to add a language
feature. Also, that's a good argument for further adoption of modules,
since it renders this linguistically impossible.

Lastly, [citation needed]. Like, I'm sure that *some* programmers have
done that. But what makes you think that this is a tool that is in
even mildly significant use/demand?

Received on 2023-09-02 16:41:57