Comment Tricks

Does any else here do little tricks with java comments in order to save time switching between different behaviours?

For example, to toggle between two lines of code, just add/remove an asterisk:


// The space is there because otherwise the forum syntax highlighting detects it as a javadoc comment.
/* */int i = 0;
//*/int i = 1;


// The space is there because otherwise the forum syntax highlighting detects it as a javadoc comment.
/* /int i = 0;
//*/int i = 1;

Post your comment tricks here.

I would just normally change


int i = 0;

to


int i = 1;

It only requires changing a zero to a one (or vice versa)! :point:

I’m using {Ctrl+/} or {Ctrl+7} in Eclipse to toggle each line separately.
I haven’t found a solution to invert the toggle on the two lines together,
from :

     int i = 0;
//   int i = 1;

to :

//   int i = 0;
     int i = 1;

The one I used was just an example.

Actual usage is for longer lines.

I think that most of us use “comment tricks” like this. When I need to disable the code for a moment (or test how good is the new version without deleting previous) I use comment/uncomment feature in NetBeans. :slight_smile:

You can conveniently toogle whole blocks by just adding a slash


		/*
			if(wanderChangeCounter<=0)
		{
			wanderChangeCounter=ran.nextInt(7);
			wanderX=ran.nextInt(3)-1;
			wanderY=ran.nextInt(3)-1;
			
		}
		  
		 //*/

to


	    //*
			if(wanderChangeCounter<=0)
		{
			wanderChangeCounter=ran.nextInt(7);
			wanderX=ran.nextInt(3)-1;
			wanderY=ran.nextInt(3)-1;
			
		}
		  
		 //*/

For comments, I just block select ant ctrl+shift+C (on eclipse)(Line comments on whole block)
For me hitting a whole line or block is easier than hitting one character.

The only “trick” I use is to try and avoid block comments (/* … */) in favour of single-line comments (//)… Because then I can use the block comment to remove large chunks of code without a closing comment in between messing things up ::slight_smile:

I’m liking the tricks here, though.