CSE 154 Code Quality Guide() {
A relatively rational approach to web development for CSE 154 at the University of Washington. Portions of this guide were adapted from Airbnb’s JavaScript Style Guide.
Questions about the guide? We are always looking to improve our resources, feel free to reach out to the course staff with any questions or concerns!
General Guidelines
Comments
-
1.1 Always include a file header comment at the top of each file with your name, the date, your section and a brief description of what the file does. See HTML example below:
NOTE: In HTML, this comment must go after the
<DOCTYPE html>
.NOTE: In Node, make sure to mention all of the GET/POST parameters that your webservice takes in as well as its output! See more thorough discussion of this in the Node portion of this guide
<!DOCTYPE html> <!-- Name: Mowgli Hovik Date: 01.01.2019 Section: CSE 154 AX This is the index.html page for my portfolio of web development work. It includes links to side projects I have done during CSE 154, including an AboutMe page, a blog template, and a crytogram generator. -->
-
1.2 Always cite sources in your comments if you use anything found online.
NOTE: It is preferred to cite sources in the text content of the HTML so that your users actually see it!
BIG NOTE: You should not be citing any sources on homework assignments as everything should be your own work. Feel free to use outside artwork, quotes, etc. in your creative projects with proper citations. If you want to use code found online, ask your TA or instructor first then cite it with permission. Additionally, if you copy any lecture code for your creative projects, please cite that as well.
Whitespace & Indentation
-
2.1 Use soft tabs (space character) set to 2 spaces. You should use the same tab length across all of your files.
NOTE: Please refer to the setup guides linked on the course website if you are unsure of how to correct this. If you still run into issues please contact the course staff.
-
2.2 Never have consecutive newline characters in your code, even at the end of a file.
// bad function myFunc(foo) { if (foo === 'baz') { return true; } // ... } function myOtherFunc() { // .. }
// good function myFunc(foo) { if (foo === 'baz') { return true; } // ... } function myOtherFunc() { // .. }
<!-- bad --> <p>super cool paragraph</p> <p>other cool paragraph</p>
<!-- good --> <p>super cool paragraph</p> <p>other cool paragraph</p>
Long Lines
-
3.1 Always keep lines under 100 characters. It makes your code much easier to read. The one exception here is links. Any string containing a link can go over 100 characters.
TIP: Most IDE’s let you set a line on the screen at a certain character limit. Set it to 80 characters and avoid going over that to be extra careful.
File Names
- 4.1 All files names submitted in CSE 154 should use lowercase
naming. You may choose to separate words with a
-
character. For example, bothmycoolfile.js
andmy-cool-file.js
are valid file names.myCoolFile.js
is not.
Why? Different operating systems handle letter casing in different ways. Always using lowercase naming keeps our code consistent and prevents broken links on different systems.
Contributors
- Conner Ardman
- Melissa Hovik
- Tal Wolman
- CSE 154 Spring 2019 Staff
- CSE 154 Summer 2019 Staff
- Original Airbnb Contributors