I'm aware that I can use (* ... *)
to comment out stuff in a notebook. Many languages have a syntax for single-line comments, such as
//
in C, C++, Java, C#, ...#
in shell, Python, ...
For example, in C++ you can write
int x = 5;
// std::cout << "debug: x = " << x << std::endl;
return x;
in which the second line is commented out.
Is there a way to quickly comment out just one line in Mathematica, without having to type paired comment characters?
Answer
There is no way to comment out a single line.
Mathematica doesn't really respect lines, it pushes working at the expression level when possible (not at the source text level). Converting cells between different forms (StandardForm, InputForm) will even shuffle around newlines. Copying and pasting code does the same.
As @acl has mentioned, you can select a piece of code and comment it out with Alt-/. The shortcut Ctrl-. makes it easy to select subparts of expressions. These commands are found in the Edit menu (mentioning in case the keyboard shortcut is different on other platforms).
I am not advocating this behaviour, just explaining the current situation.
Comments
Post a Comment