我该如何命名这个简单的方法呢?

发布于 2024-08-09 07:35:11 字数 331 浏览 4 评论 0原文

首先,这实际上并不是一个编程问题。这更像是一个“我如何满足 McConnels 命名约定?”的问题。

我有这个处理 Word 文档的 Delphi 应用程序。我需要做的一件事是遍历文档中的所有书签,并根据一个简单的规则删除其中一些书签:如果我当前处理报价,我将删除名称以“cw_orderspecic”开头的所有书签。如果我处理订单确认,我将删除所有名称以“cw_quotespecic”开头的书签。

该方法已就位,一切正常,但我有一个小问题。我应该如何称呼我的方法?当前名称(“DeleteBookmarksNotAllowedForCurrentDocumentType”)太长。

有什么建议吗?

First of all, this is not really a programming question. It's more a question of "how do I satisfy McConnels naming conventions?"

I have this Delphi-application that manipulates word-documents. One of the things I need to do is run through all the bookmarks in the document and delete some of them based upon a simple rule: If I currently work on a quote I will delete all bookmarks where the name begins with "cw_orderspecific". If I work on an order confirmation I will remove all bookmarks with names beginning with "cw_quotespecific".

The method is in place, and everything works perfectly, but I have a tiny problem. What should I call my method? The current name ("DeleteBookmarksNotAllowedForCurrentDocumentType") is too long.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

妥活 2024-08-16 07:35:11

更改函数以获取要删除的前缀,并将其命名为 DeleteBookmarksWithPrefix:

DeleteBookmarksWithPrefix("cw_quotespecific")

DeleteBookmarksWithPrefix(otherWorkTypePrefix)

这使得代码非常可读,并且使该函数可以在其他情况下重用,而不是仅对一个非常特定的情况有用任务。

请注意,如果您有第三种工作类型,您可能需要颠倒它的含义:

DeleteBookmarksWithoutPrefix(currentWorkTypePrefix)

Change the function to take the prefix to delete, and call it DeleteBookmarksWithPrefix:

DeleteBookmarksWithPrefix("cw_quotespecific")

or

DeleteBookmarksWithPrefix(otherWorkTypePrefix)

That makes the code very readable, and it makes the function reusable in other circumstances, rather than only ever being useful for one very specific task.

Note that if you'll ever have a third work type, you might want to reverse the sense of it:

DeleteBookmarksWithoutPrefix(currentWorkTypePrefix)
与风相奔跑 2024-08-16 07:35:11

删除不相关的书签?

DeleteNonRelevantBookmarks ?

骑趴 2024-08-16 07:35:11

你想要多短?我的第一反应是放弃一些看起来不那么重要的话。就像DeleteBookmarksNotAllowedForDocumentType、DeleteBookmarksNotAllowedForDocument 或简单地DeleteBookmarksNotAllowed 一样。虽然我可能更喜欢像DeleteInvalidBookmarks 这样的东西。当然,这仅在没有其他方法按不同规则删除书签的情况下才有效。
或者,如果您愿意改变方法函数的方式,我会通过将前缀作为参数来使其更加通用,然后命名会更简单。

How short you want it to be? My first instinct is to drop some words that don't seem that important. Like DeleteBookmarksNotAllowedForDocumentType, DeleteBookmarksNotAllowedForDocument, or simply DeleteBookmarksNotAllowed. Though I'd probably prefer something like DeleteInvalidBookmarks. Of course this works only if there are no other methods that delete bookmarks by different rules.
Or if you're willing to change the way you method functions, I'd make it more generic by giving the prefix as a parameter, then the naming would be simpler.

凉风有信 2024-08-16 07:35:11

使用缩写词?在注释中定义 CDT 是“当前文档类型”,您将得到 DeleteBookmarks_NotAllowedForCDT。够短了。

Use acronyms? Define in comments that CDT is "Current Document Type", and you'll get DeleteBookmarks_NotAllowedForCDT. Short enough.

等待圉鍢 2024-08-16 07:35:11

DelBookmarksStartingWith 怎么样?说得很清楚,也表达了意图。

How about DelBookmarksStartingWith? It's pretty clear and expresses intent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文