event
has same name as its encolising class Event
206
207class Event(models.Model):
208 addon = models.ForeignKey(Addon, on_delete=models.deletion.CASCADE, db_index=False)
209 event = models.IntegerField(choices=AddonEvent.choices)210
211 class Meta:
212 unique_together = [("addon", "event")]
category
has same name as its encolising class Category
52 verbose_name=gettext_lazy("Project"),
53 on_delete=models.deletion.CASCADE,
54 )
55 category = models.ForeignKey( 56 "trans.Category",
57 verbose_name=gettext_lazy("Category"),
58 on_delete=models.deletion.CASCADE,
group
has same name as its encolising class Group
56
57
58class Group(Guideline):
59 group = True 60
61 def is_passing(self) -> bool:
62 # Not used
font
has same name as its encolising class Font
29 style = models.CharField(
30 verbose_name=gettext_lazy("Font style"), max_length=100, blank=True
31 )
32 font = models.FileField( 33 verbose_name=gettext_lazy("Font file"),
34 validators=[validate_font],
35 storage=FONT_STORAGE,
comment
has same name as its encolising class Comment
41
42class Comment(models.Model, UserDisplayMixin):
43 unit = models.ForeignKey("trans.Unit", on_delete=models.deletion.CASCADE)
44 comment = models.TextField()45 user = models.ForeignKey(
46 settings.AUTH_USER_MODEL,
47 null=True,
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.
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
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