Skip to content

Chat about how to choose the line symbol "-" and the underline symbol "_" in naming and their scope of application

Original link: https://www.itylq.com/how-to-use-hyphen-underscore-symbols.html

Release date: 2024-10-14 Migration time: 2026-03-21

When naming directories and files, we often struggle with whether to use the center line "-" or the underscore "_". The various software installation packages that we come into contact with every day are also named in a variety of ways. Some use center lines, some use underscores, and some use a mixture of center lines and underscores. It is a mess.

1 Depends on the use

The purpose of introducing midline or underline symbols when naming is to be used as separators to improve the readability of information. At this point, the center line symbol "-" and the underline symbol "_" have the same effect, and they can well separate different texts, words, and numbers.

2 Look at conflict items

The center line symbol "-" can represent the subtraction operator in programming languages, which can easily cause conflicts. Especially for a string named purely with numbers, if some part of it is separated by a center line symbol, it is likely to be performed as an arithmetic operation. Therefore, the center line symbol "-" is not suitable to be used in the programming field. Underscore "_" does not have this problem.

3 Look at common habits

The common habits here do not refer to the common habits of individuals, but to the usage habits of most users in a certain field or a certain platform. For example, in many programming languages ​​or frameworks, underscores "_" are often used to name variables, functions or classes to improve readability (of course, camel case naming with capital letters can also improve readability).

Based on the above three considerations, I think, similar to the long-term practice in Linux, when you need to name directories and files (including various software compressed packages and exe executable files), use the center symbol "-" to separate them; and when naming variables, functions or classes in various programming codes, including various types of scripts, it is better to use the underscore symbol "". **As for the mixed use of the dash symbol "-" and the underline symbol "", that is a very stupid way to use it and will only bring more confusion and confusion.

4 additional

It is also common to see the use of spaces " " as separators to name directories or files. In terms of improving the readability and aesthetics of information, spaces are also a better way to separate. However, spaces will bring a series of troubles and problems to URL encoding, file transfer, command execution, etc. Therefore, in actual use, you should try to avoid using the space symbol " " as a naming separation. It is worse than either the center symbol "-" or the underline symbol "_".


This article was moved from WordPress to MkDocs