0

so while a was talking to a friend about my code, he said that i shouldn't use underscore characters in my variables. i understood that it's allowed by the language (c++) and as long as i don't name a variable with an underscore character at the beginning of it it's okay. i've been reading the naming convention and it also says that's it's ok. i'm confused, cause my friend told me that he learned that from his teachers????

i'm a beginner yes, i just wanted to get this clear. thanks in advance

  • as long as you avoid using leading underscores, you're a okay. I use underscores as a space separator in my variable names. – NathanOliver Jun 29 '22 at 02:59
  • 1
    This is pretty opinion based. Most code bases have rules that you follow, one codebase may require camelCase while another might be written in snake_case. As long as you are consistent and follow the rules of the code base it is fine – Natio2 Jun 29 '22 at 07:37
  • `_BAD` because leading underscore-and-capital is reserved. `also__bad` because two underscores in a row anywhere in the identifier is reserved. `_globalbad` because leading underscore-and-lowercase is reserved *at the global scope*, but is okay to use as a member variable or parameter or local variable. – Eljay Jun 29 '22 at 11:12
  • It's quite common to use underscores in identifiers. There are a few combinations of underscores and letters that aren't allowed; as long as you don't use those, you're fine. See the comment by @Eljay for details. – Pete Becker Jun 29 '22 at 12:55
  • @NathanOliver -- two underscores in a row, anywhere in the identifier, is also reserved. – Pete Becker Jun 29 '22 at 12:56

0 Answers0