Code Conventions - IncrediCoders/Python1 GitHub Wiki
What are code conventions? We're glad you asked!
Code conventions are the code styling decisions we made in the book. Each convention and decision was made for various reasons, so let's get into it!
Case Styles
Typically, there are a few core casing styles (also called casing conventions or simply casing) that developers use: Snake Case VS Camel Case VS Pascal Case VS Kebab Case – What's the Difference Between Casings?
Dionysia Lemonaki did an amazing job writing that article that explains the different casing styles.
You name a lot of variables and functions when you code, so you want to be consistent with your naming conventions.
One thing to keep in mind is that the names of your variables and functions can't have spaces in them. So, these casing conventions don't include spaces, and they exist to make sure that the names you choose are consistent in how they appear.
Here is a very brief summary of the different casing styles:
camelCasing
: Although the first word starts with a lowercase letter, each new word starts with a capital letter. It uses no spacing or dashes in between the words. This is also called medial casing (since you use uppercase in the middle), and it was started for the chemistry industry in 1813.PascalCasing
: A form of camel casing, this is also referred to as CamelCasing, where the first word has a capital "C." It was named after the Pascal programming language, which uses Pascal casing.snake_casing
: It uses an underscore between each word. It's also called underscore casing.kebab-casing
: It uses a dash between each word.ALLCAPSCASING
: Also known as the screaming case, it's all caps.SCREAMING_SNAKE
: All caps with snake casing, where you have an underscore between each word.
We landed on using three of these casings for the book:
- Snake Casing: We use snake (or underscore) casing for functions, such as
this_is_a_function()
. A function is basically where you call a bunch of code to do a thing. More on that later. - Pascal/Camel Casing: We use the Pascal style of camel casing (with the first letter capped) for variables and lists.
- All-Caps Casing: We use all-caps casing (also called scream casing) for environment variables, global variables, and ENUMS which are basically just variables that don't change (we want to keep the value throughout the program) or that are used across multiple functions, modules, and even files. For example, the variable
SCREEN
is in all caps, because it is an environment variable, which means that it sets up the environment. The environment includes things like the background, window, or screen.