2008-02-27 Switch comments - enabling and disabling Codeparts fast and easy
Deutsche Version auch verfügbar
I always thought everybody knows this little Trick already because I'm using this for many years now. Apparently not.
So here's the Hint that helps a lot during everyday coding. Because I don't know if there's a proper naming already I call it "Switch Comments".
While working on Code it happens a lot you need to switch parts of Code on and off for testing. To do so you can comment and uncomment the Lines using // or /**/ Comments.
With longer code parts this can become a real pain. But using Switch Comments you can easily do it by changing just one Character.
Switch Comments are a Combination of Single and Multi line Comments. They start with a: //* and end again with // */. Code that is wrapped that way is fully functional. By simply removing one of the / from the starting Comment the whole Block will be deactivated.
Here's the Example:
Active Comment:
demo = {
/*
someTest.Javascript();
toDemonstrate = 'how Easy';
// */
it.is('to make Code appear');
and = ['disappear','again'];
this.isVeryUseful('indeed');
};
demo = {
//*
someTest.Javascript();
toDemonstrate = 'how Easy';
// */
it.is('to make Code appear');
and = ['disappear','again'];
this.isVeryUseful('indeed');
};
Sadly CSS fails because of the missing Support for // Comments. But Javascript, PHP and many more work nicely with this helpful little thingy.
Update:
My Collegue Steve Webster came up with the logic alternative for CSS:
Comment active:
.test{
border:1px solid red;
/*/
background-color:blue;
/**/
margin:1em;
}
.test{
border:1px solid red;
/**/
background-color:blue;
/**/
margin:1em;
}
english