Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is no one using the STL naming conventions? [closed]

Lots of C++ projects use some sort of camel case naming convention. The only project using the STL naming conventions seems to be boost (where much prototyping for the STL is being done). I know that there are some projects that predate the STL, but also most new code bases (that use the STL) stick with the camel case naming convention.

So my questions are:

  • Why is no one using the STL naming conventions?
  • Would you recommend using the STL naming convention over camel case for a new project?
  • I have seen some projects use the STL naming conventions for some 'STL type' classes (limited_stack, simplify_type) and camel case for everything else. This looks like a good approach to separate infrastructure from application code. Would you recommend doing this?

(I know that naming conventions have been discussed to death. Still I think that this question has not been answered before. Especially the idea of splitting naming conventions is, in my opinion, worth discussing.)

like image 895
jd_hans Avatar asked Jan 27 '11 17:01

jd_hans


1 Answers

First of all, let me stress that my answer is pretty much subjective, based on my experience only, not backed with any external data or resources.

A convention is just that: a convention. It matters not which one you use, but rather which one is readable and comfy to type for you and the programmers that get to maintain the code you're working with at the moment.

I use CamelCase in C++ because it's more visually pleasing for my eye and because I'm just used to it. On the other hand, I use underscores and lowercase function names in C - it's become sort of a simple way of distinguishing which language has been used for me.

Other programmers will most certainly give you other reasons - most of which will be more or less subjective, true for them or the dev temas they're members of.

Look at other languages. C# favours CamelCase, with the first letter capitalised. Why is that better than leaving the first one lowercase?

PHP programmers that use Zend framework are also familiar with Zend naming conventions: http://framework.zend.com/manual/en/coding-standard.naming-conventions.html.

Drupal API is PHP too - but uses underscores, lowercase letters and module/theme-specific prefixes.

Libraries, frameworks and even entire languages may have naming conventions that for some reason are favoured by their makers. That does not force you to quit using your usual naming convention :). So, all in all, I think the answer to your question can be put in such a silly manner: just because :D. Because the individual programmers feel comfortable with it.

As for the second question: no, I would not recommend using any convention over another for any project. Choose what's best for you. The only situation where you have no choice is when you're in a dev team that for some reason wants to stick to a single convention (such as a consistent API).

Third question: yes, you can view it this way. I usually prefix my classes so it's pretty much obvious that UmbraModule or TCODConsole are part of Umbra or libtcod API. As for STL, I prefer not namespacing it. Prefixing everything with std::* is a very clear indication of whether it's part of a different library or not, thus the infrastructure/application code is clearly distinguished - leaving the CamelCase vs. underscores a secondary matter :).

like image 195
mingos Avatar answered Nov 02 '22 13:11

mingos