r/pythontips • • Apr 06 '19

Some Python anti-patterns

46 Upvotes

18 comments sorted by

View all comments

-1

u/[deleted] Apr 06 '19

[removed] — view removed comment

0

u/PiaFraus Apr 06 '19

When i see fruits, i know it's an iterable. The proper logic shouldn't give a damn of the types. All you know it's some sequence of something representing fruits. You can store them and print, and dont care about tyoes, together with this abomination of a syntaxis

1

u/[deleted] Apr 07 '19 edited Aug 29 '25

[removed] — view removed comment

1

u/PiaFraus Apr 08 '19

Heh. The entire point of that example was that a Tuple does not have the same interface as a list.

Let's assume you are right and this is the point.
Now let's have the the name would be fruits_tuple. Now it's a tuple and has the same interface as a tuple. So condition in your "entire point" is satisfied.

Did renaming resolve the antipattern?
No. Thus, the assumption that you are right and it was a point - is incorrect. The absolutely same set of problems with future developers would arise if your type hints are used and not enforced. "which can be confusing for other developers, or even your future self, who can act on the variable assuming that it is of the type mentioned in its name" - jsut change "in it's name" with in it's type hint.

Hence, labeling the iterable "fruits_list" is therefore an "anti-pattern" (aka a bad idea).

Hence labeling the iterable (with type hint) fruits: Tuple[str, ...] is therefore an "anti-pattern" (aka a bad idea).

and when you ran mypy, it would have caught it. Or even better your interpreter could have caught it while you were still coding.

So now you are enforcing 3rd party tools?

But whatever floats your boat. Type hints are awesome and mandatory in my work's code base.

I am just glad I am not working with you.

P.S. I had a conversation regarding the type hint with a python core developer, whose videos are constantly praised in /r/python and he is not sold and had a list of good reasons, why type hinting is just making python looks more ugly, making readability worse without bringing much benefits.

Don't forget the "we are all consenting adults here". Python is not having private/protected fields in classes for the similar reason.