python中命名不唯一结果错误?
也许这是一个有点非常规的问题,但我想听到一个答案。由于英语不是我的母语,我想我应该征求第二意见。
我想在 python 中提出一个错误,并且想知道如何命名它。
class AmbiguousResultError(Exception): pass
class NoResultFoundError(Exception): pass
def getUrlFor(mystring):
list_of_urls = []
# parse url object for all matching urls for the given string
# and add them to list_of_urls
if len(url) > 1:
raise AmbiguousResultError("More then one url matches for {0}".format(mystring))
elif not url:
raise NoResultFoundError("There was no matching url for {0}".format(mystring))
else:
return list_of_urls[0]
第一个 raise
是我想知道的,如何命名它才能准确。我想到了
NoUniqueResultFoundError
AmbigouslyResultError
UncertainResultError
但它们都不能让我满意,我也不知道这个命名是否切中要害。对于其他人来说也应该是显而易见的。必须有一个具体的表达方式。是哪一个呢。我想在 english.stackexchange.com 上提问,但我认为程序员的思维方式与语言学家不同。
Maybe this is a little unconventional question but I'd like to hear an answer to it. Since english is not my native language I thought I'd ask for a second opinion.
I want to raise an Error in python and was wondering how to name it.
class AmbiguousResultError(Exception): pass
class NoResultFoundError(Exception): pass
def getUrlFor(mystring):
list_of_urls = []
# parse url object for all matching urls for the given string
# and add them to list_of_urls
if len(url) > 1:
raise AmbiguousResultError("More then one url matches for {0}".format(mystring))
elif not url:
raise NoResultFoundError("There was no matching url for {0}".format(mystring))
else:
return list_of_urls[0]
The first raise
is the one which I was wondering, how to name it such that it is precise. I thought of
NoUniqueResultFoundError
AmbiguousResultError
UncertainResultError
But they all don't satisfy me, and I don't know if I hit the nail with this nameing. It should be obvious to others, too. There has to be a specific expression for that. Which one is it. I thought of asking it on english.stackexchange.com, but I think a programmer has another sort of thinking then a philologist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我更喜欢
AmbigouslyStringError
而不是AmbigouslyResultError
。毕竟,具有多重含义的不是结果,而是用户提供的字符串。或者可能是
MultipleResultsFoundError
。我认为你的NoUniqueResultFoundError
建议是一样好的。如果您像对待此代码一样对其余代码进行彻底和深思熟虑,那么其他开发人员在调试它时就不会有问题。I'd prefer
AmbiguousStringError
toAmbiguousResultError
. After all, it's not the result that has multiple meanings, it's the string the user provided.Or possibly
MultipleResultsFoundError
. I think your suggestion ofNoUniqueResultFoundError
is as good as anything though. If you're as thorough and thoughtful with the rest of your code as you are with this, other developers won't have a problem debugging it.