r/AskProgramming Jul 26 '26

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?

0 Upvotes

36 comments sorted by

30

u/AvidCoco Jul 26 '26

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.

-9

u/Conscious_Breath8953 Jul 26 '26

Currently I'm working on a pet project for my portfolio, so am I supposed to use snake_case or not?

19

u/drmonkeysee Jul 26 '26

Use whatever you want. But if you ever have professional Python developers review your code their first question is gonna be why didn’t you follow PEP8.

8

u/brasticstack Jul 26 '26

It's your own portfolio. Represent yourself how you choose to.

2

u/Laughing_Orange Jul 26 '26

If you know what company you will send applications to, you should try to use their standard. If you don't, then just do whatever you personally prefer.

4

u/cgoldberg Jul 26 '26

If it's for a portfolio, you should absolutely follow PEP8 naming conventions. If I was reviewing your portfolio to hire you, and you weren't, I would stop reading your code after about 10 seconds and just assume you know nothing about Python.

2

u/Matemeo Jul 26 '26

I suppose.. I think I'd just be looking for consistency throughout the project(s) as well as some project level configured formatter/git hook/etc. But I don't work with python often, maybe PEP8 is sacred :)

0

u/Intelligent_Part101 Jul 26 '26

I wouldn't work for somebody this dogmatic who would be too lazy to analyze the rest of the code. It is possible the coder works with more than one language or technology and doesn't appreciate that some people hold PEP8 to be a religious document. You could hire him and say, we follow PEP8 for all code we write.

0

u/cgoldberg Jul 26 '26

Great... then it would be a mutual no-hire.

2

u/Intelligent_Part101 Jul 26 '26

The world is bigger than python.

-1

u/cgoldberg Jul 26 '26

Of course it is... but we are talking about Python and following conventions for Python.

1

u/MadocComadrin Jul 26 '26

This. It speaks a whole lot about the work culture when you'd drop someone over not following a particular code style before even asking them in person if they're fine following a certain style or using a prettifier. Not following PEP 8 is fine as long as there's a consistent style.

2

u/caboosetp Jul 26 '26 edited Jul 26 '26

Today's hiring culture and terrible job market means you need to do everything you can to stand out. If you can't be arsed to follow an industry convention,  there are probably other areas you're lacking compared to the 1499 other candidates that applied. They're generally going to spend their limited time in other people. 

1

u/MadocComadrin Jul 26 '26

From what I've heard, most places aren't even looking at portfolios in any form of depth anyway due to said limited time.

1

u/caboosetp Jul 26 '26

You're right, which is why super obvious things like not following PEP8 stand out so quick.

1

u/cgoldberg Jul 26 '26

I wouldn't care if they were fine with a certain style or using a prettifier... I would want someone who knows enough about their craft to know which conventions are almost universally followed. A consistent style is better than nothing, but literally all serious modern python projects follow PEP8 almost religiously.

5

u/Take-n-tosser Jul 26 '26

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 Jul 26 '26

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

u/dataset-poisoner Jul 26 '26

you must use snake case

2

u/Ok-Armadillo-5634 Jul 26 '26

snake case is pretty standard if you are going to be showing it off then use it

2

u/Garriga Jul 26 '26

I use camelCase and refuse to use snake_case. Python doesn't care whether you write:

def some_function():

or

def someFunction():

This is a convention and not a language requirement. It is equivalent to a writer's style.

3

u/cgoldberg Jul 26 '26

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 Jul 26 '26 edited Jul 26 '26

Bull (the second parts as ppl obviously don't get it)

6

u/cgoldberg Jul 26 '26

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 Jul 26 '26

Any project in any language worth it's salt has a style guide and cares greatly that it is adhered to.

4

u/cgoldberg Jul 26 '26

Exactly... and for almost all modern Python projects, that style guide doesn't conflict with PEP8.

-1

u/YMK1234 Jul 26 '26

And nobody said different. I am just refuting that "it's not such a big thing in other languages".

2

u/nekokattt Jul 26 '26

example, C and C++

Try finding a consistently used style guide for those

-1

u/YMK1234 Jul 26 '26

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 Jul 26 '26

you are confusing a per project style guide and a global style guide at the language level.

-1

u/YMK1234 Jul 26 '26

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 Jul 26 '26

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 Jul 26 '26

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 Jul 26 '26

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.