

The One Character Block Comment - vlucas
http://www.vancelucas.com/blog/the-one-character-block-comment/

======
waldrews
Please please don't do this. It hurts readability, and relies on a subtle
grammar ambiguity. Without a highlighting editor (e.g. reading a diff in a
code review) I'll be scratching my head trying to read this. And tools like
editors that have an imperfect parser are likely to get confused.

There's a chance you'll confuse yourself (or your code reviewer or other
reader) and spend an hour debugging to find what you thought was commented out
wasn't. That's not worth it to save one keystroke.

~~~
Mintz
I think the purpose the author shared this technique for is when you need to
constantly comment/uncomment a block of code for testing.

I agree with you, though. Once you're done with your experiment, reset the
commented lines to something more conventional.

~~~
moe
Even then, any editor worth its salt supports comment toggling with a single
keystroke anyways. Good editors (vim, cough) can even toggle lines or
paragraphs regardless of cursor position.

So I agree, this hack is more trouble than its worth.

~~~
pbhjpbhj
the FF webdeveloper extension is the one I find easiest for live CSS editing -
though I'm using firebug more and more - it doesn't have comment toggling
(it's just a text field). Such tricks are handy.

Unless you're trying to work them around CSS comment hacks!

------
huhtenberg
Anyone who discovered, went bananas for and then eventually stopped using this
trick on their own, raise your hand.

:)

------
jcromartie
In C I don't use block comments, I just use:

    
    
        #if 0
          ...
        #endif
    

One character, no comment syntax hacks.

------
dfranke
This is also an old trick to test whether your code was compiled as a C++ or
not:

    
    
      2//**/2
        == 1) ? "C" : "C++"

~~~
timf
Is there a situation where you would need this instead of "#ifdef
__cplusplus"?

e.g. [http://www.parashift.com/c++-faq-lite/mixing-c-and-
cpp.html#...](http://www.parashift.com/c++-faq-lite/mixing-c-and-
cpp.html#faq-32.4)

~~~
dfranke
No. It's just for hack value.

------
shimon
Emacs users: try the comment-dwim command, usually bound to M-;. This will
toggle the commented-ness of the selected code and be relatively smart about
it. "dwim" stands for "do what I mean". :)

~~~
jf
Yes! And for the times when you are in a mode that comment-dwim doesn't know
the comment syntax for, you can use the string-rectangle (C-x r t) command to
comment regions.

------
skip
It's a nice trick, but I will probably stick to Ctrl-K-C (block comment) and
Ctrl-K-U (block uncomment) in Visual Studio, just out of habit. I hate leaving
big block comments in the middle of a module anyways: hurts readability.

~~~
jasonkester
It's probably telling that his code sample is PHP. Though I seem to remember
Eclipse having support for CTRL+/ style block commenting/uncommenting. Most
other good IDEs (and emacs, as noted below) do it too.

But yeah, I sometimes take for granted how nice VS.NET is at these little
detail things (though I use resharper-style CTRL+/ bindings for this
particular feature). Thanks to this author and his pain for reminding me how
good we have it.

~~~
mixmax
_It's probably telling that his code sample is PHP_

Excuse me, but last time I checked PHP was one of the most widely deployed
languages in the world, which a lot of people smarter than you and I spend
their working time hacking. Can we please stop the PHP bashing.

~~~
bkudria
(Disclaimer: I work in PHP)

PHP is popular. But the language sucks. Big-time. Popularity does not mean
something is automatically good, in a technical sense.

~~~
mixmax
Absolutely agree, and judging by the score of my parent comment maybe I didn't
make myself clear.

I don't mean to say that PHP is a perfect language by any means, far from it.
My point was more that just because some code example is written in PHP you
can't automatically infer that the code is inferior. I personally think that's
terribly arrogant, but that may just be me.

~~~
moe
_My point was more that just because some code example is written in PHP you
can't automatically infer that the code is inferior._

Perhaps I'm terribly arrogant but I do make that inference. Simply because the
number of _good_ coders who would pick PHP when given a choice is very, very,
very, very, very, very, very, very, very, very, very small. And shrinking.

~~~
mixmax
Most coders don't have the choice.

I'm sure that if it was up to the programmers many big sites would be hacked
out in Haskell, but as it is an awful lot of them happen to be done in PHP.
And Coders have jobs and bosses.

~~~
moe
On their personal blog?

------
nimbix
Or, you could use an editor more advanced than notepad.exe and use a "toggle
comment" command which which allows you to switch between

    
    
      //line 1
      //line 2
      //...
      //line N
    

...and...

    
    
      line 1
      line 2
      ...
      line N
    

...with more flexibility than using a syntax trick.

------
thunk
I find it really helpful to have a duplicate-and-comment-block command, so you
can immediately start hacking on an uncommented dup. Used with another command
to dump blocks to a junk file, it's like a wee block-level SCM.

~~~
Periodic
This is a pattern I tend to use as well because it lets you reference known
working code when changing things, and easily switch between development and
stable code. However, usually it's just one line, so "copy, paste, comment,
move" works well enough.

------
jff
The real solution is to make your code work properly every time.

Or, in Plan 9's acme editor, we just highlight the desired text and execute
the following command in the tag area: Edit s/^/\/\//g

Then when we're ready to go back, we just select again and do: Edit s/^\/\///g
which is the same as the previous command but with one forward slash moved.

Alternately, in almost every case it's easy enough to just stick in /* */
comments around it and delete them as necessary.

------
vlucas
I must say I didn't expect so much hate for this comment hack. Hack? That's
right, it absolutely is a hack - and it's definitely not the most elegant
solution.

I think a lot of people really missed the point here, and used comments as a
way to flaunt their clearly more impressive and infinitely superior geek
prowess by using IDEs and emacs.

The point was to present a solution that was fairly platform and language
agnostic. If I had included an IDE shortcut in the article, I would have had
to go through a long list of all the IDEs out there and all their
corresponding shortcuts. I would have then been inevitably flamed for missing
some or for not representing a specific programming language.

Oh, and don't forget to bash PHP or point out how much I suck at programming
for using PHP. Because everyone knows only cool developers and true geeks
don't use PHP.

------
bodhi
Seems to be a lot of hate on this trick here. One difference between this
trick and "I just press <shortcut key> in my IDE" is that this will comment
out one block of code, but will also _uncomment a second block at the same
time_.

------
nollidge
He keeps saying "backslash" when it's a forward-slash (or just "slash").

~~~
pbhjpbhj
Suppose it depends on whether your normal language is rtl or ltr?

------
akronim
> this trick will work with any language that supports both single-line and
> block style comments

isn't this just a horrible workaround for not having a debugger?

------
jackdawjack
uuh surely most editors can do this for you? m-x comment-region in emacs for
instance

~~~
wmeredith
I think the point of this is it's application agnostic.

------
jseifer
It's usually command / in TextMate.

