Writing Friendly Code 6.Working With The Unknown | WebReference

Writing Friendly Code 6.Working With The Unknown

home / web / dev / friendly

Writing Friendly Code

6. Working with the Unknown

After isReddy() is called by the onload event, init() verifies the loaded status of the document and calls setPg(). setPg() has the task of interpreting the document, which can contain any number of the containers the script will evaluate as "pages." 

The script engine has parsed the document, the stylesheet and the script body at this point. Everything except the background, the border, and a watermark graphic are hidden when the Web page first appears on the user's screen. The script now must build an array of pages for property and event references. It needs to decide what to call things, and where to find them. At the end of these deliberations, it simulates a user clicking the cover page button and eventually, in a second or so, the magazine cover and the navigation and other controls appear on the screen. 

As often happens when I work on a new project, I began with a much more complex model than I needed. Both version 4 browsers have the capacity to read a document and rewrite it from scratch. You can use outerHTML to replace content wholesale in IE; and document.layer.document.write() from Navigator. I went off in this direction for a while, and the code grew and grew.... It got out of hand.

The simpler you can write the code, the better it is. If something already exists, don't make another one, use that one. I  think this quote applies to writing code as much as it does to literature. It is from the Elements of Style, by William Strunk:

"Vigorous writing is concise. A sentence should contain no unneccessay words, a paragraph no unneccessary sentences, for the same reason that a drawing should have no unneccessary lines and a machine no unneccessary parts. This requires not that the writer make all his sentences short, or that he avoid all detail and treat his subjects only in outline, but that every word tell."

Works for me.

Laying out the Page 

Comments are welcome

 


Created: Dec. 2, 1999
Revised: Dec. 7, 1999

URL: https://webreference.com/dev/friendly/