Comments prevent execution

Wednesday 19 October 2005

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!

tagged: » 3 reactions

Comments

[gravatar]
Jerry Glover 5:30 PM on 19 Oct 2005

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]
Bob 6:07 PM on 19 Oct 2005

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]
xtian 5:31 AM on 20 Oct 2005

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:

name
email
Ignore this:
not displayed and no spam.
Leave this empty:
www
not searched.
 
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.