Among them, there are good articles that are concisely organized.
Java language naming guidelines https://qiita.com/rkonno/items/1b30daf83854fecbb814
I agree with what is written here and think it should be. But what if you can't think of a good name?
Assuming that you follow the coding conventions in your project, I think the following is desirable:
FileOutputStream
For example, consider the name of a variable that stores a FileOutputStream
that is used to output some processing result.
fos
--- Fos …… ?? I don't understand. (I used this a long time ago when I regret it)fileOutputStream
--- I know the type. I think that the amount of information is small for the length.And so far. As the wise reader may have noticed, ** putting a type in a variable name doesn't make much sense **. Nowadays, it's easy to see what the variable type is in the IDE, and even if you don't use the IDE like me, it's okay if you make the class or method ** simple enough to easily see where the declaration is. .. The method arguments are of course explained in the ** API documentation **, so you don't need to put the type name in the argument name.
So what is a better name? As mentioned in the above article, ** I think the name is good because you can imagine the contents of the data by looking at the name **. In my own words, ** give it a name that describes who it is **.
For example
resultCsv
--- Oh, it's a CSV file with the results recorded.saleInThisYear
--- Oh, this year's salescommandOutput
--- Oh, what is the command execution result?It feels like.
XxxxService
XxxxService
with a one-to-one correspondence to XxxxController
could just be a service
.Example
public class XxxxController {
/**
*A service that handles the business of Xxxx.
*Since it is an implementation policy to substitute by constructor injection, here{@code @Autowired}Do not attach.
*/
private final XxxxService service;
I would be grateful if you could introduce in the comments what kind of class, what kind of field, what kind of method, what kind of local variable, with such a good name (or I thought it was amazing).
Recommended Posts