Use of infix operator hack in production code (Python)
What is your opinion of using the infix operator hack in production code? Issues:
- The effect this will have on speed.
- The potential for a clashes with an object w开发者_StackOverflow中文版ith these operators already defined. This seems particularly dangerous with generic code that is intended to handle objects of any type.
It is a shame that this isn't built in - it really does improve readability
It will be measurably slower than more Pythonic code, fragile (e.g. in the way you suggest), and baffling to every expert Python programmer that comes upon such code for the first time.
If you want to turn Python into one of the very few languages that allow user-defined infix operators (such as Haskell), you're better off designing a way to alter the syntax dynamically for the purpose, implement it as a patch to Python's parser, and start lobbying for it -- if it improves readability as much as you say, then it shouldn't be that hard to get Guido's approval for a clean, easy-to-explain implementation (if Guido, as I suspect, should sternly reject it instead, then you may want to ponder who's a better judge of language readability: you, or the designer of one of the most readable widespread languages? but I can't channel Guido, that's the timbot's job;-).
In my personal opinion this would not be a great idea in production code: the biggest problem with it is that it totally non-standard and will probably leave non-familiar readers wondering where this novel syntax has suddenly sprung from.
I think you should prefer clarity rather than succinctness in general - Python is not C!
精彩评论