This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.

| Magic Comments Submitted by

Have you ever been working on a piece of code, and been using block comments to comment out something that you later find you want to uncomment? When doing this, you normally have to add the /* to the start of the block and */ the end of the block. Then when you want to uncomment it, you have to do the reverse.. not exactly time consuming, but a bit annoying.. especially if the block is large, and you end up doing it a number of times. There is a simple way to get around this problem, and I've found it immensely useful.
You start the block comment as per usual, with /* but you end it with /**/
e.g.

    /*
    	// ..lots of code here..
    	DoSomethingHere();
    	// ..more lots of code here

    /**/

When you want to uncomment the code, just remove the /* at the start, everything becomes uncommented, and the end of the block just remains in a nice little 'no-op' comment all by itself.
but wait, it gets better...
Say you are making some changes to a bit of code, but you want to keep the original code for testing purposes. i.e. you want to test the differences between the code, so you will sometimes want to use the original code, and sometimes you want to use your changes... but never both at the same time. You can use a set of comments like:

    /*
    	// ... lots of code here...
    	OriginalCode();
    	// and here ...
    /*/
    	// ... some code here...
    	ChangedCode();
    	// ... and here
    /**/

Adding or removing the start of the initial block comment (/*) will automagically leave either the first, or the second code block commented out, respectively. It's quite simple in how it works. If the start comment /* is there, the middle comment /*/ is treated as the terminator of the block comment, and the final comment /**/ just remains harmlessly by itself. If the start comment isn't there, the middle comment /*/ is treated as the start of the block, and the final comment /**/ acts as the block terminator.
If anyone else uses/has seen this type of commenting, let me know, because i've never seen it used elsewhere except by myself, and the people i've told about it.
imron.

The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.