Python 长类名的最佳命名约定是什么?

Python 长类名的最佳命名约定是什么?,python,model-view-controller,flask,conventions,pep8,Python,Model View Controller,Flask,Conventions,Pep8,现在,我正在为MVC模式编写Python flask代码。 但是,我认为我自己,我认为控制器类的声明器太长了 例如,我有 class GoogleQuestionController: def __init__(self): (.....) 及 两个类的名称非常相似,所以我不能像 question_controller = GoogleQuestionController() 上面 定义类声明器的最佳建议是什么 google_question_controller

现在,我正在为MVC模式编写Python flask代码。 但是,我认为我自己,我认为控制器类的声明器太长了

例如,我有

class GoogleQuestionController:
    def __init__(self):

        (.....)

两个类的名称非常相似,所以我不能像

question_controller = GoogleQuestionController()
上面

定义类声明器的最佳建议是什么

google_question_controller = GoogleQuestionController()
yahoo_question_controller = YahooQuestionController()
这个代码太长了

所以,我现在就这样使用

yq_con = YahooQuestionController()
gq_con = GoogleQuestionController()


也许这不是你想要的答案,但我强烈建议你选择:

google_question_controller = GoogleQuestionController()
yahoo_question_controller = YahooQuestionController()
我不认为这太长,它实际上是可读的和整洁的。

现在,意见补充说,请记住,对长度没有限制,但变量的可读性非常高:

使用函数命名规则:小写,单词之间用 必要时加下划线以提高可读性


也许这不是你想要的答案,但我强烈建议你选择:

google_question_controller = GoogleQuestionController()
yahoo_question_controller = YahooQuestionController()
我不认为这太长,它实际上是可读的和整洁的。

现在,意见补充说,请记住,对长度没有限制,但变量的可读性非常高:

使用函数命名规则:小写,单词之间用 必要时加下划线以提高可读性


上下文在这里很重要:

google_question_controller = GoogleQuestionController()
yahoo_question_controller = YahooQuestionController()
也许可以,但如果我们能够重构,使名词不模棱两可,即如果只有一个google对象,我可能会使用:

google = GoogleQuestionController()
yahoo = YahooQuestionController()
类似地,如果动词没有歧义,例如,如果我在Google对象/模块中,我会使用
question
(或者
controller
):

通过这种方式,您可以重写代码以提高可读性


通常,在这种情况下,将相似的行为组合在一起可以产生更好的抽象,例如,我们可以定义一个mixin/基类,它使用
GoogleQuestionController
YahooQuestionController
等之间的共享API来使用
self.controller

上下文在这里很重要:

google_question_controller = GoogleQuestionController()
yahoo_question_controller = YahooQuestionController()
也许可以,但如果我们能够重构,使名词不模棱两可,即如果只有一个google对象,我可能会使用:

google = GoogleQuestionController()
yahoo = YahooQuestionController()
类似地,如果动词没有歧义,例如,如果我在Google对象/模块中,我会使用
question
(或者
controller
):

通过这种方式,您可以重写代码以提高可读性

通常,在这样的情况下,将相似的行为组合在一起可以产生更好的抽象,例如,我们可以定义一个mixin/基类,它使用
self.controller
,使用
GoogleQuestionController
YahooQuestionController
之间的共享API。请记住,始终将代码长度置于可读性之上。始终。
x,y=GQC(),YQC()
。请记住,始终将代码长度置于可读性之上。总是