I know everyone is used to using correct layout and style for coding Java assignments. Since you are writing code for others to read and grade, it makes sense for the entire class to use a consistent style to enhance readability and maintainability.
This Style Guide puts forth the coding standards, conventions, and guidelines used in CS 350 for writing correct, high-quality, and maintainable XHTML, CSS, and JavaScript code. Emphasis is placed on readability and debugging -- and not on optimization. While you may disagree with some aspects of these standards, view than as our company policy and adhere to them to make your grader's life easier.
In addition to the standards, instructions are given for setting HTML-Kit's Preferences to make adherence to many of these standards automatic.
CS 350 Coding Standards
With the exception of the first Lab, always write your code to conform to XHTML 1.0 Strict. By choosing Strict, you are electing to enforce a clean separation between content and presentation - the key principle to achieving accessibility.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Even though it is technically correct, do not add the XML declaration as the first line.
<?xml version="1.0" encoding="us-ascii"?> <!-- Do NOT use this XML declaration -->
Microsoft Internet Explorer 6.0 and earlier goes into quirks mode if there is anything on the first line before the DOCTYPE, including the xml prolog declaration. A HTML comment, even an empty one, will cause the same problem.
Use the Edit Menu | Preferences ... | Tidy Tab to set
Follow the DOCTYPE with a file header comment to help the grader locate your work, indicate the amount of time you spent on completing the assignment, and state the CS 350 honor code.
<!-- Account: Enter your cs350 account number here File: U:\Lab2\index.html Honor Code: I pledge that this code represents my own work. I received help from (enter the names or write "no one") in designing and debugging my program. -->
If you work with HTML-Kit at home, an easy way to keep track of the time spent working on the assignment is to enable the time trackerwith HTML-Kit preferences
Next, use the Tools Menu | Time Tracker | Set User and add your name as the user
To check the work time for the assignment, use the Tools Menu |Time Tracker | View Report
This feature is not available in the Hebeler Labs due to write permissions to the C:\ drive.
At a minimum, use meta elements to make explicit the character set, page description (this can be as short as "Lab 2: Web Page Authoring with XHTML-Kit", keywords (again keep this short), and your name as author.
XHTML requires all pages to have the title element.
<meta https-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>CS 350: Lab 2</title> <meta name="description" content="Lab 2: Web Page Authoring with XHTML-Kit" /> <meta name="keywords" content="Web, Internet, XHTML, CS 350" /> <meta name="author" content="Your Name" />
Meta elements are easily inserted with HTML-Kit by clicking theDocument Plugin tab (standard with HTML-Kit) and using the METAtool and selecting the appropriate meta elements.
Tip: Set HTML-Kit to open new documents with your customized comments and meta elements. Go to HTML-Kit Preferences, select the Startup tab, check Insert following text into new documents: and paste your customized XHTML code in the text box.
Programmers use both horizontal (indentation) and vertical (blank lines) to enhance readability of code.
For example, 3 blank spaces are used for indentation to show the logical structure and blank lines between chunks of code to offset sections.
My own preference is to not use horizontal indentation with block elements. That is, block elements appear in column 1, i.e. the leftmost position to avoid dealing with line wrap and formatting of code generated with server-side scripting or DOM manipulation. This is certainly a minority position, but one that works for me. However, vertical white space between major chunks of information becomes especially important to show structure.
To see an example of this, use your browser's View Source menu item to view this page.
Horizontal indentation is optional in CS 350 - experiment both ways and see what you prefer. However, formatting for readability, regardless of horizontal indentation, is required for the purposes of grader sanity.
Should you wish to use horizontal indentation to highlight the structure of your XHTML code, Tidy's settings allow you to toggle on or off indentation of content.
Use the Edit Menu | Preferences ... | Tidy Tab to set
Feel free to experiment with the white space -- keeping in mind that your goal is to enhance the readability of your XHTML code by others.
You may wish to have two custom config file settings to use with Tidy, one for on-screen display and one for printing, and switch between the two by selecting "Run with custom config file".
In most cases, we ask that you submit two printouts: both your XHTML code and your page as displayed in the browser. This allows us to annotate your printouts with comments and problem areas.
Use the Edit Menu | Preferences ... | Print Tab to set
You may also consider reducing the Editor Text Font size when printing to save paper.
We will write code that conforms to CSS 2 recommendations. Be sure to validate your CSS with the W3C CSS validator (using HTML-Kit's OnlinePlugin).
As much as possible, use external style sheets to provide a uniform, maintainable look to your Web pages. Limit the use of embedded and inline CSS to override the external style sheet (or for occasional single-time formatting). Consider using the media attribute with separate external style sheet(s) to control the way your Web pages print.
Best Practices
/* Account: CS35002_nn File: U:\Lab4\lab4.css Author: Your Name */ BODY { background-color: #FFFFFF; color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 90%; } A { background-color: transparent; color: #0000FF; } A:hover { background-color: #FEFF00; color: #FF0000; }
Even though JavaScript is a programming language in its own right, many programmers seem to forget about coding standards with JavaScript. In general, follow the same coding guidelines as you would with Java.
The PHP standards are based on the PEAR Coding Standards, but simplified somewhat to better fit the requirements of CS 350 and smaller student assignments.
<?php ... ?>
to delimit PHP code, not the <? ?>
shorthand<?php $age = 100; // global variable used for testing only //define two constants for minimum and maximum ages define("MIN_AGE", 21); define("MAX_AGE", 90); //determine if the user is of legal age if ($age < MIN_AGE) { print("too young"); } elseif ($age >= MAX_AGE) { print("too old"); } else { print("perfect"); } ?>