-
Notifications
You must be signed in to change notification settings - Fork 3
Software Design Guidelines
Revisions
Name | Date | Change | Version |
---|---|---|---|
Bruce Schubert | 2015.07.05 | Initial Document | 1.0 |
Contents
[TOC]
This document provides insights for developers who want to extend or reuse the Wildfire Management Tool (WMT) web application framework.
- Open the Chrome DevTools: Ctrl+Shift+I.
- With Chrome DevTools open, click the >_ icon to open the "Drawer".
- Select the Emulation tab at the bottom.
- Click the mobile device icon in the top left.
- Then select the device model you want to test against in the Emulation tab.
You can extend the functionality of World Wind shapes and annotations by simply adding capabilities to them. The Wmt.Globe class has a SelectController that looks for the existence of the following capabilities on the picked object, and it will invoke the appropriate function for the user action:
- Movable:
- Openable:
- Removable:
- Selectable:
- ContextSensitive:
The Globe module encapulates the WorldWindow and its canvas. The Globe extends the WorldWindow by providing terrain data services such as aspect, slope and elevation.
The Controller performs services for the views. The Controller owns the Model.
- Publish/Subscribe pattern
WMT does not manifest any globals.
This section's guidelines are based for the most part on the Web World Wind Design and Coding Guidelines. The principle differences include JSLint and using NetBeans vs WebStorm for the project IDE.
- See the WMTweb Software Requirements Specification document for the product requirements.
- The project's development IDE is NetBeans. The NetBeans project configuration files for the project define the formatting rules.
- The Module pattern is followed for all functionality. All JavaScript code is captured within a module. There is only one global defined by Web World Wind, and that is the WorldWind singleton. It contains the constructors and static functions used throughout the rest of the World Wind library.
- http://requirejs.org/docs/api.html is used to support the Module pattern and to provide the Asynchronous Module Definition (AMD). Every module participates in RequireJS/AMD. See: http://requirejs.org/docs/whyamd.html
- WMTweb never crashes the browser. Always catch exceptions at least at the highest entry point, e.g., event listeners and thread execution.
- Variable and function names are clear, descriptive and easy to read. They are not labelled with a convention not described in this document. Use whole words rather than abbreviations, e.g., "index" rather than "idx". Correct all variable spelling warnings flagged by NetBeans. Add necessary ones to the project's dictionary.
- There are no "private" properties or functions/methods in WMTweb . Assume that a module extender will need access to all variables and functions of the module.
- Third party libraries are used minimally and strong justification is required for their use. Any usage of third party libraries must be agreed upon among the team and incorporated into the build system.
- Within a rendering pass, WMTweb does not access the disk or the network. Disk and network access is done asynchronously.
- WMTweb is designed such that the right things just happen once things are set up. The effect of something going wrong is benign. Avoiding micromanagement of state and code brittleness. For example, layers fork off retrieval of data but they don't try to keep track of these retrievals. If the retrieval succeeds then the data will be available the next time the layer looks for it. If it's not available at that point then the layer will simply ask for it again.
- All code uses the JavaScript "use strict" directive.
- NetBeans flags code errors and warnings as you write it. The errors are indicated by red and yellow markers in the right margin of a module's editor window. When a module is checked in there should be no red flags and all yellow flags should be addressed to the extent possible. Strive to have no warnings or spelling errors. In this case the square at the top of the right margin will be dark green.
- The system is designed such that memory allocation and usage is minimized by both the system and its applications. To that end most methods that compute and return a value of type other than Number accept a "result" argument in which to return the computed value. When that argument exists, validate that it is non-null and defined.
- Log any exceptions prior to throwing them. Use the same message for the log as for the exception. Use pre-defined logger messages (see WorldWind.Logger) when possible. Pre-define in Logger those messages expected to be used more than a few places.
- Ensure all exception messages are descriptive and helpful, but keep them short.
- Functions validate their arguments and throw the appropriate exception, typically WorldWind.ArgumentError, and identify the exception message the parameter name and the problem -- null, out of range, etc. Validation is a necessary part of the implementation; code should not be checked in without it.
- "Protected" methods whose calling client can't be trusted validate their arguments and throw an appropriate exception.
- When validating arguments, do not validate for type. Just validate non-Number arguments for existence and appropriateness to the function. Validate arrays for sufficient length when the necessary length is known a priori.
- All WMTweb code follows the same style and conventions and looks the same in style and format.
- WMTweb code is heavily commented. The comments describe both the what and how of a block of code.
- WMTweb variable and function names are descriptive.
- WMTweb follows the coding conventions described in Chapter 2 of the book JavaScript Patterns. These conventions are encoded in the NetBeans project files.
- Line length is 120 characters and indentation widths are 4 characters.
- Variable and function names use camel case. The exception is constructors, which capitalize their first letter. Constants are in all upper case with words separated by underscores.
- White space is preferred over packing code into a small space. Use white space liberally. Separate functional blocks of code with vertical white space. Think of code within a function as a sequence of paragraphs and separate each with a blank line.
- Set up NetBeans to insert the BSD 3-Clause standard license into new code files. The license template can be found in the Downloads section. See Tools > Templates | Settings and edit the User.properties file to set the properties used by the license template. Example:
#!properties
user=<Your Name>
copyright_holder=Bruce Schubert
contact=<[email protected]>
organization=Emxsys
- Static code analysis is performed by http://www.jslint.com/help.html.
- Run JSLint and address all errors and warnings prior to checking in any code.
- JSLint errors and warnings can be viewed in the NetBeans Actions Items window.
- Setup NetBeans to use the JSLint plugin. See Tools > Plugins > Available Plugins | JSLint to install, and Tools > Options > Miscellaneous | JSLint to configure. Use the following settings: 1. Assume console, alert, ... 1. Assume a browser 1. Tolerate dangling _ in identifiers 1. Tolerate ++ and -- 1. Tolerate unused parameters 1. Tolerate TODO comments 1. Tolerate messy white space
- The only globals that may be defined for a file are: //define// and //$//. Example:
#!javascript
/*global define, $, WorldWind */
- Documentation is generated by JSDoc.
- Run JSDoc and review the results prior to checking in any code. It's a convenient check on documentation and typing.
- Document all functions and properties. Mark those meant for internal use only as such.
- Code isn't complete until the documentation is written. Write all documentation when you implement the function or property. Don't wait until "later". Assume that you will never return to a module to "clean up".
- Use present tense in all documentation. Examples are: "Indicates that ...", "Computes ...", "Returns ...". Do not use terms like "Will compute" or "Will return".
- Ensure that the type of all documented arguments and properties is specified in the documentation. For arrays, use {Number[]} and {Vec3[]} and not simply {Array}.
- Use correct capitalization and full sentences to document everything. All function, parameter and error descriptions start with an upper case letter and end with a period.
- Ensure that all method arguments, return values and exceptions are documented.
- Use NetBeans to identify spelling mistakes in documentation. It will flag them with a wavy underline. 1. Class documentation goes in the @classdesc descriptor for the class' constructor.