Lazy source code comment stunts

Double-Slash-Whole-Block-Commenting

Here is a simple way to disable or enable whole code blocks with just two slashes:

PHP / C++:

/*
  Block (commented block)
//*/
///*
  Block (active block)
//*/

Object Pascal/Delphi:

(*
  Block (commented block)
//*)
//(*
  Block (active block)
//*)

Alternatively you can use { and } in the Object Pascal/Delphi example.


Double-Slash-Whole-Block-Switching (Object Pascal/Delphi only)

The Object Pascal dialect used in Delphi supports three ways of commenting code, two for commenting whole blocks ( { } and (* *) ) and one for commenting lines ( // ).
We can exploit this feature to switch between two code blocks easily and fast:

Block 2 is in the enabled state:

{
  Block 1  (commented block)
(*}
  Block 2  (active block)
//*)

Note, I am just adding two slashes in front of the first comment block to activate it again – similar to Double-Slash-Whole-Block-Commenting trick above. This will also magically disable the second block due to the way the comment marks are arranged:

//{
  Block 1  (active block)
(*}
  Block 2  (commented block)
//*)

These tricks are probably applicable to other programming languages as well. Please let me know.

2 thoughts on “Lazy source code comment stunts

  1. Interesting will be read anout c# . If You can tell about. And If you have hard program task upload please all it on one of rapidshare search engine like this http://rapid4me.com

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.