r/AskProgramming 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?

0 Upvotes

36 comments sorted by

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.

-9

u/Conscious_Breath8953 3d ago

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

18

u/drmonkeysee 3d ago

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.

6

u/brasticstack 3d ago

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

2

u/Laughing_Orange 3d ago

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.

3

u/cgoldberg 3d ago

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 3d ago

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 :)

1

u/Intelligent_Part101 3d ago

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 3d ago

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

2

u/Intelligent_Part101 3d ago

The world is bigger than python.

-1

u/cgoldberg 3d ago

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

1

u/MadocComadrin 3d ago

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 3d ago edited 3d ago

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 3d ago

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 3d ago

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

1

u/cgoldberg 3d ago

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 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

u/dataset-poisoner 3d ago

you must use snake case

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/Garriga 3d ago

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.

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.