Commenting out portions of code in Scala
- by akauppi
I am looking for a C(++) #if 0 -like way of being able to comment out whole pieces of Scala source code, for keeping around experimental or expired code for a while.
I tried out a couple of alternatives and would like to hear what you use, and if you have come up with something better?
// Simply block-marking N lines by '//' is one way...
// <tags> """ anything
My editor makes this easy, but it's not really The Thing. It gets easily mixed with actual one-line comments.
Then I figured there's native XML support, so:
<!--
... did not work
-->
Wrapping in XML works, unless you have <tags> within the block:
class none { val a= <ignore>
...
cannot have //<tags> <here> (not even in end-of-line comments!)
</ignore> }
The same for multi-line strings seems kind of best, but there's an awful lot of boilerplate (not fashionable in Scala) to please the compiler (less if you're doing this within a class or an object):
object none { val ignore= """ This seems like
...
<truly> <anything goes> but three "'s of course
""" }
The 'right' way to do this might be:
/***
/*
... works but not properly syntax highlighed in SubEthaEdit (or StackOverflow)
*/
***/
..but that matches the /* and */ only, not i.e. /*** to ***/. This means the comments within the block need to be balanced. And - the current Scala syntax highlighting mode for SubEthaEdit fails miserably on this.
As a comparison, Lua has --[==[ matching ]==] and so forth. I think I'm spoilt?
So - is there some useful trick I'm overseeing?