Kozea / Pyphen

Hy-phen-ation made easy
https://courtbouillon.org/pyphen
Other
198 stars 24 forks source link

Type annotations? #50

Closed ariebovenberg closed 1 year ago

ariebovenberg commented 1 year ago

Hi there, it seems like the use of type annotations is becoming ever more popular in the community. Is there any reason Pyphen doesn't have them? I'd be happy to submit a PR šŸ™‚

liZe commented 1 year ago

Hi there, it seems like the use of type annotations is becoming ever more popular in the community. Is there any reason Pyphen doesn't have them? I'd be happy to submit a PR šŸ™‚

Hi, and thanks for the kind proposal!

Weā€™re not fond of type annotations for many reasons that would be too long to discuss here šŸ˜„, thatā€™s why we donā€™t have them in Pyphen (and in other projects maintained by CourtBouillon). But, well, maybe one day, at least for "small" libraries like Pyphen. Thatā€™s a topic for discussion, because theyā€™re becoming popular as you notice, thatā€™s why we often take a lot of time to answer this kind of issues! But itā€™s not the moment (yet?) for us.

Iā€™m closing this issue, because thereā€™s nothing to yet!

ariebovenberg commented 1 year ago

Thanks for the well-considered reply šŸ‘ . Interesting to hear that this is a conscious choice. I can imagine reasons for this, but I'd of course be interested in your considerations šŸ‘€ . Publishing this rationale may prevent this type of question from occurring in the future. Feel free to close the issue as the question has been answered.

liZe commented 1 year ago

I can imagine reasons for this, but I'd of course be interested in your considerations šŸ‘€ . Publishing this rationale may prevent this type of question from occurring in the future.

Why not!


First of all, Iā€™m not trying to convince anyone that type annotations are "bad", and I donā€™t want to be convinced that they are "good". I find them somehow useful, but I also find them quite annoying.

Thatā€™s only my personal point of view.


Iā€™ve been working for some time on a quite big project with 100% type annotations, and Iā€™ve found them really interesting and intellectually challenging. Thatā€™s a great exercice to really think about the type of your parameters, it forces to take care of corner cases and to be sure about what you can and canā€™t do with your functions. Iā€™ve spent a lot of time carefully defining types and see mypy give me 100% coverage, and each time it was great reward!

But, even if itā€™s rewarding, letā€™s face it: I donā€™t find them really useful in Python.

When I write code with statically typed languages, checks at compilation time can give me some confidence with my code. The best language Iā€™ve tested for this is Rust: it can take a lot of time before my code compiles, but when it does I can be almost sure that it does what I want. I then have the impression that the large amount of time Iā€™ve spent defining types and ownership is very useful for the quality of the code I write.

I have the impression that adding type annotations in Python takes time, but that itā€™ll never give me the confidence that types give me in other statically typed languages. If I want to carefully think about types, then I prefer to write Rust! The compiler is amazingly powerful, and it is by design.

To be honest, I often donā€™t want to carefully think about the types I use. Iā€™m soooo lazy. For sure, itā€™s really easy to write code that doesnā€™t work with Python. But itā€™s also really easy write code that works. šŸ’œ Thatā€™s what I love šŸ’œ. It will never be as clean, as solid, as "right" as Rust, but itā€™s damn easier, faster and shorter, at least for me! And I can always write tests to check that I didnā€™t break anything.

Moreover, adding type annotations adds code. And I love when code is short, because I find it easier to read and to maintain. I think that finding "good" variable names is important because it increases readability, for example when reading the signature of a function. When there are type annotations, I really lose the ability to understand what the code does, because I have the feeling that types tell me how the code works.

In the future, I may be interested to add type annotations in projects that I know very well, if theyā€™re small enough to fit entirely in my head. But my head is really, really limited!


TL;DR: Letā€™s say that I prefer when code is short and simple than extensive and exact.