coding guidelines - consistent variable naming [closed]
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
开发者_Go百科Closed 6 years ago.
Improve this questionI am currently writing a coding style guideline for junior devlopers, and I am curious if anyone uses list of common variable names (for basic concepts), to limit confusion in codebase?
For example:
- for email address: email (and not: mail, e-mail, address, *mail_address* ...)
- for database name: dbname (and not: db, dbase, base, database, *database_name*, dbn ...)
- for file name with full qualified path: filepath (and not: file, path, *file_name*, pathtofile ...)
- for relative file name (without path) : filename (and not: file, name, f, ...)
- for configuration object : config (and not: configuration, conf, vars, ...)
Do you use similiar conventions?
Edit:
To be precise: it is not about formatting convention (camelCaps or *names_with_underscores*) which tends to be language and project dependant, but about naming convention (mail, email or courriel), something which is common for all the languages (like convention of using i, j, k for iteration counters)
Pick a consistent convention and stick to it.
Your suggested convention is not consistent. email is using the English word, so instead of dbname you should use database_name. Also, file_path, file_name, configuration.
In short, I suggest full English words, separated by '_'. This is consistent and is the convention used in Eiffel. Other systems may be consistent, too. But not a mix of everything.
This is micro management of the worst kind. Just say "Try to use clear nonambiguous variable names." Tell them to prefer longer names and just use code completion to save typing.
Use pair programming and code review if you need to teach juniors to write code that makes sense to other people.
You need to trust them to do the right thing and correct them when they don't.
And don't make up your own conventions, it's very likely the language you're using already has conventions in its culture, like for example camelCaseForVariableNames in Java. Just follow those.
Many people usually prefer to adopt the conventions already adopted in the language they use.
E.g. in java it would be databaseName and in C++ database_name
精彩评论