SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Invisible Comments

By Leon Platt, 2001/04/26

Total article views: 3355 | Views in the last 30 days: 10

Tip of the month -
INVISIBLE COMMENTS - Now you see'em, Now you don't

If you've read any of my articles or downloaded any of my code you will quickly discover that I love using client-side JavaScript. You'll also discover that I write almost as many comments as I write lines of code. This is great for my colleagues at work. This stuff's hard enough to understand without good commenting. I ran into a dilemma when I was told that I should not allow potential competitors to view my JavaScript comments. If they wanted to figure the code out; make them work for it.

This was simple enough to do; so I thought. I simply wrapped my comments in ASP script tags <%..comments..%> and put a ' in front of each line to make the ASP interpreter think it was an ASP comment. The results were great, competitors could no longer see my comments. An added advantage of this was that the comments no longer needed to be sent to the clients browser! Check it out, smaller HTTP packets! This can make a big difference if you comment like I do! Unfortunately, when I did this my color scheme in InterDev was thrown completely out of whack. You see I like to make all my comments appear as white text on a green background. I thought to myself, what am I going to do? I can't program without green comments!

Determined as I am, I finally found my solution. Wrap the ASP tags in a JavaScript comment. So what I ended up with was, a JavaScript comment, wrapped by a ASP comment, wrapped by another JavaScript comment. My color scheme works, my collages can see my comments, my competitors need to work to figure out my code, and my boss is happy. Note: not all three layers are necessary to achieve my results. I could just use ASP comments wrapped by JavaScript Comments. However, doing it with the three layers allows you to do search and replaces on your JavaScript comments without getting them mixed up with your real ASP comments.

While we're talking about comments, I just want to throw in something about Microsoft's new C# language. If you've ever looked at any C# code, you may have seen comments done in XML format. We all like XML right? This really hit me as a great idea. So....Why not implement this in your current ASP or VB code. There's no reason why you can't. A comment is a comment. A XML comment is still a comment, but is there anything to be gained by doing this? Well, it would make it really easy to write an VB add-in to document your code. How about using XPATH to search all your code for certain functions or subroutines? What about shareware sites where you have people searching for code to solve a particular problem. No more keeping a separate database with keyword indexes. The source code has everything you need. Just for thoughts....

An example of Leon's JavaScript commenting
JavaScript Comments, wrapped by ASP comments, wrapped by JavaScript comments.

/*<%
'//<FUNCTION>display_book(whichone,tmpbookIndex)
'//<HEADER>
'//---------------------------display_book()--------------------------
'//
'//	<CALLED BY> get_books(),vcr(),allbooks_onclick(),movebook(),Ddelete_onclick(),Spaste_onclick()
'//</CALLED BY>
'//
'//	<INPUT>	whichone - 1=saved book list  0=queried book list
'//			tmpbookIndex - the books position in the list
'//	</INPUT>
'//		
'//	<PURPOSE>  Select the current book from the dom containing all books
'//				query the book object and get the info to populate the form controls
'//				update the listbox containing the IDs of all books in the dom
'//</PURPOSE>
'//
'//	<OUTPUT>	 Xbooknumber - the current books position in the list
'//				objXbook - an object containing all info on the current selected book
'//</OUTPUT>
'//
'//	<DEVELOPER>	Leon Platt</DEVELOPER>
'//
'//	<DATE>    Feb 18, 2000  </DATE>
'//</HEADER><CODE>
'//%<*/
function display_book(whichone,tmpbookIndex)
  {  
  if (tmpbookIndex<1) return;
  if (whichone==1)  //Saved book list
	{
		Dbooknumber = tmpbookIndex;
		//the position of a book in the DOM is always Dbooknumber - 1 
		objDbook= objDallbooks.childNodes.item(1).childNodes.item(Dbooknumber-1);
		var DbookName= objDbook.selectSingleNode("FIELD[@gcolumnname='title']").text.toUpperCase();
		/*<% '//display the book name%>*/
		document.all.Dbookname.innerText=
		 DbookName;varDbookType=objDbook.selectSingleNode("FIELD[@gcolumnname='type']").text;
		/*<% '//display type of book%>*/
		document.frmFields.Dtype.value=
		 DbookType;varDbookWhen=objDbook.selectSingleNode("FIELD[@gcolumnname='pubdate']").text;
		/*<% '//display when the book was published%>*/
		document.frmFields.Dwhen.value=
		 DbookWhen;varDbookPrice=objDbook.selectSingleNode("FIELD[@gcolumnname='price']").text;
		/*<% '//display the book price%>*/
		document.frmFields.Dprice.value=
		 DbookPrice;varDbookSales=objDbook.selectSingleNode("FIELD[@gcolumnname='ytd_sales']").text;
		/*<% '//display the books year to date sales%>*/
		document.frmFields.Dsales.value=
		 DbookSales;varDbookid=objDbook.selectSingleNode("FIELD[@gcolumnname='title_id']").text;
		/*<% '//display the book id%>*/
		document.frmFields.Dtid.value=Dbookid;
		/*<% '//display book xx of xx %>*/
		document.all.Dbookid.innerText="[ "+Dbooknumber+" of "+Dnumberofbooks+" ]";
		/*<% '//set the length of the list box to the number of books%> */
		document.frmFields.Dallbooks.length=Dnumberofbooks;
		/*<%'//get the notes about the book%> */
		var Denglish = objDbook.selectSingleNode("FIELD[@gcolumnname='notes']").text;
		/*<%'//display the books notes%>*/
		document.all.Denglish.children(1).innerHTML=Denglish;
		/*<%'//fill in the available books list box with the current books from the xml doc%>*/
		for (i=
		0;i<Dnumberofbooks;i++)
			{document.frmFields.Dallbooks.options[i].text=objDallbooks.childNodes.item(1).childNodes.item(i).selectSingleNode("FIELD[@gcolumnname=
			'title_id']").text;document.frmFields.Dallbooks.options[i].value=objDallbooks.childNodes.item(1).childNodes.item(i).selectSingleNode("FIELD[@gcolumnname='title_id']").text;
		}
		document.frmFields.Dallbooks.selectedIndex=Dbooknumber-1;
	}
	/*<%'//</CODE></FUNCTION>*/

By Leon Platt, 2001/04/26

Total article views: 3355 | Views in the last 30 days: 10
Your response
 
 
Related tags

ASP    
Programming    
 
Related content

ASP and ADO Gotcha - Duplicate Field Names in a Query

By Leon Platt | Category: ASP
(not yet rated) | 3,267 reads

Outlook Appointments, ASP and vCalendar

By | Category: ASP
| 5,358 reads
Like this? Try these...

Meeting Bingo

By Steve Jones | Category: The Lighter Side
| 4,018 reads

ASP and ADO Gotcha - Duplicate Field Names in a Query

By Leon Platt | Category: ASP
(not yet rated) | 3,267 reads
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com