写了段很实用的 prompt,作用是给程序开发里的变量起个规范的名字。
这玩意虽然技术难度很低,但是吧,对于我们这种没有系统工程经验的业余开发者是真的很实用。
随手分享一下👀
欢迎推荐给你的 老是乱给变量起名导致协作困难 的开发同事😂
📚中文版
# 背景:
我是一名程序员,负责软件开发,并且是一名以中文为母语的人。
在我的工作中,我最头疼的问题是给程序中的变量起合适的名字。
# 任务:
我将向你输入一个中文名词,请你先理解这个名词在程序开发中的作用,并返回5个合适的英文变量名给我。
# 要求:
1. 有意义:变量名应该清楚地表达变量的用途和存储的数据类型。
2. 简洁:变量名应尽可能短,但同时足够描述性。
3. 避免缩写:除非是广泛认可的缩写,否则应避免使用缩写,因为它们可能会引起混淆。
4. 使用驼峰命名法:在许多编程语言中,驼峰命名法是一种常见的命名约定,其中第一个单词的首字母小写,后续单词的首字母大写。
5. 避免使用保留字:不要使用编程语言的保留字作为变量名。
6. 使用名词:对于变量,通常使用名词来命名,因为它们代表数据。
7. 避免使用数字:除非有特殊需要,变量名通常不包含数字。
8. 保持一致性:在整个项目中应保持命名风格的一致性。
9. 避免误导性名称:不要使用可能会误导读者的名称。
10. 考虑上下文:变量名应在其使用的上下文中有意义。
11. 使用复数形式:如果变量存储一系列对象,可以使用名称的复数形式。
12. 避免特殊字符:变量名不应包含特殊字符,如$、@、#等。
13. 考虑国际化:如果软件需要支持多种语言,变量名应避免使用特定语言的词汇。
14. 遵守语言规范:不同的编程语言可能有不同的命名约定,应予以遵守。
15. 避免使用拼音:除非是中文编程环境,否则不建议使用拼音作为变量名。
16. 考虑可搜索性:变量名应易于搜索,以便在代码库中快速定位。
17. 避免过长的描述性名称:虽然描述性很重要,但过长的名称可能会降低代码的可读性。
18. 避免非ASCII字符:除非是特定语言的字符,否则应避免使用非ASCII字符。
19. 避免使用易混淆的字符:例如,l(小写L)和1(数字一),O(大写O)和0(数字零)。
📚 英文版(更节省 token)
# Background:
I am a programmer, responsible for software development, and a native Chinese speaker.
In my work, my biggest headache is to give proper variable names to the variables in the program.
# Task:
I will input a Chinese noun to you, please understand the role of this noun in program development first, and return 5 suitable English variable names to me.
# Requirements:
1. Meaningful: The variable name should clearly express the purpose of the variable and the type of data stored.
2. Succinct: variable names should be as short as possible, but at the same time be descriptive enough.
3. Avoid abbreviations: Avoid abbreviations unless they are widely recognized, as they can be confusing.
4. Use camelCase nomenclature: In many programming languages, camelCase is a common naming convention in which the first word has a lowercase initial letter and subsequent words have uppercase initial letters.
5. Avoid reserved words: Do not use reserved words of a programming language for variable names.
6. Use nouns: For variables, it is common to name them using nouns because they represent data.
7.Avoid using numbers: Unless there is a special need, variable names usually do not contain numbers.
8. Consistency: Consistency in naming style should be maintained throughout the project.
9. Avoid Misleading Names: Do not use names that may mislead the reader.
10. Consider the context: a variable name should make sense in the context in which it is used.
11. Avoid single-letter variable names: Unless it is a cyclic variable, avoid single-letter variable names because they usually lack descriptiveness.
12. Use the plural form: If the variable stores a collection of objects, you can use the plural form of the name.
13. Avoid special characters: variable names should not contain special characters such as $, @, #, etc.
14. Consider internationalization: If the software needs to support multiple languages, variable names should avoid language-specific words.
15. Adhere to language specifications: Different programming languages may have different naming conventions that should be adhered to.
16. Avoid Pinyin: Unless it is a Chinese programming environment, it is not recommended to use Pinyin for variable names.
17. Consider searchability: variable names should be easily searchable for quick location in the code base.
18. Avoid long descriptive names: Although descriptive is important, too long names may reduce the readability of the code.
19. Avoid non-ASCII characters: Avoid non-ASCII characters unless they are language specific.
20. Avoid confusing characters: for example, l (lowercase L) and 1 (the number one), O (capital O) and 0 (the number zero).