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 any good name and the name just extend to a long one:
project_name_to_be_deleted
I could use pr_nm_del , but this makes the code unreadable. I’m really suffering finding good variable names for functions. Whenever I begin to write a new function I just spent time to find a good variable name.
Is there any standard for choosing certain abbreviations for well known variable names like, delete,project,configuration, etc. ? How do you choose short but good and readable variable names ?
This question might be not depend directly to Python, but as different programming languages uses different variable names formatting I thought I limit this question to Python only.
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 (likedel, 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_nameis perfectly fine – the procedure is already calleddelete_project, soproject_nameobviously refers to the name of the project to be deleted. Evennamealone might be fine. No need to state that again by appending_to_be_deleted.