Why filename uniformity is important. *.c++ *.h++

S

Steven T. Hatton

I've mentioned a few times that the lack of standard filenames in C++ can be
problematic. This is an example of the kind of situation where it becomes
so. I tend to switch between using Emacs[*] and KDevelop[**]. I often
find Emacs easier to use for simple test code, but KDevelop (when the cvs
image is healthy) tends to facilitate better overal project organization.

Not infrequently, I want to work on code written with one tool in the other.
Well, Emacs thinks of *.h files as C rather than C++ headers, and thus goes
into C mode when they are opened. If I don't catch it, the code is
fromatted and highlighted differently than it would be in C++ mode. I
therefore use *.hh nameing when using Emacs (as well as *.cc, because I
like it better than *.cpp). OTOH KDevelop doesn't deal with *.hh (nore
*.cc) files well, preferring *.h (and *.cpp).

OK, so I spin up some bash to convert a directory from one form to the
other:

function kdev2emacs()
{
test -d old || mkdir old;

for f in *.h; do
test -f $f && cat $f | sed -e /"#include "/s/"\.h\([\"\>]\)"/.hh\\1/ >
${f%%.h}.hh;
mv $f old;
done

for f in *.cpp; do
test -f $f && cat $f | sed -e /"#include "/s/"\.h\([\"\>]\)"/.hh\\1/ >
${f%%.cpp}.cc;
mv $f old;
done
}

$ ls
main.cpp ring.cpp ring.h torus.cpp torus.h torusscene.cpp torusscene.h

$ grep \#include *[ph]
main.cpp:#include "torusscene.h"
....
torusscene.cpp:#include "torus.h"
torusscene.cpp:#include "torus.moc"

$ kdev2emacs

$ ls
main.cc old ring.cc ring.hh torus.cc torus.hh torusscene.cc
torusscene.hh
$ grep \#include *[ch]
main.cc:#include "torusscene.hh"
....
torusscene.cc:#include "torus.hh"
torusscene.cc:#include "torus.moc"

Cool! It works! ...

Whoops!
torusscene.cc:#include <Inventor/Qt/SoQt.hh>
torusscene.cc:#include <Inventor/Qt/viewers/SoQtExaminerViewer.hh>
torusscene.cc:#include <Inventor/SbBasic.hh>
torusscene.cc:#include <Inventor/fields/SoMFVec3f.hh>
torusscene.cc:#include <Inventor/nodes/SoSeparator.hh>
torusscene.cc:#include <Inventor/nodes/SoTransform.hh>
torusscene.cc:#include <Inventor/nodes/SoCoordinate3.hh>
torusscene.cc:#include <Inventor/nodes/SoQuadMesh.hh>
torusscene.cc:#include <Inventor/nodes/SoShapeHints.hh>

These aren't mine. I can't simply rename or symlink them.

And as I've already said, *.c++ and *.h++ is the One True Way.
[*] http://www.gnu.org/software/emacs/emacs.html
[**] http://www.kdevelop.org
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell
 
A

Andrew Koenig

I've mentioned a few times that the lack of standard filenames in C++ can
be
problematic. This is an example of the kind of situation where it becomes
so. I tend to switch between using Emacs[*] and KDevelop[**]. I often
find Emacs easier to use for simple test code, but KDevelop (when the cvs
image is healthy) tends to facilitate better overal project organization.

I don't know about KDevelop, but in Emacs, you can indicate that a file is a
C++ file by putting a comment such as

// -*-C++-*-

near the beginning of the file. Then the file's name doesn't matter.
 
S

Steven T. Hatton

Andrew said:
I've mentioned a few times that the lack of standard filenames in C++ can
be
problematic. This is an example of the kind of situation where it becomes
so. I tend to switch between using Emacs[*] and KDevelop[**]. I often
find Emacs easier to use for simple test code, but KDevelop (when the cvs
image is healthy) tends to facilitate better overal project organization.

I don't know about KDevelop, but in Emacs, you can indicate that a file is
a C++ file by putting a comment such as

// -*-C++-*-

near the beginning of the file. Then the file's name doesn't matter.

Yes. However, if I open code that was created in KDevelop, and I did not
make the conscious effort to add the Emacs mode specification, or I open
code written by someone else, I still have the problem. And even if the
code /does/ have the mode specification, the speedbar won't pick it up.

I ran into this when working with Open Scene Graph[*] which uses
extensionless headers. They have the Emacs mode specification, but speedbar
depends on filenames, and therefore will not show their headers. I've been
symlinking them, but that is an ugly kludge with problems.

[*]http://www.openscenegraph.org/
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell
 
J

JKop

I myself use:

..cpp
..hpp


to emphasize that the language I'm dealing with is C++.


Hypothetically speaking, if I were to write C code (which I wouldn't), then
I'd call them:

..c
..h


-JKop
 
T

Tom Widmer

And as I've already said, *.c++ and *.h++ is the One True Way.

I think some OSes can't take + characters in filenames. DOS? Remember,
C++ and DOS are still widely used together (DJGPP).

Tom
 
J

JKop

Tom Widmer posted:
I think some OSes can't take + characters in filenames. DOS? Remember,
C++ and DOS are still widely used together (DJGPP).

Tom

Which is exactly why I prefer:

..cpp
..hpp

over:

..c++
..h++


I'll also limit the names to 8.3 (aaaaaaaa.123), when I'm writing code
files.

-JKop
 
S

Steven T. Hatton

Tom said:
I think some OSes can't take + characters in filenames. DOS? Remember,

I try to forget.
C++ and DOS are still widely used together (DJGPP).
Ok, I'm curious. Who uses DOS these days for C++ development? Not the DOS
emulation in N(ew) T(estament) or Chi(X) Rho(P).

DJGPP?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell
 
S

Steven T. Hatton

JKop said:
Which is exactly why I prefer:

.cpp
.hpp

over:

.c++
.h++

AFAIK, all recent Microsoft OS's support a + in a file name. I would have
to reboot to find out if XP does. The matching size of the extension is a
good thing. It makes it easier to grep in one shot.
I'll also limit the names to 8.3 (aaaaaaaa.123), when I'm writing code
files.

Guess which file holds the declaration for class sth::tmath::TensorIndex<>
sth/tmath/PowerOf.hh
sth/tmath/tmath_impl.hh
sth/tmath/Matrix.hh
sth/tmath/Vector.hh
sth/tmath/Space.hh
sth/tmath/Tensor.hh
sth/tmath/TensorIndex.hh

--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell
 
T

Tom Widmer

I try to forget.

Ok, I'm curious. Who uses DOS these days for C++ development? Not the DOS
emulation in N(ew) T(estament) or Chi(X) Rho(P).

DJGPP?

Google...

Tom
 
V

Victor Bazarov

Steven said:
I've mentioned a few times that the lack of standard filenames in C++ can be
problematic. [...]

And I guess you just can't help it but mention it again...
Why don't you post this to a newsgroup for your OS, eh? It is only
relevant there. For all I know, there exists a system with a C++
compiler where files are identified by numbers and not names.
 
H

Howard

And as I've already said, *.c++ and *.h++ is the One True Way.

Hmm. That must mean that everyone is doing it wrong. In almost all cases,
I see .cpp and .h as the extensions on the files I use, whether written
in-house or by a third party. I stick to that, because it's what everyone
else is using. Conformity as well as uniformity, you understand. :)

-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top