Using prefixes for different scopes
Variable prefixes should be used in the general
Java coding conventions. It will improve code readability and is supported by major IDE's like eclipse and WSAD.
I propose following prefixes:
| Variable type | Prefix | Example |
|---|
| Field | f | fExampleVariable |
| Static Field | s | sExampleVariable |
| Parameters | p | pExampleVariable |
| Local Variables | l or <none> | lExampleVariable or exampleVariable |
These additional conventions are easy to remember and I think in some case they can be just as important as using design patterns. Just like any convention they are difficult to enforce. A good coder can easily recognize a well defined design pattern that is used in particular program, which makes this coder more efficient. The variable prefixes convention serves the same purpose. If people choose one convention and always follow it, it will be huge help during code reviews and/or sharing ownership of parts of the program developed by the team (rather then by a single individual).
Spelling out data types
I propose to use fully spelled out data types (with the appropriate prefixes of course). For example if the data type called
UserAccount, the parameter passed to the method should be called
pUserAccount. In case of primitives, Strings or other generic data types, we should name the variable in such a way that it will be obvious what purpose in our code it serves. For example:
String sAccountDoesNotExistErrorMessage = "Account Does Not Exist";
//instead of String sAccDNExErrMess or some thing like that
This approach to naming variable used to be a challenge when good tools didn't exist and everything had to be typed by hand. Every modern IDE will have word completions available these days.