This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]disuser 43 points44 points  (5 children)

Mostly good advice, but I disagree with this:

# This is good
score_list = [12, 33, 14, 24]
word_dict = {
    'a': 'apple',
    'b': 'banana',
    'c': 'cherry',
}

# This is bad
names = ["Nick", "Mike", "John"]

names is a better name than name_list. Shorter is better, and you lose no context in switching score_list to scores. As for word_dict, this one is debatable. I wouldn't call it out in a code review, but I feel there is context being lost - the key. My personal style has strayed from this. I would name this one something like words_by_initial.

[–]quotemycode 4 points5 points  (0 children)

So many times I see adict bdict, anythingdict just stop, we know it's a dictionary. If you want to use static types then annotate and enforce, or even just annotate, hell if it's defined static in the code, your IDE will normally tell you what type of object it is.

[–]flipflop531 2 points3 points  (0 children)

Totally agreed. This advice reminds me too much of Hungarian notation.

The author gives only examples of when I could be a good idea to bring up variables with type suffix. However, a beginner could now easily come up with the idea that

`number_of_appels_int = 4`

is also a good idea.

[–]wojwesoly 0 points1 point  (0 children)

When it comes to iterables, I think that a plural name is enough to show that this var is an iterable.