Tetsudou
Tetsudou

Reputation: 224

Naming Variables and Functions

I'm using Python, but I think it's same for pretty much every programming languages. It has nothing to do with the functionalities, but I came to notice that when I see other people's codes, variable names with multiple words are connected, and the first letters of each words (except for the first one) are capitalized.

thisIsATypicalVariableNameWithMultipleWords = 0

But when using functions, usually nothing is capitalized and the words are connected by _.

this_is_a_typical_function_name_with_multiple_words()

Is this how the variables and functions are typically named? Thanks in advance.

Upvotes: 0

Views: 79

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121366

You are looking at a naming convention, and such conventions are rather arbitrary but usually agreed upon in a style guide.

The Python developers have published such a style guide for Python: PEP 8 -- Style Guide for Python Code. It includes a section on naming conventions for Python code. You don't have to adhere to these, but it is a good idea to do so if you want to work with other Python developers where most do adhere to these conventions.

The style guide also provides you with names for the styles; your two specific styles (which are not the only two styles), are called mixedCase and lower_case_with_underscores.

mixedCase is no longer used in Python code; the style guide only mentions it as a legacy case for function names used by certain older standard library modules.

lower_case_with_underscores is the current recommended convention for function, method and attribute names.

Upvotes: 2

Related Questions