Skip to content Skip to sidebar Skip to footer

Python Sequence Naming Convention

Since there is no explicit typing in python, I want to be able to make the difference between sequences and non-sequences using a naming convention. I have been programming with py

Solution 1:

In general, avoid this kind of behaviour. Notice from PEP8

A Foolish Consistency is the Hobgoblin of Little Minds

which is exactly what calling a variable weightss would be doing. So in general have your variables describing what they are, not according to some naming convention:

weights = [44, 66, 88]
weight_groups = [[44, 66, 88], ...]

etc.

From the same section of the PEP8:

But most importantly: know when to be inconsistent -- sometimes the style guide just doesn't apply. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask!

Solution 2:

The "s" naming convention would name the variable weightss, which is ugly. I am sure there is be a better naming convention for sequences.

I think the convention you're describing is meant to be interpreted as "whenever you have list of something, make it clear that it's a list by pluralizing it". For example, if you have a list of instances of grass, you would call this grasses, not grasss. I don't think it's meant to be taken as literally as you're taking it.

PEP always advises you to take your own approach if that is more readable and useful. As Ali mentioned, one of the guiding principles of PEP is that you shouldn't fall prey to foolish consistencies.

Solution 3:

Whatever you little heart desires....

Just kidding, but I wouldn't get to hung up on it. If it's ugly, do something to make it more readable like seq_weight and seq_weights

Solution 4:

Why not just thing_list or thing_seq?

Post a Comment for "Python Sequence Naming Convention"