0

In one of my colleagues code review for c++, one of my team mates asked her to put an underscore for the beginning of the function since it was not exposed via the header file.

But I found it not compulsory(left to the programmer's style) for the following reasons:

  1. This was an old code base and none of the code followed this coding convention.
  2. This was a function name and not a method defined in the class.
  3. Most of my company uses Java and is much familiar with Java more than c++. Putting an underscore would create more confusion than clarity.

I think this question is quite subjective. Am I wrong here? Should we put an underscore for each function not exposed via header file?

var
  • 109
  • 8
  • 3
    If the function is declared at global scope that's not even legal (if you are talking about a function name beginning with an underscore). – Baum mit Augen Nov 04 '16 at 02:46
  • 4
    Don't do that. [Identifiers beginning with an underscore in global namespace is reserved](http://stackoverflow.com/a/228797/3309790). – songyuanyao Nov 04 '16 at 02:47
  • 1
    For me I prefer not to, because it make variable and function names become similar to predefined built-in variables or functions. – Zamrony P. Juhara Nov 04 '16 at 02:48
  • 1
    _@var_ Putting an underscore at the end of a symbol keeps the doctor away. – πάντα ῥεῖ Nov 04 '16 at 02:55
  • @πάνταῥεῖ Keeps the... Who? :) (lucky with your nick, otherwise no rhymes are to be found in that aphorism to make it memorable ;) ) – Adrian Colomitchi Nov 04 '16 at 03:00
  • @AdrianColomitchi I'm simply extrapolating. That leaves the dimension of rhyming rules :3 – πάντα ῥεῖ Nov 04 '16 at 03:09
  • @πάνταῥεῖ Its underscore at the beginning of the function name declared in the global namespace. – var Nov 04 '16 at 03:13
  • @BaummitAugen Thanks, the function is defined in the global namespace, but, putting an underscore did not give any compilation errors/warnings? I am using a very old version of c++. – var Nov 04 '16 at 03:15
  • 1
    @var Simply don't use underscore at the beginning of symbol names, these are reserved for compiler implementation specific stuff. It's a convention mentioned in the c++ standard, so there won't be any warnings or errors about it. Similar as with undefined behavior. – πάντα ῥεῖ Nov 04 '16 at 03:17

0 Answers0