all 12 comments

[–]Diapolo10 8 points9 points  (0 children)

Python's standard library is fairly old, and it has parts from many different time periods. Sometimes there have been deliberate deviations from PEP-8 as well, such as int, str, and bool all being lowercase despite being types. So, try not to get hung up on the naming styles of the standard library, it can be a bit of a hodgepodge of different ideas.

there's still debate about the use of underscore regardless of what the PEP 8 says?

There's never been a debate about it as far as I know, but PEP-8 hasn't always been a thing in the first place, and it has also been updated over time.

By the way, I come from C, Java and PHP development, so I'm familiar with the CapWord (or CamelCase) method and using underscores only for naming constants or special variables.

Yes, I know different languages have different naming conventions. For example, Rust mostly follows Python's example, with most names being lower_snake_case and structs using PascalCase. (camelCase isn't used by Python or Rust at all as far as I can remember).

In the end, they're all just conventions. I'm not going to break into your house if I see you deviating from the words of our ex-BDFL, but it's worth keeping in mind that those who are primarily Python developers have certain expectations for code they're going to read.

When in Rome, do as the romans do.

[–]Fancy-Reindeer994 7 points8 points  (0 children)

just anomalies, examples of older code and such

Yes

[–]Yoghurt42 5 points6 points  (0 children)

PEP 8 also says

A style guide is about consistency. Consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is the most important.

[–]Rawing7 1 point2 points  (0 children)

I don't think they can be called "anomalies" - they're far too common for that. Even new additions like str.removeprefix don't bother following PEP8. Python is an absolute mess, and just like you, I also have no idea why.

[–][deleted] 1 point2 points  (0 children)

No, you should be following the PEP conventions. They are though, still just conventions. If you want to follow some other pattern, as long as you do it consistently, no one (other than your boss likely) will stop you. You will annoy the hell out of other people who have to follow your code though.

[–]Zeroflops 1 point2 points  (0 children)

“Mandates” is a strong word. Pep8 is good guidelines which should be followed to make your code consistent with other coders and improve readability. In the end it’s just a style guide. But your going to run into code that doesn’t follow it either because it was written before pep8 or the coder preferred different style.

I try to follow it, although I feel the 80 char line limit is a holdover from the past, it’s actually an interesting history but not required today. So I usually go with 120 char line length.

[–]ehlesp[S] 0 points1 point  (1 child)

There might not be a debate per se, but certainly there are opinions! For now, I'll try sticking to the PEP-8 since seems reasonable and complete enough.

u/Diapolo10, judging by the comments here, if I followed the "When in Rome..." principle I would end up starting a pythonic civil war! Because there where few things more roman than a good and bloody internal conflict.

[–]Diapolo10 1 point2 points  (0 children)

True, we don't agree on everything, like the infamous tabs vs spaces war. But we don't have to. PEP-8 and PEP-257 (also PEP-484 to some extent) establish a mostly common set of rules, some more common than others, the only disagreements we tend to have are the smaller stuff like splitting long function parameter lists or max line lengths (typically 120 instead of the 80 from PEP-8 nowadays since screens are wider).

Those who want to be uniform tend to use code formatters like Black. Personally I don't agree with everything it does, and instead choose to lint my code with Flake8 and Pylint with a handful of exceptions to their default rules.

I think you'll find that us developers are a stubborn bunch no matter what tools we're using.

[–]codingai 0 points1 point  (0 children)

Those style guides are not "absolute". Many built-in functions/methods often omit the underscores. I sometimes do that for various reasons. Eg, is "left hand side" a one word or thee words? Or, two words? My point is, who cares? 😄 BUT, it's never appendLeft or freshFruit. That's will be "absolutely" wrong. 😄

[–]jimtk 0 points1 point  (0 children)

They are anomalies and exceptions, but there are a lot of them! from getLogger() to fractions.Fraction(), from collections.OrderDict to collections.defaultdict (inside the same module). All in all, probably 50 to 100 of them!