我經常在開源或「專業」python代碼中看到註釋 - 比如webapp2或webob,看起來非常分散。評論似乎超過了代碼。我注意到個別開發人員也在自己的應用程序中執行此操作。大的間距,大量的評論,然後每隔幾行代碼幾行代碼。我應該如何評論python代碼?
我想我喜歡這種風格,它感覺更有組織。現在,我是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的讀 - 這是有幫助的,但一些評論提煉的智慧auteurs與不是「寫英語時,斯特倫克和白色的更詳細一點的大複雜的Python項目申請「是必需的。
是的,我認爲這就像我的目標,作爲我的戰略之一,以解決更大的項目。謝謝! – 2013-04-21 08:18:02