If we use the C prefix for classes, should we also use it for structure?

Assuming that the project has been using the C class prefix for a long time, it would be a waste of time at a late stage, and that the person who originally wrote the style guide was hit by a bus, and that the code no longer has structures ...

This is a pretty trivial question, but if the C ++ style guide says: β€œUse C to prefix the class name,” then it should be understood the same way as using C to prefix the structure, or we should use something else , for example S for example.

class CFoo { }; struct CBar { }; 

... or...

 class CFoo { }; struct Bar { }; 
+7
c ++ coding-style
source share
8 answers

If the style guide doesn't specify, I would (possibly) use "structs are classes with all members public" - also use C for structures, yes. Or I would have thought: β€œHa, here is a lauf to get around this stupid initial rule, yay” and not use it. In other words, it is very subjective.

+12
source share

The simple answer is do not use the C prefix for classes. This is the Hungarian notation of the most senseless variety. This is probably the time to rewrite the style guide. Honestly (and speaking as someone who wrote several things), most of these guides are garbage and / or were written for a long, long time and never updated.

+25
source share

If the code style guide does not indicate, find the code that follows the style guide and see what has been done.

If the code already given in the style guide is missing, we have come to an agreement with all the participants in the project.

If no one is involved, just decide and be consistent.

+5
source share

I think this guide is stupid and confusing. The fact that you should have asked this question proves it.

Coding styles are designed to improve readability; this is obvious if the identifier is a class or not, especially if you are using a decent ID with mouse tips.

+3
source share

Usually we use the prefix C for classes and the prefix T for structures that do not have methods (i.e. C structures).

+2
source share

For me it comes down to:

Do you want readers of your code to immediately distinguish between two types of declarations?

While using a prefix is ​​usually frustrating, carefully consider the presentation of the supporting code. Is it helpful for them to think, "A! No C prefix, this is a structure." Using a structure instead of a class may mean something specific in your code. If this is not the case, it makes sense to continue to use the prefix for the maintainer.

+2
source share

If the style guide does not serve its purpose to simplify readability, consistency, and correctness, it should be changed until it is executed or selected in the lap file (garbage bin).

In addition, if people do not follow it, then it should be updated so that it will be easier to follow (or change tools to facilitate coding in the guide).

+2
source share

According to the existing C prefix pattern for classes, you must prefix S for struct, i for interface.

In addition, the prefix is ​​E for listing, D for delegate, D for directory, F / M for function / method, F for file, F for field, N for namespace, P for page, P for parameter, P for property, R for the return value, v for the variable.

As with variables, the prefix

  • a for array
  • b for boolean
  • c for char
  • f for float
  • g for GUID
  • h for descriptor
  • i for int
  • j for json
  • k for key
  • l for the list
  • m for MarshalByRefObject
  • n for nullable
  • o for the object
  • p for pointer
  • q for the queue
  • r for the registry
  • s for single
  • t for TimeZone
  • u for Uri
  • v for version
  • w for WeakReference
  • x for XmlDocument
  • y for yoda
  • z for zipfile

Example

Good:

 namespace NGqqnbig.NConsoleApplication1 { class CProgram { static void Main(string[] pasArgs) { FMain(pasArgs); } static void FMain(string[] pasArgs) { var vsLine= CConsole.FReadLine(); var viSVN= CConvert.FToInt32(vsLine); var occCVC = new CCCCVC(); occCVC.PICVC = viSVN; } } class CCCCVC { private int fiCVC; public int PICVC { get { return fiCVC; } set { fiCVC = pivalue; } } } } 

Poorly:

 namespace Gqqnbig.ConsoleApplication1 { class CProgram { static void Main(string[] args) { var line= Console.ReadLine(); var svn= Convert.ToInt32(line); var cardVerificationCode = new CreditCardVerificationCode(); cardVerificationCode.VerificationCode = svn; } } class CreditCardVerificationCode { public int VerificationCode { get; set; } } } 
0
source share

All Articles