我经常看到开源或“专业”python代码中的注释——比如webapp2或webob,看起来很分散。注释的数量似乎超过了代码。我注意到个别开发者也在自己的应用程序中这样做。大间距,大量注释,然后每隔几行代码。在
我想我喜欢这种风格,它确实感觉更有条理。现在我已经是python中更大的项目了,我想我是否应该像我看到的其他人那样,用代码和注释来组织一个大型项目。我认为它可能会使它更具可读性和可维护性,也可能使我成为一个更好的程序员——因为事情会变得更清楚。在
只是想:这个问题在代码审查上更好吗?倾听就是服从
目前我只是这样评论,例如:#U - Idempotent. b-atching requests
# which can be PUT, DELETE or GET.
#@control.access.collector_or_owner
def patch(s,*a,**k):
s.resolve(*a,**k)
for mod in s.requested_modifications:
method = mod.get('method') or 'PUT'
point = s.current_point+mod.get('point') or ''
body = mod.get('body') or ''
s.say('Will execute %s on %s for %s\n' % (method,point,body))
# create the in-app request
mod_request = webapp2.Request.blank(point)
mod_request.body = str(body)
mod_request.method = method
mod_request.app = s.app
# then find the handler and report
execute_tuple = s.app.router.match(mod_request)
mod_request.route,mod_request.route_args,mod_request.route_kwargs = execute_tuple
handler = mod_request.route.handler
if handler not in s.app.router.handlers:
s.app.router.handlers[handler] = handler = webapp2.import_string(handler)
else:
handler = s.app.router.handlers[handler]
s.say('Will execute %s on %s for %s via %s\n' % (method,point,body,execute_tuple))
# then execute
in_app_response = webapp2.Response()
handler = handler(mod_request,in_app_response)
handler.dispatch()
s.say('Response is %s\n' % (in_app_response))
它只关注“该做什么”,但没有解释其他任何事情。我相信有更好的方法,但我不想自己想出更好的办法,我要的是圣贤的智慧。在
我读过Style Guide PEP——这很有帮助,但是对于大型复杂的python项目,需要一些能提炼出评论智慧的东西,而不是“编写英语时,Strunk和White apply”这样的细节。在