With the proposed module system, it becomes feasible for small projects to adopt the single file approach and forego writing a separate file for an interface. With the single file approach, class members won’t necessarily be grouped by access (because it’s no longer being written just for a user). However it’s fairly cumbersome and error prone to frequently change access types with the current access specifier system, and it adds a lot of noise to the code.
E.g:
class MyClass {
public:
void somethingPublic() { }
private:
void somethingPrivate() { }
public:
void anotherPublicThing() { }
};
I propose being able to write that as:
class MyClass {
public void somethingPublic() { }
private void somethingPrivate() { }
public void anotherPublicThing() { }
};
Writing the specificer on the same line with a colon is an error-prone abuse of syntax; it isn’t immediately obvious that the specifier applies to more than just the declaration that it shares a line with.
It’d work like it does in every other language: following declarations will be unaffected.
The current access specifier system makes a lot of sense due to the common practice of writing out the interface for a class separately in a header file. Header files tend to be written for potential users of the class: public stuff at the top (since that’s what users will be using), then protected and finally private. Being able to write “public:” once at the top and have all following declarations made automatically public is very convenient.
With the proposed module system, it becomes feasible for small projects to adopt the single file approach and forego writing a separate file for an interface. With the single file approach, class members won’t necessarily be grouped by access (because it’s no longer being written just for a user). However it’s fairly cumbersome and error prone to frequently change access types with the current access specifier system, and it adds a lot of noise to the code.
As a purely additive change, I don’t see this breaking any existing code.
No. If you want each member to have an access class explicitly specified, then do that with the existing syntax. Either way, you have to be consistent about it to get the advantages you claim exist.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/15377a15-fea0-4841-9834-d9c8861dc412%40isocpp.org.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/15377a15-fea0-4841-9834-d9c8861dc412%40isocpp.org.
On Mon, Jan 15, 2018 at 3:48 PM, <hamza...@me.com> wrote:It’d work like it does in every other language: following declarations will be unaffected.ay, there's the rub.In every other language, per-line is the _only_ way to do it. In C++ you would allow people to mix things:public:int x;private int y;int z;
Il giorno lunedì 15 gennaio 2018 23:03:24 UTC+1, Tony V E ha scritto:On Mon, Jan 15, 2018 at 3:48 PM, <hamza...@me.com> wrote:It’d work like it does in every other language: following declarations will be unaffected.ay, there's the rub.In every other language, per-line is the _only_ way to do it. In C++ you would allow people to mix things:public:int x;private int y;int z;Who said we should allow to mix things?
UTC Time: January 15, 2018 10:03 PMFrom: tvan...@gmail.com
The current way encourages you to separate public from private. What's would the benefit be of the new way?
It can't be purely additive without the ability to mix things.
UTC Time: January 15, 2018 10:03 PMFrom: tvan...@gmail.comThe current way encourages you to separate public from private. What's would the benefit be of the new way?There is a huge benefit -- in a "patch" generated by"diff", now you can clearly see what does the changemean without including a context of growing length.Local reasoning needs to apply to "patch" as well.