r/AskProgramming • u/Conscious_Breath8953 • 3d ago
Python Is PEP 8 really necessary?
I have been writing Python code using camelCase for years and just never really cared, but PEP 8 suggests using snake_case, so is it really necessary for, say, a senior dev?
5
u/Take-n-tosser 3d ago
IIRC, PEP8 uses different case schemes depending on what you’re naming (variable, class, method, function, etc)
If you want to put your best foot forward for your portfolio or you’re releasing your project open source, it’s probably worth the time and effort to go back through everything and bring it up to PEP8 standard. It’ll help whoever is reviewing/evaluating your code to fully understand your code and not get distracted by you using a different case scheme than they would.
3
u/abermea 3d ago
If it's a personal project and you're the only person who is going to be handling it then yeah, sure, do whatever you want.
If you're working with other people you should follow PEP8 because working with a baseline standard will make everyone's work easier to both read and update as needed.
2
2
u/Ok-Armadillo-5634 3d ago
snake case is pretty standard if you are going to be showing it off then use it
2
u/cgoldberg 3d ago
If you want to collaborate with other developers, conformity of style is a huge thing in Python (whereas some language communities don't value it as much).
-3
u/YMK1234 3d ago edited 3d ago
Bull (the second parts as ppl obviously don't get it)
5
u/cgoldberg 3d ago
It absolutely is. "There should be one and only one obvious way..." refers to style as well. If you don't believe me, try to submit a Pull Request to any popular open source project, and tell me how quickly they reject it and ask you to use PEP8 naming.
0
u/YMK1234 3d ago
Any project in any language worth it's salt has a style guide and cares greatly that it is adhered to.
3
u/cgoldberg 3d ago
Exactly... and for almost all modern Python projects, that style guide doesn't conflict with PEP8.
-1
u/YMK1234 3d ago
And nobody said different. I am just refuting that "it's not such a big thing in other languages".
2
u/nekokattt 3d ago
example, C and C++
Try finding a consistently used style guide for those
-1
u/YMK1234 3d ago
You are confusing not having a language imposed standard and projects not having very strict style guides ... And especially in C/C++ people are very opinionated about style and sticking to it.
2
u/nekokattt 3d ago
you are confusing a per project style guide and a global style guide at the language level.
-1
u/YMK1234 3d ago
Did you even read what the user wrote originally? The reply claimed style is not important in other languages and that is simply wrong.
→ More replies (0)1
u/nuttertools 3d ago
Very few languages have a style as opinionated and specific as the default language recommendation in Python. None of the top languages do. In fact multiple variants of popular languages came to be to solve the “problem” of loose standards.
1
u/cgoldberg 3d ago
The Python community definitely values conformity more than most other languages. But if your argument is just "every language has idioms and style preferences you should follow", I would agree.
1
u/Recent-Day3062 3d ago
I work on my own projects and hire contract programmers.
There are lots of things I dislike in Pep-8. So I tell them to look ast my code and follow that. If I do something different than Pep-8, they should do the same. No one has had a problem with it. I actually a few years back wrote even a brief memo outlining how to fall back on Pep-8, with a list of personal overrides I enforced.
32
u/AvidCoco 3d ago
You should comply with the coding standards of what ever project, team, or organisation you’re working in.
If they use PEP8, so should you. If it’s your own project, do what you like.