过去时、现在时和将来时的命名函数?

发布于 2024-07-26 03:33:12 字数 327 浏览 6 评论 0原文

我试图为 Permission 类提供一些清晰简洁的名称,让您检查权限是否被允许、曾经或将被允许/拒绝。 我不知道什么叫未来时态。

class Permission:
  def can_read()
  def could_read()
  def will_read()?
  def will_be_readable()?

我最偏爱 will_read(),但这听起来很有趣。 will_be_read() 很清楚,但有点长,而且 will_be_read() 听起来很误导。

I'm trying to come up with some clear and concise names for a Permission class that lets you check if a permission is, was, or will be, allowed/denied. I'm at a loss for what to call the future tense.

class Permission:
  def can_read()
  def could_read()
  def will_read()?
  def will_be_readable()?

I'm most partial to will_read(), but it sounds funny. will_be_readable() is clear, but its kinda long, and will_be_read() sounds misleading.

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

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

发布评论

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

评论(4

长安忆 2024-08-02 03:33:19

是啊,英语这里确实有问题,没有“can”的将来时! 切换到(例如)read_nowread_pastread_future 怎么样? 如果过去和未来在您的情况下有特定的含义,我确信可以在这里找到更好的命名。

Yeah, English really has a problem here, with no future tense of "can"! What about switching to (say) readable_now, readable_past, readable_future? If past and future have specific meanings in your case better naming could be worked out here, I'm sure.

蝶…霜飞 2024-08-02 03:33:19

由于它与是否允许/拒绝权限有关,因此也许有一个比 read 更具描述性的词?

可以_授权

授权

预定授权

Since it is related to if a permission is allowed/denied, maybe there is a more descriptive word than read?

can_authorize

authorized

scheduled_to_authorize

眼泪淡了忧伤 2024-08-02 03:33:18

过去、现在和将来对我来说是最清楚的..
或者可能是可读的之前、可读的现在、可读的以后

was, is, and will_be is clearest to me..
or maybe readable_before, readable_now, readable_later

A君 2024-08-02 03:33:17

由于您正在寻找权限类,因此代码将被表述为一个问题:

if (the_user.can_read()) ...
if (the_user.can_read_past()) ...
if (the_user.can_read_future()) ...

除此之外,我将尝试为语义上相等的函数维护相等的前缀,并且我将省略默认/最可能情况的后缀。 尽管我喜欢将代码转向自然语言,但我对于牺牲逻辑命名结构的语法正确性没有任何真正的问题。 所以类似的事情就是我想要的。

will_read() 听起来更像是在操作之前触发的事件。

编辑:我知道“can_read_past”可能被视为“可以读取旧的东西”。 也许斯科特·埃文登的建议更好?

Since you are looking for a permission class, the code will be formulated as a question:

if (the_user.can_read()) ...
if (the_user.can_read_past()) ...
if (the_user.can_read_future()) ...

Apart from that I would try to maintain equal prefixes for the semantically equal function, and I would leave off the suffix for the default/most likely case. I have no real problem sacrificing grammatical correctness for a logical naming structure, even though I like to gear code towards natural language. So something like that is what I would be going for.

The will_read() sounds more like an event that is triggered before the action.

EDIT: I am aware that "can_read_past" may be percieved as "can read old stuff". Maybe Scott Evernden's suggestion is better?

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