Functions, naming conventions in Python

  • Context: Python 
  • Thread starter Thread starter Arman777
  • Start date Start date
  • Tags Tags
    Functions Python
Click For Summary
SUMMARY

The discussion centers on naming conventions for local and global variables in Python, particularly when they share the same name. Participants emphasize the importance of clarity in naming, suggesting alternatives like prefixing local variables with an underscore (e.g., _my_var) to distinguish them from global variables. They reference the PEP 8 style guide for guidance but note its limitations in addressing this specific issue. Ultimately, the consensus is that meaningful names should be prioritized over similar naming, with suggestions to use descriptive names that reflect the variable's purpose.

PREREQUISITES
  • Understanding of Python variable scope (local vs. global)
  • Familiarity with PEP 8 style guide for Python coding standards
  • Basic knowledge of function definitions and naming conventions in Python
  • Experience with debugging and code readability practices
NEXT STEPS
  • Research best practices for naming conventions in Python, focusing on clarity and context.
  • Explore the PEP 8 style guide in detail, particularly sections on variable naming.
  • Learn about Python's variable scope and how it affects function design and debugging.
  • Investigate object-oriented programming in Python to understand class and method naming conventions.
USEFUL FOR

Python developers, software engineers, and anyone involved in code maintenance and readability improvement will benefit from this discussion.

  • #31
I'm a minimal commenter as well, but agree with Ibix. You should write comments when you expect other people who will read the code won't understand something.

The problem with comments is that you can write anything in a comment and the code will compile. Each comment introduces a long term vulnerability since it will need to be updated and synchronized with the code as it changes. The more comments you have, the more work that becomes, and the less likely a person is to be diligent in updating them. In general, you cannot rely on them to be accurate. And, if there are too many mundane comments, the reader may just stop reading them and then miss the important ones (like the boy who cried wolf).
 
  • Like
  • Skeptical
Likes   Reactions: PeroK, PeterDonis and jack action
Technology news on Phys.org
  • #32
FactChecker said:
Programming can be a messy struggle, especially if you are working in other people's code. Comments can help a lot.
The bulk of time in the software development life cycle (SDLC) is spent on maintenance, usually done by someone other than the original developer, who is likely off in another job, perhaps in a different company. Code steps that seemed trivial to the original developer might not be so to someone else who is tasked with fixing bugs that the code generated. Comments can help this person, especially if they have been kept up to date and are correct explanations of what the code is doing.
 
  • Like
Likes   Reactions: FactChecker
  • #33
I don't know what other people have experienced, but my experience is that there are far more cases of too little commenting than too much, especially from beginning programmers.
 
  • #34
Jarvis323 said:
You should write comments when you expect other people who will read the code won't understand something.
Including Future You.
 
  • Like
Likes   Reactions: hmmm27, PeroK and FactChecker

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 18 ·
Replies
18
Views
2K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
3
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K