As I mentioned in my Automate the Boring Stuff review, I was led astray with regards to naming my functions and variables. That is, the book was telling me to use camelCase rather than the approved underscore method.
After writing that article I decided to do some digging and I totally feel this needs a dedicated post!
A lot of people are divided on this topic! Doing a quick Google search found people who believe it doesn't matter what you use and those that would fight for their chosen method.
The one thing everyone agrees on however is that you need to remain consistent. If you decide to use camelCase in your code, then do so for the entirety of your project, don't mix.
After Bob informed me that camelCase wasn't the way to go, I went through and renamed all of my functions and variables using the underscore method. Here's a quick snippet in case you don't know what this all looks like:
I did wonder where this guidance was coming from though. How did Bob know this was exactly how it should be?
That was when I discovered the PEP8 Style Guide on python.org. If you have any doubts as to how your code should be laid out, reference this baby and you'll be on your way.
What does it say about naming conventions? Quite a bit actually! For the pupose of this post there, here's what it says about Function names (also applicable to Methods and Instance Variables):
Function names should be lowercase, with words separated by underscores as necessary to improve readability.
If you check out the page for yourself you'll see further explanations on other naming convention options within Py.
Given the existence of the PEP8 standards, I don't think we really have a choice nor do I think there's any debate about how we should be naming variables and the like.
Going forward I'll definitely be using these rules when working on my code. If I don't, feel free to correct me!
Imagine a world where we all code to the same rules. Mmmm.
Keep Calm and Code in Python!
Do you want to get 250+ concise and applicable Python tips in an ebook that will cost you less than 10 bucks (future updates included), check it out here.
"The discussions are succinct yet thorough enough to give you a solid grasp of the particular problem. I just wish I would have had this book when I started learning Python." - Daniel H
"Bob and Julian are the masters at aggregating these small snippets of code that can really make certain aspects of coding easier." - Jesse B
"This is now my favourite first Python go-to reference." - Anthony L
"Do you ever go on one of those cooking websites for a recipe and have to scroll for what feels like an eternity to get to the ingredients and the 4 steps the recipe actually takes? This is the opposite of that." - Sergio S