/*/ comment here
do some thing.
/*/
do some thing.
//*/
Why people write code like that? Is this a good practice?
/*/ comment here
do some thing.
/*/
do some thing.
//*/
Why people write code like that? Is this a good practice?
Everyone has there own way of doing things... I'm guessing they did this so all you have to do is add a / to the first comment and remove the last / and then it toggles the comment block to the other set of instructions.
EDIT: Actually all you have to do is add a / to the first comment and then remove it to toggle it back.
It's usually only used when testing something out for the moment. That is, you should never commit code like that to version control, because it can be confusing.
For example, if you are testing two different computation methods, you can use this to switch between them. Personally I have rarely done this, if at all.
For those that don't know, you can toggle between the two code sections by adding one forward slash:
/*/ comment here
do some thing.
/*/
do some thing else.
//*/
//*/ comment here
do some thing.
/*/
do some thing else.
//*/
I would rather do
#ifdef DOIT_ONE_WAY
do one way
#else
do another way
#endif
but that's a matter of taste
Crappy practice. Dead code has no business hanging around in any production quality code. If there really are situations where the old, dead code would apply, then it should be refactored into something that can be turned on/off using configuration not recompilation.
That confuses me and would take me time to parse, so no I don't think it's good practice.
Any ease of toggling mentioned in Kane's answer is not worth it, I think. Ease of commenting should be taken care of by the developers browser.
To me this is just confusing and definitely not standard.
It's just an easy way to switch between two blocks of code (as Kane Wallmann said).
It's probably not great to leave it in production code (just delete it and get it back from source control if you need it), but while developing it's a handy way of being able to quickly toggle two implementations (or stub out some code etc).
I think this and the #ifdef method Arkadiy mentions are bad, as a multi-file search for do something both look like the code is live, while it may not be depending on previous lines.
If the code is valid #ifdef platform dependence sure do that,
but if it just testing code, etc I much prefer highlighting the lot and inserting the C++ // comment, which in VisualStudio is Ctrl-K, C
Not not necessarily bad practice, but expect mixed responses from someone who reads your code. For example, I think its really cool but would never commit code like that to the repository.
That's confusing and lacks programming aesthetics. A good way to do it is using the C preprocessor and coding it like:
#if 0
code block disabled
#endif
code block enabled