Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is one of the reasons I hate python, it allows for so many weird things that are only borderline standardised, if at all. When I started with python decades ago, I was also all hype, list comprehensions and functional patterns everywhere, and why not monkey patch a third party library on runtime? Now I regularly see such code written by the new junior devs, painful to maintain, painful to integrate into a larger code base, most certainly failing with TorchScript, and plainly convoluted for the sake of appearing smart.

If you want to code it Haskell, have you considered using Haskell?



There is nothing weird or "borderline standardized" about generators...


Fair point, they have a proper PEP. I’ve been burnt by `lst[::-1]` and the likes which TorchScript does not (did not?) support and to my surprise learned that the standard is not clear on this behaviour. Generators are fine but I somewhat fail to see their use as they move state somewhere not really clear and I have seen plenty of problems with needing `list(generator())` confusing people


I wrote a whole response thinking you were like 19 but you say you started with Python decades ago. If you still haven't gotten the hang of it I don't think there's anything to say. Generators have been in python for more than 2 decades so I find your claims extremely suspect.


I am not sure what your argument is supposed to be. That I am wrong because I haven’t gotten the hang of it after all these years? I do understand generators. For a long time. I still believe they are usually an anti-pattern, same like massive abuse of inheritance where you have 20 classes but only a single instance but you made your code “future proof”.

The point I wanted to make is that using generator, in particular like here, is something that I consider ugly and difficult to maintain and it will probably have to be rewritten when trying to export to TorchScript. I really do not see how “just get a hang for it” can help me reevaluate my perspective

Edit: Maybe you were hung up on my “standardised” - I have to admit I do not know how thoroughly the PEP defines generators and if really all edge cases are defined without needing to check the python source code. From past experiences, my trust in python language standards is a bit shaky, as it had been difficult to reproduce the very exact behaviour using a different language, or python features - without requiring digging through the sources.


I’m using python since version 1 my friend, no need to get personal and insulting. I gave an example of something that is not defined properly in a PEP as well. I really do not like python, and one of the reasons is that is encourages writing of what I believe is code that is harder to understand and harder to maintain for people who didn’t write it. There’s nothing wrong with Haskell, but it has a rather steep learning curve when you’re not coming from functional programming and if you embrace patterns like this you put extra burden on your colleagues.


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.


That’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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: