I wrote "in Java" in the title, but it's not a topic limited to a specific language. It happened that there was a lot of Java development these days, and I added "in Java" from the actual example at that time. I hope you can apply it to your own language other than Java.
So, if you write only the conclusion first, it will be like this.
- Borrow keywords from other languages. </ b> -- Borrow the naming of other libraries. </ b> * Including standard libraries in other languages
** (*'▽') If you are interested, please read on! ** **
Naming is very important in programming, especially in code that is read by an unspecified number of people, such as group development and open source. However, although very important, giving ** proper names ** to class and method names can be a more time-consuming task than you might think.
Anti-patterns related to naming are another big theme, so I will omit them this time, It can be a daunting task to give a good name that is easy to understand while avoiding bad naming.
With that said, I would like to introduce what I usually practice in order to ** give an appropriate name as efficiently as possible **.
I will write an article on Qiita again, so just writing what I usually do is not much different from ** Hatena Blog **. I thought, so I looked back on the naming pattern that I usually use when programming.
** (*'▽') Well, I think it's normal! ** **
As I wrote in the above thinking flow, "borrowing keywords from equivalent functions in other languages" is quite convenient. Specifically, here are some examples of "diversification" that I actually did.
Named the common parts that perform multithreading processing as async / await / aggregate.
When I made a multithreaded part that wraps Java's multithreaded standard implementation (java concurrency utilities) C # (strictly speaking, it was C # 3.x series) has an added function of async / await that allows you to write asynchronous processing concisely as a language syntax. As a considerable function, the naming of that area has been improved.
aggregate hasn't been added as a keyword, but it's been used as a common name for a long time.
I created a class called TryWithResources. (I understand the implementation details)
This is a straightforward name given to a utility class that can be used as an alternative to the try-with-resources syntax to ensure reliable resource release. Of course, this is an appeal that says, "I didn't need to create such a class if I could raise it to JDK7 !!" I also wrote in javadoc, "In the future, raise it to JDK7 or higher and erase this bad class." Well, I guess he still survives without being erased ...
Name the object that specifies the condition predicate, Or you could name such an interface IPredicate.
The LINQ method names (although most of them are the corresponding delegate names) are also very versatile and there are many good names that are easy to crack.
Borrowing a name from another implementation, especially using one that is at the keyword level, Beyond shortening the time to think of a name, there are the following merits, and this is my favorite.
-Because it is already defined, the information density is high. ――Information comes out in that word. ――If there is an official document, you can write the URL and skip the reference.
Especially the first merit is very big.
It is very effective to use ** defined names ** as a means of expressing systematic knowledge and information in a concise manner.
The amount of information that can be conveyed in one word is much larger than others, and the content that can be expressed with less code is enriched. It is a level where everything is completed with the first word if you are not good at it.
In other words, it's like ** using a design pattern for class design **.
Only one instance of this class is guaranteed to be created during a system process and is used for caching and sharing information that is common throughout the system.
Rather than saying
This class is a singleton.
It is faster and more accurate to say.
And in the javadoc see tag Wikipedia-singleton pattern Or something like that, just skip the reference.
This will save you the trouble of writing a long javadoc yourself, and will allow you to capture more general and open information.
Also, if it's a ** keyword **, it's almost certainly ** a language spec exists **, so the information (perhaps a standard document) will be hit immediately. Or, even if the standard documents do not hit, there is a high possibility that the introductory site (or blog, Qiita article, etc.) that explains them will hit, and there is an advantage that the searchability is high.
In my case, I often use the keyword that came from C # for naming, but in this case ** "If you google with this keyword and MSDN hits, it's the correct answer, so read it carefully !!" ** Fill in that with ** normal comments **.
If I can't find a good borrower, I'll do my best to give it a nice name. This area takes time, so I want to find it as easily as possible.
By saying that, I often refer to this area.
** Naming dictionary for programmers "Codic": ** https://codic.jp/engine
** Summary of cheat sheets that are useful when you are unsure about naming variable names and function names in programming: ** Starting with the introduction of Codic above, there are many other useful things for naming, please look for your favorite one https://nelog.jp/programming-words
** (*'▽') Thank you very much for your help! ** **
An epoch-making method of searching code on GitHub has been proposed. https://qiita.com/kyoshidajp/items/c5d4f060df636ea20cbb
I have found the strongest of the strongest naming cheat sheet. https://qiita.com/Ted-HM/items/7dde25dcffae4cdc7923
It's a convention about naming, or a guideline. https://qiita.com/takasek/items/693c57dc9ddc6c1eb1ba
Recommended Posts