If you have enough of these functions, it might make sense to make a SomeTypes class so the method names could be shortened to reduce, map, and filter.
If the functions can be generalized to accept or return types other than sometype, then of course it would make sense to remove sometype from the function name, and instead choose a name that emphasizes what it does rather than the types.
发布评论
评论(1)
Python
dicts
有iter*
方法。 lxml 树也有一个 iter 方法。读起来
似乎很熟悉,所以
按照这种模式,我会考虑命名 sometypes 的生成器
sometypes_iter
为了让我可以类似地编写,
Python 提供了一个
sorted
函数。按照这种模式,我可能会将动词函数设置为过去时:
如果您有足够的这些函数,那么创建一个
SomeTypes
类可能是有意义的,这样方法名称就可以缩短为reduce
、地图
和过滤器
。如果函数可以泛化为接受或返回
sometype
以外的类型,那么当然从函数名称中删除sometype
是有意义的,而是选择一个名称强调它的作用而不是类型。Python
dicts
haveiter*
methods. And lxml trees also have aniter
method.Reading
seems familiar, so
following that pattern, I'd consider naming the a generator of sometypes
sometypes_iter
so that I could write analgously,
Python provides a
sorted
function.Following that pattern, I might make the verb-functions past tense:
If you have enough of these functions, it might make sense to make a
SomeTypes
class so the method names could be shortened toreduce
,map
, andfilter
.If the functions can be generalized to accept or return types other than
sometype
, then of course it would make sense to removesometype
from the function name, and instead choose a name that emphasizes what it does rather than the types.