Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Commenting C++ code - TIPS

Reply
Thread Tools

Commenting C++ code - TIPS

 
 
rajeshb
Guest
Posts: n/a
 
      05-06-2004
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;
...

//*/
 
Reply With Quote
 
 
 
 
Philipp Bachmann
Guest
Posts: n/a
 
      05-06-2004
> 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.


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      05-06-2004

"Philipp Bachmann >" <"reverse email address" <(E-Mail Removed)>
wrote in message news:c7d89r$54c$(E-Mail Removed)-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


 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      05-06-2004

"John Harrison" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> "Philipp Bachmann >" <"reverse email address" <(E-Mail Removed)>
> wrote in message news:c7d89r$54c$(E-Mail Removed)-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


 
Reply With Quote
 
bartek
Guest
Posts: n/a
 
      05-06-2004
"John Harrison" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

(...)

> 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

 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      05-06-2004

"bartek" <(E-Mail Removed)> wrote in message
news:Xns94E1DA57D4976bartekdqwertyuiopo2p@153.19.2 51.200...
> "John Harrison" <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
> (...)
>
> > 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


 
Reply With Quote
 
bartek
Guest
Posts: n/a
 
      05-06-2004
"John Harrison" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

>
> "bartek" <(E-Mail Removed)> wrote in message
> news:Xns94E1DA57D4976bartekdqwertyuiopo2p@153.19.2 51.200...
>> "John Harrison" <(E-Mail Removed)> wrote in
>> news:(E-Mail Removed):
>>
>> (...)
>>
>> > 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

 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      05-06-2004
"John Harrison" <(E-Mail Removed)> 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).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: commenting out blocks of code Paul McNett Python 1 02-18-2006 02:08 AM
java commenting out of code patrick Java 4 01-11-2006 03:05 PM
Block Commenting of VHDL code in Xilinx ISE 6.3i vijay VHDL 7 02-07-2005 07:54 PM
Commenting out VB code =?Utf-8?B?U2FuZHk=?= ASP .Net 5 02-03-2005 05:51 PM
Commenting out debug code Michael C++ 3 05-27-2004 11:55 AM



Advertisments