Commenting C++ code - TIPS

Discussion in 'C++' started by rajeshb, May 6, 2004.

  1. rajeshb

    rajeshb Guest

    To toggle between two implementain with just one key stroke:

    by removing or adding a single "/" u can toggle between two C++
    implementation.
    will be usefull when u want 2 test a sample implementation without
    deleting the existing one.

    adding a single "/" will comment the second implemenation(step 1).
    removing the same will comment the first implementation (step 2).

    step 1.
    ~~~~~~~~~~~~~

    //*
    // implementation one

    int i;
    int j;
    ...

    /*/
    // implementation two

    int i;
    int j;
    ...

    //*/


    step 2.
    ~~~~~~~~~~~~~

    /*
    // implementation one

    int i;
    int j;
    ...

    /*/
    // implementation two

    int i;
    int j;
    ...

    //*/
    rajeshb, May 6, 2004
    #1
    1. Advertising

  2. > To toggle between two implementain with just one key stroke:
    >
    > by removing or adding a single "/" u can toggle between two C++
    > implementation.
    > will be usefull when u want 2 test a sample implementation without
    > deleting the existing one.
    >
    > adding a single "/" will comment the second implemenation(step 1).
    > removing the same will comment the first implementation (step 2).


    Nice idea, indeed. But I'd prefer "#if 0 ... #else ... #endif" instead,
    because I consider your solution too tricky to be readable.

    #if 1
    // implementation one

    int i;
    int j;
    ...

    #else
    // implementation two

    int i;
    int j;
    ...

    #endif

    ....

    Cheers,
    Philipp.
    Philipp Bachmann, May 6, 2004
    #2
    1. Advertising

  3. "Philipp Bachmann >" <"reverse email address" <>
    wrote in message news:c7d89r$54c$-plus.net...
    > > To toggle between two implementain with just one key stroke:
    > >
    > > by removing or adding a single "/" u can toggle between two C++
    > > implementation.
    > > will be usefull when u want 2 test a sample implementation without
    > > deleting the existing one.
    > >
    > > adding a single "/" will comment the second implemenation(step 1).
    > > removing the same will comment the first implementation (step 2).

    >
    > Nice idea, indeed. But I'd prefer "#if 0 ... #else ... #endif" instead,
    > because I consider your solution too tricky to be readable.
    >


    Using an IDE that has syntax colouring you would immediately see which block
    was commented out. I've never seen an IDE that can colour #if #else #endif
    blocks though.

    john
    John Harrison, May 6, 2004
    #3
  4. rajeshb

    Mike Wahler Guest

    "John Harrison" <> wrote in message
    news:...
    >
    > "Philipp Bachmann >" <"reverse email address" <>
    > wrote in message news:c7d89r$54c$-plus.net...
    > > > To toggle between two implementain with just one key stroke:
    > > >
    > > > by removing or adding a single "/" u can toggle between two C++
    > > > implementation.
    > > > will be usefull when u want 2 test a sample implementation without
    > > > deleting the existing one.
    > > >
    > > > adding a single "/" will comment the second implemenation(step 1).
    > > > removing the same will comment the first implementation (step 2).

    > >
    > > Nice idea, indeed. But I'd prefer "#if 0 ... #else ... #endif" instead,
    > > because I consider your solution too tricky to be readable.
    > >

    >
    > Using an IDE that has syntax colouring you would immediately see which

    block
    > was commented out. I've never seen an IDE that can colour #if #else #endif
    > blocks though.


    IMO an even 'cleaner' solution is to put alternative implementations
    in separate files, and include/exclude the desired/undesired files
    in the build.

    -Mike
    Mike Wahler, May 6, 2004
    #4
  5. rajeshb

    bartek Guest

    "John Harrison" <> wrote in
    news::

    (...)

    > Using an IDE that has syntax colouring you would immediately see which
    > block was commented out. I've never seen an IDE that can colour #if
    > #else #endif blocks though.


    FYI, gvim does it. Maybe it's not an IDE in full-blown-sense-of-the-word,
    though, but a bloody useful code editor nonetheless.

    Cheers!
    --
    :: bartekd [at] o2 [dot] pl
    bartek, May 6, 2004
    #5
  6. "bartek" <> wrote in message
    news:Xns94E1DA57D4976bartekdqwertyuiopo2p@153.19.251.200...
    > "John Harrison" <> wrote in
    > news::
    >
    > (...)
    >
    > > Using an IDE that has syntax colouring you would immediately see which
    > > block was commented out. I've never seen an IDE that can colour #if
    > > #else #endif blocks though.

    >
    > FYI, gvim does it. Maybe it's not an IDE in full-blown-sense-of-the-word,
    > though, but a bloody useful code editor nonetheless.
    >


    Does it colour the block depending on whether it will be compiled or not?

    #if 0
    // one colour
    #endif

    #if 1
    // another colour
    #endif

    That's what struck me as useful about rajeshb's tip.

    john
    John Harrison, May 6, 2004
    #6
  7. rajeshb

    bartek Guest

    "John Harrison" <> wrote in
    news::

    >
    > "bartek" <> wrote in message
    > news:Xns94E1DA57D4976bartekdqwertyuiopo2p@153.19.251.200...
    >> "John Harrison" <> wrote in
    >> news::
    >>
    >> (...)
    >>
    >> > Using an IDE that has syntax colouring you would immediately see
    >> > which block was commented out. I've never seen an IDE that can
    >> > colour #if #else #endif blocks though.

    >>
    >> FYI, gvim does it. Maybe it's not an IDE in
    >> full-blown-sense-of-the-word, though, but a bloody useful code editor
    >> nonetheless.
    >>

    >
    > Does it colour the block depending on whether it will be compiled or
    > not?
    >
    > #if 0
    > // one colour
    > #endif
    >
    > #if 1
    > // another colour
    > #endif
    >
    > That's what struck me as useful about rajeshb's tip.


    Certainly. Gvim's C/C++ syntax colour definition treats #if 0 ... #endif
    block just like it was a comment.

    --
    :: bartekd [at] o2 [dot] pl
    bartek, May 6, 2004
    #7
  8. rajeshb

    Old Wolf Guest

    "John Harrison" <> wrote:
    > "Philipp Bachmann" wrote:
    > > > To toggle between two implementain with just one key stroke:
    > > > by removing or adding a single "/" u can toggle between two C++
    > > > implementation.

    > >
    > > Nice idea, indeed. But I'd prefer "#if 0 ... #else ... #endif" instead,
    > > because I consider your solution too tricky to be readable.
    > >

    >
    > Using an IDE that has syntax colouring you would immediately see which block
    > was commented out. I've never seen an IDE that can colour #if #else #endif
    > blocks though.


    http://www.vim.org/

    (or if an IDE does not a shell and an editor make, then set your IDE's
    editor to be vim or gvim).
    Old Wolf, May 6, 2004
    #8
    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. vijay
    Replies:
    7
    Views:
    13,676
    Jim Lewis
    Feb 7, 2005
  2. =?Utf-8?B?U2FuZHk=?=

    Commenting out VB code

    =?Utf-8?B?U2FuZHk=?=, Feb 2, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    51,831
    =?Utf-8?B?Sm9uWg==?=
    Feb 3, 2005
  3. patrick

    java commenting out of code

    patrick, Jan 11, 2006, in forum: Java
    Replies:
    4
    Views:
    5,212
    Malte Christensen
    Jan 11, 2006
  4. Michael

    Commenting out debug code

    Michael, May 27, 2004, in forum: C++
    Replies:
    3
    Views:
    469
  5. Replies:
    1
    Views:
    3,126
    Arne Vajhøj
    Jul 31, 2012
Loading...

Share This Page