473,499 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Commenting C++ code - TIPS

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;
...

//*/
Jul 22 '05 #1
7 2473
> 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.
Jul 22 '05 #2

"Philipp Bachmann >" <"reverse email address" <ed*****@nnamhcab.ppilihp>
wrote in message news:c7**********@atlas.ip-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
Jul 22 '05 #3

"John Harrison" <jo*************@hotmail.com> wrote in message
news:2f************@uni-berlin.de...

"Philipp Bachmann >" <"reverse email address" <ed*****@nnamhcab.ppilihp>
wrote in message news:c7**********@atlas.ip-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
Jul 22 '05 #4
"John Harrison" <jo*************@hotmail.com> wrote in
news:2f************@uni-berlin.de:

(...)
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

Jul 22 '05 #5

"bartek" <sp******************@o2.pl> wrote in message
news:Xn**********************************@153.19.2 51.200...
"John Harrison" <jo*************@hotmail.com> wrote in
news:2f************@uni-berlin.de:

(...)
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
Jul 22 '05 #6
"John Harrison" <jo*************@hotmail.com> wrote in
news:2f************@uni-berlin.de:

"bartek" <sp******************@o2.pl> wrote in message
news:Xn**********************************@153.19.2 51.200...
"John Harrison" <jo*************@hotmail.com> wrote in
news:2f************@uni-berlin.de:

(...)
> 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

Jul 22 '05 #7
"John Harrison" <jo*************@hotmail.com> 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).
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
2430
by: Profetas | last post by:
Hi, I know that this is off topic. but I didn't know where to post. Do you comment your source code while coding or after coding. for example: you write a procedure and after it is...
4
7729
by: Ron McNulty | last post by:
Often when testing an app, I want to temporarily comment out sections of the App.config file. Is there any way to do this? Regards Ron
5
1412
by: Anders Borum | last post by:
Hello! I was wondering if there are any guidelines to documenting our C# code? I'm not talking about the actual syntax for the Xml markup we add to the classes, methods etc., but general...
3
1318
by: Naveen Mukkelli | last post by:
Hi All, I'm trying to create XML commenting for my code using XML commenting feature for the first time. I'm using VS.NET 2003 and C#. I'v tried the following way. Step 1: set the file name...
18
1293
by: Marian F. | last post by:
The 12 years old genius function to count english words in a sentence: ' This is my function to count english words in your string ' s is the string with your words to be counted ' Returns an...
8
1843
by: lallous | last post by:
Hello I've been programming for a number of years, however my commenting style is always different. Sometimes I use something like: /************************ * method .... * comments......
2
1061
by: RYoung | last post by:
Can someone point me to a reference concerning source code commenting with VB 2005, ala C# commenting? I googled and found alot of links to add-ins and commercial products, but I can't find any...
1
1238
by: Wijaya Edward | last post by:
Hi all, I have the following code: import sys import re ham_count = 0 spam_count = 0
100
4608
by: Angel Tsankov | last post by:
Can someone recommend a good source of C/C++ coding style. Specifically, I am interested in commenting style and in particular how to indent comments and the commented code, rather than when to...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.