Author |
Topic |
|
Mordachai
Tomato Guru
USA
224 Posts |
Posted - Apr 05 2018 : 12:38:55 PM
|
I loathe the vogue of smashing pointer and reference against the left hand symbol:
void* myptr; // YUCK! void Fun(Thing& thing); // YUCK!
Since the c++ parser has bizarro rules about left or right associativity of the * and & symbols, depending on context, I much prefer that they occur JUST LIKE ALL KEYWORDS, with spaces around themselves, as if this read "void pointer name":
void * myptr; // :) void Fun(Thing & thing) // Yes!
To keep thing crazy, if they are actually being applied to something, then I do want them to be connected, such as:
auto & foo = *myptr; // here, * is acting as a unary operator on myptr auto * foo = &thing; // here, & is acting as a unary operator on thing
Dereference and Addressof are exactly like ++ and -- and ~ and other similar unary operators, so they belong *with* the thing they're operating upon.
But when they're not unary ops, they're keywords, and as all other keywords, should read as just another keyword in the statement, not mushed up against anything at all.
After all:
Stuff* p1, p2; // WRONG!!! p2 is NOT a pointer - because C++ doesn't believe in the idiotic magical thinking that * is altering the type Stuff in this statement! It is NOT. So don't pretend it is!
And similarly, when you mush it left it doesn't actually change the meaning either:
Stuff& r1 = Snort(), r2 = Floog(); // NOPE, r2 is NOT a reference.
---
So - I want VA - when it generates code for me - such as extracting a method or function - to create it with a declaration that doesn't suffer from this mashup incorrect spacing arrangement:
void ReadDefinitionHeader(CString line, CCimexVersionInfo &file_version, CCimexVersionInfo &required_version, Toolbox::SimpleTextFile &file, unsigned &lineno)
Not a single one of those & symbols is acting as a unary operator - yet they're written here as if they were - generated by VA extract method.
And the reverse would - to my eyes - be just as wrong and ugly - & is a keyword like const or volatile or unsigned etc. It's just a really short one.
So please allow me to specify that somewhere in my preferences, please! I'm begging you! ;) |
|
feline
Whole Tomato Software
United Kingdom
19025 Posts |
Posted - Apr 06 2018 : 10:42:45 AM
|
Which IDE are you using? I ask because this is getting quite close to code formatting, and VS2017 has quite a few rules for code formatting of C++ code. Although looking at the options on my system, the only one that looks applicable is:
IDE tools menu -> Options -> Text Editor -> C/C++ -> Formatting -> Spacing -> Spacing for operators Remove spaces between unary operators and their operands
I do share some of your views on the placement of * and &, since I want things to be clear. For me, personally, placing the & against the variable in the parameter list always made sense, since we are specifying that this specific parameter is being passed as a reference. But this is partly down to personal taste.
What I am wary of here is the edge cases. Are you simply looking for the ability to make sure that & has a space on each side with Extract Method? Or does this start to get more wide ranging and complex? What happens with template type parameters? Pointers to a pointer, etc?
Also remember that other people have equally strong views, they are just different. Which is why we tend to be wary of code formatting, you need a LOT of settings to make everyone happy. |
zen is the art of being at one with the two'ness |
|
|
Mordachai
Tomato Guru
USA
224 Posts |
Posted - Apr 06 2018 : 12:49:01 PM
|
Yes, this absolutely boils down to personal prefs. And yes, absolutely, can't make everyone 100% happy - you'd die trying :)
I know my thing above boils down to "I have opinions and preferences - blah blah I'm right" :)
lol - in the end, I would love more settings to have some control - I get that I'll never have it align perfectly with my aesthetics.
I'm using VS2017 - latest non-beta update (like 2 days ago?) - and I couldn't find any settings to control this.
If I could get "always put spaces around * and &" - I'd be tickled pink - because 98% of the time they're defining the _type_ involved (const thing by ref, non-const thing by pointer, etc.) and 2% of the time they're acting as unary ops in my code - and having an extra space on those occasions that I use VA to extract a function or otherwise use its refactoring tools would be more than acceptable.
I'll poke around in the VS2017 formatting option you pointed out to see if that can help me. Thank you.
NOTE: I went over every setting under Text Editor C++ - and I cannot find a thing that would help. They don't seem to have any settings for argument spacing or keyword control - tons of other options, including the one you mention, and many of the options they offer are very useful. I can get most of my code to format with VS2017 correctly.
But afaik - both VS2017 and VA do not have any controls over how they format function arguments - which is what prompted this post. |
Edited by - Mordachai on Apr 06 2018 1:15:48 PM |
|
|
feline
Whole Tomato Software
United Kingdom
19025 Posts |
Posted - Apr 07 2018 : 07:02:18 AM
|
The number of IDE formatting options is slowly growing with time, and just goes to prove how many options different people want access to
We are considering some form of limited formatting control with parameters, and I have put a note onto this case about this situation. We are wary of getting into code formatting, so I am not sure if we will try this, but we are at least aware of the request:
case=104541 |
zen is the art of being at one with the two'ness |
|
|
Mordachai
Tomato Guru
USA
224 Posts |
Posted - Apr 07 2018 : 11:05:16 AM
|
Yeah, I had a wild hair - I don't normally complain about formatting because it's usually pointless - or worse -starts a thread war somewhere.
Thanks for your kind response. |
|
|
sean
Whole Tomato Software
USA
2817 Posts |
|
|
Topic |
|
|
|