过去时、现在时和将来时的命名函数?
我试图为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是啊,英语这里确实有问题,没有“can”的将来时! 切换到(例如)
read_now
、read_past
、read_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.由于它与是否允许/拒绝权限有关,因此也许有一个比 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
过去、现在和将来对我来说是最清楚的..
或者可能是可读的之前、可读的现在、可读的以后
was, is, and will_be is clearest to me..
or maybe readable_before, readable_now, readable_later
由于您正在寻找权限类,因此代码将被表述为一个问题:
除此之外,我将尝试为语义上相等的函数维护相等的前缀,并且我将省略默认/最可能情况的后缀。 尽管我喜欢将代码转向自然语言,但我对于牺牲逻辑命名结构的语法正确性没有任何真正的问题。 所以类似的事情就是我想要的。
will_read()
听起来更像是在操作之前触发的事件。编辑:我知道“
can_read_past
”可能被视为“可以读取旧的东西”。 也许斯科特·埃文登的建议更好?Since you are looking for a permission class, the code will be formulated as a question:
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?