3 ms·
I also really dislike Python but actually their implementation of generators is pretty good IMO. Few languages have it, e.g. Rust still doesn't have generators.
by IshKebab 2y ago
I also really dislike Python but actually their implementation of generators is pretty good IMO. Few languages have it, e.g. Rust still doesn't have generators.
They are pretty niche but when you find a situation that needs them they're really elegant. I've used them for generating deterministic test stimulus and it's really nice.
- fp64 2y agoThat’s maybe my point, maybe not. Generators can be useful, but somewhat niche as you said. I still prefer explicit code and try to avoid generators, I can’t remember the last time I wrote a yield. I disagree on their elegance. From my earlier days in python I remember writing a lot of convoluted things that felt smart at the time but turned out stupid, and I think representing infinite list with recursive generators in python is exactly that. Maybe a fun exercise to show what’s possible, but from painful experience I am quite certain someone will read articles like these and apply it everywhere without fully understanding it. I loved perl and how terse and expressive I could be, but after a little while of not using it (hah, python came to my life!) I had no clue anymore what my code was supposed to mean, and the same happened later to my “oh so elegant” python code eventually. Nowadays I mostly work with python ML code that has to be exported as TorchScript, thus I’m very sensitive to things that don’t work there. Not per se a problem with python - but having rewritten a lot of code to make it work, pretty much each and every time I found the explicit, imperative rewrite much cleaner and easier to follow and understand