Python Functions, naming conventions in Python

  • Thread starter Thread starter Arman777
  • Start date Start date
  • Tags Tags
    Functions Python
Click For Summary
Using the same name for local and global variables in Python can lead to confusion, and it's recommended to adopt clear naming conventions to avoid this issue. The PEP 8 style guide suggests using prefixes like an underscore for local variables, but opinions vary on its effectiveness. Clearer naming, such as using descriptive terms instead of generic ones, is emphasized to improve code readability and maintainability. Some participants argue against using global variables altogether, suggesting that encapsulating functionality within classes can provide better structure. Ultimately, the discussion highlights the importance of thoughtful naming to enhance code clarity and reduce the need for comments.
  • #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 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 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 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
1K
  • · 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
5K
  • · Replies 15 ·
Replies
15
Views
2K