I understand how important it is to choose an appropriate name that reflects your intentions whenever it is possible, and how it can impact your code quality.
For example, below are some methods 开发者_如何学Pythonin java.math.BigDecimal that I consider having an interesting parameter names :
BigDecimal add(BigDecimal augend);
BigDecimal divide(BigDecimal divisor, int scale, RoundingMode roundingMode);
BigDecimal multiply(BigDecimal multiplicand);
BigDecimal subtract(BigDecimal subtrahend);
Such methods are always made me realize that knowing some specific notations and terms is a great help for improving your code, hence I think it would be good if I know them better.
Recently I've found a really good website that gives you a list of commonly used terms in mathematics, and I wonder is there any similar resources (whether in networking, physics, or any other fields related to programming) that can improve your vocabulary as a programmer?
Please keep in mind that what I meant here is not a coding standard, such as Zend Naming Conventions.
I find Wikipedia to be a good resource for this.
For example, when I needed a variable to store am
or pm
, I previously called it ampm
.
A short while back, I looked into it and now name it meridiem
.
I'd say that there are glossaries for multiple fields which might help in finding good terms but generally it's also a matter of experience and conventions that your team sets for itself.
A problem with naming is that others reading a name might not know how to interpret it and thus you should at least add a comment explaing the meaning of the class/field/method.
Other than that, I'd suggest to name the methods by their purpose or the algorithm they use, e.g. sort
or quicksort
. If you implement an algorithm from a specific area, you should be familiar with that area or at least that algorithm, result in less problems with naming. (Example: if I implement a method to calculate the levenshtein distance of two strings I'd name the method something like int calcLevenshtein(String arg1, String arg2)
).
精彩评论