Comments prevent execution

Wednesday 19 October 2005This is more than 19 years old. Be careful.

Looking for basic information about ASP.NET syntax, I found this description of Server-Side Comment Syntax. It explains:

Server-side comments enable page developers to prevent server code (including server controls) and static content from executing or rendering. The following sample demonstrates how to block content from executing and being sent down to a client.

There you have it: the point of a comment is to prevent a chunk of code from executing. There’s no mention of using comments to communicate with other developers. This helps explain a number of Daily WTF’s!

Comments

[gravatar]
Another developer recently told me the following code commenting philosophy one of his old colleagues swore by:


"If it's hard to write, it should be hard to read and even harder to change."

[gravatar]
Comments are to prevent server code from executing? The author deserves a dope slap.

Note: the text does make an important, if muddled, point that everything between <%-- and --%> is filtered out. In other words, unlike HTML comments, these comments aren't sent to the client. An important distinction if the comments contain proprietary information -- or snide remarks. ;-)
[gravatar]
As well as what Bob said, they really do mean what they say about it stopping code from executing.

If you have a server control in an ASPX page, and you comment it out with <!-- -->, the control will still be rendered on the server into the resulting HTML (which will be hidden on the client because of the comment tags), and any side-effects it might have (database updates, web-service calls, etc) will still take place. With the <%-- --%> comments, the server-side execution won't happen.

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.