Class member
records
has same name as its encolising class Records
208 def __init__(self, scm):
209 """Initialise."""
210 self.scm = scm
211 self.records = None 212 self.relay = None
213
214 try:
Class member
facebook
has same name as its encolising class Facebook
27 def __init__(self):
28 """Initialise."""
29 self.scm = None
30 self.facebook = [] 31
32 def read_data(self, scm):
33 """Read each file."""
Class member
entities
has same name as its encolising class Entities
35
36 def __init__(self, scm, name, url):
37 """Initialize."""
38 self.entities = [] 39 self.by_guid = {}
40 self.by_name = {}
41 self.knownas = {}
Description
There is a class member with the same name (not considering the case difference) as its enclosing class.
This can cause confusion while reading the code later on keeping a track of what the field represents. It is strongly recommended to provide self-explanatory names so that someone who's reading the code doesn't have to spend time keeping a track of the variable/method names.
Not preferred:
class Orange:
'''We mean, the fruit.'''
orange = "#FFA500"
# Other class implementations
def get_orange(self):
return abc
fruit = Orange()
render_to_frontend(fruit.orange) # Rendering a color, but one can get confused with the fruit
render_bg(fruit.get_orange) # Not clear that `get_orange` is returning a color
Preferred:
class Orange:
'''We mean, the fruit.'''
color = "#FFA500"
# Other class implementations
def get_color(self):
return abc
fruit = Orange()
render_to_frontend(fruit.color) # Evident that we are working with color
render_bg(fruit.get_color) # Evident that we are fetching the fruit's color