Introduction To Programming Here are the coding standards for the course and a screencast overview. Your projects and labs will be graded partially on conformance to these rules. This document will be expanded as the semester progresses. The accompanying screencast is at the bottom.
One of the most important aspects of modern programming is readability. To be able to read code written by other people and understand it has become much more important than having condensed, optimal code. Modern programming languages can optimize your code better than you can. So, the number one criteria for the way we write is for other human beings to read it. These standards are about readability, making your could as readable as possible.
The unit of indentation of JavaScript source code will be four (4) spaces.
Avoid making any line of JavaScript code more than 80 characters. This improves readability. Sometimes this can't be avoided but when possible it is required to have 80 or fewer characters in a line of code.
Good documentation will be required in your labs and projects files. Here is a minimal list of what the instructor will be looking for. Quality counts!
Good variable naming and usage is very important when learning to program computers. Here is a list of the rules for variables:
How things are named in a computer program is very important. In the early days of programming names were very short and cryptic to save on RAM usage. You may have seen variables with names like "i", "fnme", and "cal_prc". These days our computers all have lots and lots of RAM and we can stop this old confusing habit. Here are the course rules for naming things:
// Good Names
var firstName;
var totalPrice;
var totalPriceForRedWidgets;
var customerCodeForNewNonUsRetailCustomer; // do programmers
// really do this?
// yes, we do
Semicolons are used in JavaScript to end a line. Most of the time they are not required by JavaScript. However, they are required in a few places so as a course standard, that is also a convention in the industry, the use of semicolons at the end of statements is required.
// Use of semicolons
var name = "Fred";
return name;
total = total + 100;
The way we write statements is critical for code that is readable and easy to understand. Here is how we're going to write JavaScript statements.
// WRONG WAY!
var name = "Fred"; var city = "Madison";
document.write(name + ", " + city)
// Right way!
var name = "Fred";
var city = "Madison";
document.write(name + ", " + city);
Whitespace can improve the readability of code. Here are the course standards for whitespace.
// Operator spacing
var name = "Fred";
var x = 1;
x = x + 1;