can I disable entire sections of code temporarily
267 visualizzazioni (ultimi 30 giorni)
Can I disable entire sections of code temporarily?
I have a large code that contains different scenarios. I'm working on one scenario and I'd like to disable the other sections, just while I'm working on that bit so that I can run the code quickly without having to wait for it to do all the other stuff too.
Più risposte (2)
Daniel Shub il 28 Mar 2012
You can enclose code in an if block
or even better (since you can include invalid syntax) would be to use block comments
The nice thing with block comments is that you can comment the comment
to reactivate the code. The only thing to be careful with is if you auto indent and/or autowrap the code in the block comment your line breaks can get screwed up.
Jason Ross il 28 Mar 2012
Usually when I get to a place where the code has gotten this large, a little voice in my head starts screaming "PUT IT IN A FUNCTION" (or subroutine, or module, or whatever means the language I'm coding in has to compartmentalize a section of code). That way I can separate the overall program flow from the detailed bit of what each step of the program is doing. And then it becomes simple to control that flow with a comment or other conditional method.