{"id":71,"date":"2008-12-30T01:31:08","date_gmt":"2008-12-30T00:31:08","guid":{"rendered":"http:\/\/katastrophos.net\/andre\/blog\/?p=71"},"modified":"2008-12-30T12:50:32","modified_gmt":"2008-12-30T11:50:32","slug":"lazy-source-code-comment-stunts","status":"publish","type":"post","link":"https:\/\/katastrophos.net\/andre\/blog\/2008\/12\/30\/lazy-source-code-comment-stunts\/","title":{"rendered":"Lazy source code comment stunts"},"content":{"rendered":"<p><strong>Double-Slash-Whole-Block-Commenting<\/strong><\/p>\n<p>Here is a simple way to disable or enable whole code blocks with just two slashes:<\/p>\n<p><strong>PHP \/ C++:<\/strong><\/p>\n<pre name=\"code\" class=\"c++:nocontrols\">\r\n\/*\r\n  Block (commented block)\r\n\/\/*\/\r\n<\/pre>\n<pre name=\"code\" class=\"c++:nocontrols\">\r\n\/\/\/*\r\n  Block (active block)\r\n\/\/*\/\r\n<\/pre>\n<p><strong>Object Pascal\/Delphi:<\/strong><\/p>\n<pre name=\"code\" class=\"delphi:nocontrols\">\r\n(*\r\n  Block (commented block)\r\n\/\/*)\r\n<\/pre>\n<pre name=\"code\" class=\"delphi:nocontrols\">\r\n\/\/(*\r\n  Block (active block)\r\n\/\/*)\r\n<\/pre>\n<p>Alternatively you can use <code>{<\/code> and <code>}<\/code> in the Object Pascal\/Delphi example.<\/p>\n<p><strong><br \/>\nDouble-Slash-Whole-Block-Switching (Object Pascal\/Delphi only)<\/strong><\/p>\n<p>The Object Pascal dialect used in Delphi supports three ways of commenting code, two for commenting whole blocks ( <code>{ }<\/code> and <code>(* *)<\/code> ) and one for commenting lines ( <code>\/\/<\/code> ).<br \/>\nWe can exploit this feature to switch between two code blocks easily and fast:<\/p>\n<p>Block 2 is in the enabled state:<\/p>\n<pre name=\"code\" class=\"delphi:nocontrols\">\r\n{\r\n  Block 1  (commented block)\r\n(*}\r\n  Block 2  (active block)\r\n\/\/*)\r\n<\/pre>\n<p>Note, I am just adding two slashes in front of the first comment block to activate it again &#8211; 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:<\/p>\n<pre name=\"code\" class=\"delphi:nocontrols\">\r\n\/\/{\r\n  Block 1  (active block)\r\n(*}\r\n  Block 2  (commented block)\r\n\/\/*)\r\n<\/pre>\n<p>These tricks are probably applicable to other programming languages as well. Please let me know.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[2,20,17,19],"class_list":["post-71","post","type-post","status-publish","format-standard","hentry","tag-delphi","tag-development","tag-findings","tag-hack"],"_links":{"self":[{"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/posts\/71"}],"collection":[{"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/comments?post=71"}],"version-history":[{"count":15,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/posts\/71\/revisions"}],"predecessor-version":[{"id":96,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/posts\/71\/revisions\/96"}],"wp:attachment":[{"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/media?parent=71"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/categories?post=71"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/tags?post=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}