-
-
Notifications
You must be signed in to change notification settings - Fork 895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
About "t_" prefix #11
Comments
I don't see the benefits either. I wasn't even aware that this practice existed. |
I added a note explaining the reasoning 665e7a3 I believe the first time I saw that prefix it was actually a full This very much falls into the category of things I didn't expect people to agree with me on, but it's what I use in my code. |
Thanks for providing more background on this. To me it sounds though, like the problem that this technique approaches is that of incomprehensibly large functions. |
Another note: using the |
My two cents for my preferred style (which goes against the Google standards, and as I recall is kind of Java-ish).
It easily lets me be aware of the intended scope of a variable. This has saved by bacon on a number of occasions.
|
I'd also prefer not to use any variable prefixes, as they often makes things harder to talk about (or rather to pronounce). Something like: "Hey, Jeff, we should consider moving this tee-width parameter to local scope". Swapping the [t|m] prefix with an underscore suffix (like Google does it for instance) doesn't have this problem. |
Remember to be very careful when prefixing variables with My general rule is to just not prefix anything with |
I want to add a point here against using prefixes like this: They make the code less readable. You say on the other hand it will be easier to recognize where a variable comes from / what it's scope is (which would be better readability). But this is not the responsibility of code typing style. The responsibility of making the scope / origin of a variable clear is only on the IDE / editors side (syntax highlighting, auto-highlighting selection, outline views and the like). So, since we nowadays have editors doing all this for you, I'd say prefixing takes a greater amount of readability than it gives, because editors already do provide the positive effects of prefixing so that only the negative aspects of prefixing stay. |
Code doesn't just live in an IDE or code editor. We share code in e-mails, chat programs, supporting documentation, or even printouts. While all of these support some kind of syntax highlighting, that formatting is fixed at authoring time. It doesn't adapt to the readers' expectations, and one developer's visual cue for function arguments is another developer's formatting chosen for locals. Naming conventions certainly help to minimize the confusion. So while I am all in favor of prefixing function parameters, the I'm suggesting to keep the prefix for function arguments, but change it from |
Creeping Hungarian infestation here! I do not understand the 'They make the code less readable' remark. I prefer the a_ over the t_. |
Re: 'return (-1);'. Definitely not clean code. What is the -1 saying? It should, possibly, be:
|
The benefit of prefixes is: when using something with code completion, typing the prefix will immediately shrink down all available choices to the scope of the prefix (e.g. members or parameters). Depending on your familiarity with the code base, your memory and the intelligence of the IDE this might be a significant benefit. |
This is unnecessarily detailed. Function parameters fall into category of local variables. Thus, simply
This simply solves the requirement 665e7a3:
No |
Just FYI, the "prefix underbar" option has far too high of a chance invoking undefined behavior. |
Prefixing function parameters makes them truly un-readable and difficult to pronounce which is very frustrating for those of us who are verbal in nature. Frankly, prefixes should be used very sparingly. A suffix |
Regarding a prefix for arguments (and referring to them verbally) I prefer the |
This was an interesting read. Apologies for nudging everyone with my 👍s. In 2021 what have you seen in the wild? What is working for teams for this? I am not a C++ expert by any means, I'm just picking it up, but this is something that has bothered me about the language (lots of variables in different scopes and there is mental overhead in choosing member vs local names). Edit: Had another thought, would l_ (L for local) not be a suitable suffix? Though it unfortunately an ambiguous letter in most typefaces. |
In my style there's only one widely-used name decorator and that's Function arguments are essentially local variables and in my mind don't require any decoration. Module or global variables don't need anything either, I prefer the general rule of thumb to make the length of a variable name somewhat correlated to the size of its scope: For a loop counter or similar that "lives" for three lines of code Then sometimes I use |
Oh I quite like that rule and good example with |
Why we should use "t_" prefix for function parameters? What is the practical sense? I think it's just difficult to read. The function parameters should not be prefixed.
https://github.com/lefticus/cppbestpractices/blob/master/03-Style.md#distinguish-function-parameters
The text was updated successfully, but these errors were encountered: