Quick Newbie question about naming conventions
-
Hi, I'm trying to get into C++ and I was wondering about the class and method names. I'm hailing from C#, where everything is written fully and all names are immediately comprehensible. However, it seems in C++ mostly abbreviations are being used. Is there any good reason for this or is that just because C++ has been around since long before Intellisense, so it's just a matter of convenience? Thanks.
-
Hi, I'm trying to get into C++ and I was wondering about the class and method names. I'm hailing from C#, where everything is written fully and all names are immediately comprehensible. However, it seems in C++ mostly abbreviations are being used. Is there any good reason for this or is that just because C++ has been around since long before Intellisense, so it's just a matter of convenience? Thanks.
ya! it's only a matter of convenience to avoid long variable names and distinguishing them from being local or member variables. for example there is oneHungarian Notation[^] that can be followed. If you feel that the people who follow you, should understand the code by just having a glimpse at it, it would be better to use a notation. on an ending note - > If you use your own:DOCUMENT IT VERY CAREFULLY.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
Hi, I'm trying to get into C++ and I was wondering about the class and method names. I'm hailing from C#, where everything is written fully and all names are immediately comprehensible. However, it seems in C++ mostly abbreviations are being used. Is there any good reason for this or is that just because C++ has been around since long before Intellisense, so it's just a matter of convenience? Thanks.
It's not specific to C++. Different projects use different naming conventions, so depending on whose code you look at it will vary greatly. It's really a matter of preference. The C++ standard library comes all in one single namespace called
std
that deals with basic stuff like string manipulation, lists etc., whereas the .NET API pretty much wraps the entire OS API. The C++ library can get away with much shorter names since its feature set is very limited and defined, whereas .NET needs means to organize all that stuff, and it does so by using tons of nested namespaces, which results in much longer symbol names overall. I agree that most STL class names are not necessarily immediatly comprehensible and are thus not really a good example to follow in terms of naming conventions. Nor are the MFC, which were conceived before design patterns, templates, and namespaces had reached the real world, plus they are massively influenced by the Windows API naming conventions and are overall much closer to a C library than to a modern C++ library. My advice is to be as verbose as you need to be but as short as you can be without sacrificing clarity. The time you save when you use cryptic abbreviations is far less than the time it is going to cost when someone has to fix a bug in that code, or even just understand what it does. If you want an example of what readable C++ code with good coding conventions and modern design looks like, check out the open source FreeCloth project. Reading through that code really changed the way I had been thinking about a few things. Hope this helps, Peter -
Hi, I'm trying to get into C++ and I was wondering about the class and method names. I'm hailing from C#, where everything is written fully and all names are immediately comprehensible. However, it seems in C++ mostly abbreviations are being used. Is there any good reason for this or is that just because C++ has been around since long before Intellisense, so it's just a matter of convenience? Thanks.
Thanks!