C++ Proposal
Let @ become a synonymn for this->
.
Would this offer any new functionality?
§
Then what is the point?
§
For every occurrance, it saves 5 characters.
Why not use nothing instead?
§
this->
neccessarily hints class scope.
'Nothing' potentially hints a global scope, and leaves ambiguity.
Is this->
used particularly often?
§
No. It is relatively rare because the 6 extra characters adds clutter.
Is it really that big of a deal?
§
No, but it is a minor detail that can become an a issue of readability:
// Example found searching through searching through system source files:
TYPED_TEST ( StorageCache, AddFilePaths)
{
/* this */
auto ids = this -> cache. ids ( { this -> filePath1, this -> filePath2, this -> filePath3, this -> filePath4 } );
ASSERT_THAT ( ids, ElementsAre ( this -> id1, this -> id2, this -> id3, this -> id4 ) );
/* vs @ */
auto ids = @ cache. ids ( { @ filePath1, @ filePath2, @ filePath3, @ filePath4 } );
ASSERT_THAT ( ids, ElementsAre ( @ id1, @ id2, @ id3, @ id4 ) );
/* vs nothing */
auto ids = cache. ids ( { filePath1, filePath2, filePath3, filePath4 } );
ASSERT_THAT ( ids, ElementsAre ( id1, id2, id3, id4 ) );
}
Benefits?
§
There will be more inclination to specify this->
via @.
Leads to more explicit and cleaner code.
Simple to impliment.
Drawbacks?
§
It might break metacode which relies on @.
It would be unique to C++, making it a non transferrable idea to other languages.
There could be better uses for @ [that I am ignorant of].
Alternatives?
§
Instead of `@`, a singular `.` could work instead.
A slight problem here is that it visually clashes with commas and could have the developer searching for a parent object
TYPED_TEST ( StorageCache, AddFilePaths)
{
auto ids = . cache. ids ( { . filePath1, . filePath2, . filePath3, . filePath4 } );
ASSERT_THAT ( ids, ElementsAre ( . id1, . id2, . id3, . id4 ) );
}
Final thoughts
§
This is simply for future consideration of what to do with @ in C++.
If a better proposal came forth, I would be in favour of that.
While I am not selling this feature aggressively, I do think it is at least worth bringing up the minor annoyance of this->
tendency to clutter up code, hoping one day for a solution.
Thank you for your time and consideration.