我正在构建一个网站(使用Django),但对于函数的命名规范感到困惑。举个简单的例子:假设我有一个页面,让用户决定他们想看图像A还是图像B。一旦用户提交了决定,网站就会显示用户请求的图像。
这是我在视图模块中将拥有的两个函数:
def function1(request):
"""Returns the page that presents the user with the choice between A and B"""
def function2(request):
"""Takes in the submitted form and returns a page with the image the user requested."""
这种情况下,如何命名相应函数的约定是什么?我至少看到两种可行的方式:
选项1:
function1: "decide", function2: "view_image"
选项2: function1: "view_choices", function2: "decide"
核心问题在于,这些函数中的每一个都会有两个任务:(1)处理并存储用户提交的数据,以及(2)返回下一页,该页可能与用户的输入相关或无关。因此,我应该根据(1)还是(2)来为我的函数命名呢?