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

Discussion in 'C++' started by Steven T. Hatton, Oct 15, 2004.

  1. 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
    Steven T. Hatton, Oct 15, 2004
    #1
    1. Advertising

  2. "Steven T. Hatton" <> wrote in message
    news:...

    > 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.
    Andrew Koenig, Oct 15, 2004
    #2
    1. Advertising

  3. Andrew Koenig wrote:

    > "Steven T. Hatton" <> wrote in message
    > news:...
    >
    >> 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
    Steven T. Hatton, Oct 15, 2004
    #3
  4. Steven T. Hatton

    JKop Guest

    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
    JKop, Oct 15, 2004
    #4
  5. Steven T. Hatton

    Tom Widmer Guest

    On Fri, 15 Oct 2004 00:08:23 -0400, "Steven T. Hatton"
    <> wrote:

    >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
    Tom Widmer, Oct 15, 2004
    #5
  6. Steven T. Hatton

    JKop Guest

    Tom Widmer posted:

    > On Fri, 15 Oct 2004 00:08:23 -0400, "Steven T. Hatton"
    ><> wrote:
    >
    >>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
    >


    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
    JKop, Oct 15, 2004
    #6
  7. Tom Widmer wrote:

    > On Fri, 15 Oct 2004 00:08:23 -0400, "Steven T. Hatton"
    > <> wrote:
    >
    >>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,


    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
    Steven T. Hatton, Oct 15, 2004
    #7
  8. JKop wrote:

    > 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
    Steven T. Hatton, Oct 15, 2004
    #8
  9. Steven T. Hatton

    Tom Widmer Guest

    On Fri, 15 Oct 2004 09:25:39 -0400, "Steven T. Hatton"
    <> wrote:

    >Tom Widmer wrote:
    >
    >> On Fri, 15 Oct 2004 00:08:23 -0400, "Steven T. Hatton"
    >> <> wrote:
    >>
    >>>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,

    >
    >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?


    Google...

    Tom
    Tom Widmer, Oct 15, 2004
    #9
  10. Steven T. Hatton wrote:
    > 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.
    Victor Bazarov, Oct 15, 2004
    #10
  11. Steven T. Hatton

    Howard Guest

    "Steven T. Hatton" <> wrote in message
    news:...

    > 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
    Howard, Oct 15, 2004
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9l?=

    Extract filename from a filename typed by user

    =?Utf-8?B?Sm9l?=, Aug 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,003
    Travis Murray
    Aug 24, 2004
  2. Mr Newbie

    Uniformity

    Mr Newbie, Nov 8, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    441
    Mr Newbie
    Nov 9, 2005
  3. Replies:
    1
    Views:
    1,434
    Roland de Ruiter
    Jun 15, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,756
    Smokey Grindel
    Dec 2, 2006
  5. Jan Clemens Faerber

    Universal Selector to gain browser uniformity

    Jan Clemens Faerber, Apr 4, 2013, in forum: HTML
    Replies:
    4
    Views:
    346
    Jan Clemens Faerber
    Apr 5, 2013
Loading...

Share This Page