Chapter 1: Python code, convention on variables names
giaruffo opened this issue · 1 comments
Not an error, but just notice that reported Python code does not always follow common naming conventions on variables: Python's variable are expected to start with small case characters, and names are exptected to be not too general.
Using one capital letter to name a variable is generally considered too naive, as reported in many tutorials, such as: https://medium.com/@dasagrivamanu/python-naming-conventions-the-10-points-you-should-know-149a9aa9f8c7
There is a reason behind such a convention: expert programmers want to avoid ambiguity with classes; in fact, capitalized names are usually given to classes.
For example,
G = nx.Graph()
could be changed to something like:
graph1 = nx.Graph()
(also note that the name of the class 'Graph' is capitalized).
I am aware that such ambiguity has been introduced in the networkx official tutorial in the first place, but students with some knownledge on Python may find reported examples odd-looking.
Yes, good point. We discussed this and decided to follow the NetworkX convention in NetworkX code. In fact there is a note explaining this convention in the Chapter 1 Tutorial, that reads:
A note on naming conventions
Usually in Python, variables are named in snake_case, i.e. lowercase with underscores separating words. Classes are conventionally named in CamelCase, i.e. with the first letter of each word capitalized.
Obviously NetworkX doesn't use this convention, often using single capital letters for the names of graphs. This is an example of convention leaking from the world of discrete mathematics. Since most of the documentation you will find online uses this convention, we will follow it as well.