Which abbreviations should we use for python variable names?

后端 未结 5 1143
说谎
说谎 2021-02-08 19:27

In generally I\'m using the standard naming stated in PEP-8 for variables. Like:

delete_projects
connect_server

However sometimes I can\'t find

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-08 19:47

    pr_nm_del? You might as well let a cat name it. I believe abbreviations should be avoided at all cost, except well-known/obvious ones (like del, as mentioned in the comments - that one's even a language keyword!) that save a whole lot of typing.

    But that doesn't mean overly verbose identifiers. Just as context is important to understand statements in natural languages, identifiers can often be kept much shorter (and just as understandable) by referring to context. In your example, project_name is perfectly fine - the procedure is already called delete_project, so project_name obviously refers to the name of the project to be deleted. Even name alone might be fine. No need to state that again by appending _to_be_deleted.

提交回复
热议问题