The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
It is reserved for those who implement things like the standard library that usually comes with your compiler. Using a beginning underscore for member names or inside a function is legal, but not recommended. But, that being said, when I write classes in the standard C++ format (all lowercase), I use a trailing underscore to distinguish member variables from local variables.
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
Yes, but I relented on that issue in order to achieve a compromise on underscores. I didn't want underscores in the leading position at all, while Mr. Object wanted underscores to be prohibited unless they were in the leading position indicating scope. I use underscores in locals which for me are generally all lower case. I also use underscores in globals when the name includes an acronym: ObjectABC_Factory, for example, where ABC is the acronym.
Back story: My group has a naming convention and coding style document that is 1½ pages, and most of it recommends rather requires or prohibits. In fact, I think there's only one thing in it that is absolutely prohibited, and that's Hungarian notation. When we created this document in 2000, that was still quite a thing when doing Windows programming. The only place we allow it to be used is in argument names for callback functions, and they are recommended to use the same names as in the documentation.
For what it's worth, we've never had a conflict between our use of leading underscores and any compiler in the last 20 years, and that's spread over tens of millions of lines of C, C++, and C# code.
I had to look this up, because I didn't realize there were two variants. So thanks for prompting that!
Apps Hungarian isn't as bad, but arcane prefixed abbreviations to denote a purpose don't appeal to me. If something has a small scope, such as a loop variable, a single letter often works as a name. If it has a large scope, I'd rather see it spelled out.
The original Hungarian notation was actually supposed to be useful at the time. The prefix should have been a 'type' as in 'size', 'color', 'frequency', 'voltage', etc. So if you defined your variables as;
To be honest... no, I didn't know it. But I will remember it Is a good one
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
Either, you have to re-invent every wheel yourself ...
Or you'll just have to be prepared for mixed styles. If you use libraries, type/class definitions, ... whatever developed by others than yourself, you better be prepared for accepting mixed styles with regard to casing, use of underscores, indentation rules (e.g. in header files - you will see them even if you don't see the source code of that library), commenting style (/* */ comment blocks, end-of-line comments, no comments, ...), use of abbreviations in identifiers, ...
Sometimes you see conflicting styles even in a single product. The Win32 functions has a subset of functions taking all essential parameters as a single struct, headed by the struct size, so new extensions to the interface can add is parameter to the end of the struct; the size field indicates which version the caller wants to run. But most functions come in version Func, FuncEx, FuncExEx, ... FuncExExExExEx (yes, five times "Ex" has occurred!), each with its own parameter format/sequence. When your personal preference is strongly with the one style that is used the least, you end up bitching a lot "Why couldn't they always use..." when you type those Ex Ex Ex...
In Norwegian culture, "Aunt Sophie" is a well known figure. Anyone who grew up in Norway since the 1950 knows Torbjørn Egner's "Cardamom Town"[^] story (it has been translated into many languages, so you might know it from your own childhood!). In this story, aunt Sophie is constantly complaining "If just people were like me, the world would be a much better place!" "Aunt Sophie's angry song"[^] is well know to every Norwegian child. Too bad I didn't find an English version!
If you are accused of being an "Aunt Sophie", it means that you are unconditionally requiring everybody to follow your rules, your ideas of what people should think, how they should behave, and everything else, disregaring any counter argument. Being called an Aunt Sophie is certainly not meant as any sort of flattery! I would certainly not like such an accusation!
So I accept reality. There are various established styles out there. You may, in the name of "consistency" cling to your own style, come sun or come rain. Or you may go for the "When in Rome, do as the Romans" (although I know that is a very un-American approach...), adapting your own style to that of the library / subsystem / whatever your are interacting with.
But basing your entire private, political, professional or other life on the premise that everbody will think like you, behave like your, is doomed to failure.
I agree completely.
Consistency eases the mind and the eye, clearing your head to think about important matters instead of how this particular variable is cased.
Consistency in code can reduce errors and so create consistent quality as well (or maybe it's the other way around).
If I find inconsistent code I immediately assume it's written by some bungler who was so occupied understanding basic programming that there was simply no mental space left for consistency.
And usually I'm right.
If you can't even get consistency right, the rest of the code probably sucks as well.
When I look at that library I also see variables such as "username_val", where I presume "val" is short for "value".
What else than a value are you going to enter anyway?
It seems like an API created by a government, 'nuff said