英文:
Does the method name need to be grammatical?
问题
我有一个看起来有点傻的问题,我的英文不是很好,我经常不知道该如何命名变量或方法。
举个例子,有一个方法,它的功能是打开一个用于创建用户的模态框,我会将其命名为 openCreateUserModal
,它对应的英文句子是 "open create user modal",我认为这样的表达在英语中不太符合语法,因为有两个动词。是否将其命名为 openCreatingUserModal
会更好?或者方法的名称不需要遵循英语语法?
我想得到一个命名复杂方法的规则。
英文:
I have a question that may seem silly, my english is not very good, I often don't know how to name variables or methods.
For example, There is a method, its function is to open a modal for creating users, I will name it openCreateUserModal
, Its corresponding English sentence is "open create user modal", I think this is not grammatical in English because there are two verbs. Would it be better to name it openCreatingUserModal
?Or the method name does not need to follow English grammar?
I want to get a rule for naming complex methods
答案1
得分: 0
openCreateUserModal是完全合适的。它清楚地传达了函数的作用。在这种情况下,遵循英语语法规则并不重要,只要函数名清楚地指示函数的作用即可。
由于您没有提到任何特定的语言,以下是C#命名约定的来源。这些原则适用于任何编程语言。
https://csharp-book.softuni.org/Content/Chapter-10-methods/method-naming/method-naming.html
英文:
openCreateUserModal is perfectly fine. It clearly conveys what the function does. Following the rules of english grammar is not important in this context as long as the function name clearly indicates what the function does.
Since you haven't mentioned any particular language, below is a source c# naming conventions. The principles are the same for any programming language.
https://csharp-book.softuni.org/Content/Chapter-10-methods/method-naming/method-naming.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论