The Official BLOG and Wiki for CustomMode.com
[ start | index | login ]
start > Naming Variables

Naming Variables

Created by dmitry. Last edited by dmitry, 3 years and 360 days ago. Viewed 360 times. #4
[diff] [history] [edit] [rdf]
labels
attachments

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 typePrefixExample
FieldffExampleVariable
Static FieldssExampleVariable
ParametersppExampleVariable
Local Variablesl 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.

no comments | post comment
custommode.com | ©2000-2005
webmaster at custommode dot com