Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Introduction
This standard defines how your code should be styled for assignments and projects while studying here in the department. By following these conventions, you will produce code which is more readable and easier for you or someone else to follow. These guidelines apply to all programming languages. The examples are shown in Java. Being able to write clean legible code will also improve your employability.
Identifiers
Variables/Attributes
Identifiers for all attributes and variables should be meaningful and if appropriate contain its own unit of measure. The unit of measure helps in understanding how to use it without reading the comments. Variables/attributes should always start with a lower case letter. Always use camel case to help aid reading of identifies, so an upper-case letter is introduced for every new word.
Examples:
float weightInKilos; float heightInMetres; float delayInMilliseconds;
Class Identifiers
Class identifiers always start with an uppercase letter and should always be a noun. So, Encryption is not a good name but Encryptor or EncryptionHelper are fine.
Examples:
Person Doctor Appointment
Constants
Identifiers of constants should always be expressed in uppercase, unless and only unless there is a necessary convention to use lowercase (for example to distinguish between g (ac-celeration due to earth’s gravity and G the universal gravitational constant). For constants underscores are used to separate words.
Examples:
public static final float PI=3.149265445; public static final int COLUMNS=10;
Method Names
Method names should start with a lower case letter and then follow camel case. All method names should be verbs.
Examples:
The code should ideally be what is termed self-documenting, that is it is simple enough to understand without keeping on referring to the comments. If the code is hard to follow then it should be simplified and in some cases broken up.
Comments must always precede the part of the code that they refer to. Comments should not go over the right hand side of the edit window. If a comment is too long, then it should be broken down over several lines.
Javadoc
All comments in Java programs should follow the Javadoc format, this allows code docu-mentation to be generated automatically.
Class Comments
All classes should start with a preamble describing the purpose of the class, what data it stores and what services it provides, so that a user of the class can quickly determine how to use the said class.
Method Comments
At a minimum each public method in a class should be commented. This is vital since the public methods are the public interface to the code. Each method should have comment to both the input variables and the returned values (if there are any).
Example:
If in the preparation of your code you have used specific ideas or code fragments that you have found on-line or in a textbook, then you must include references to those source in your
comments and indicate clearly which part of the code is based on those. The reference must be precise:
• If you have used a textbook then you must point to the specific page, pages, or figure that you have used.
• If you have used an answer to a question on, say, stackoverflow, then you must point to that specific answer, including a URL to that answer.