On Thu, Apr 7, 2016 at 3:40 AM, Steven D'Aprano <st...@pearwood.info> wrote: >> I fully agree. But you don't have to use classes, exceptions, >> decorators, generators, iterators, closures, comprehensions, meta >> classes, ... the list of meaningless buzzwords just goes on. > > Honestly, hearing you say that makes you sound just tired and lost, an old > dog who has given up on the possibility of learning any new tricks. That's > sad, because none of those technologies above (with the possible exception > of metaclasses, which are kinda mind-bending the first eighty or ninety > times you read about them) are that complicated or difficult to use. > They're just *different*. > > I feel for you -- when I hear folks talking about asynchronous programming, > or databases, I feel just as lost.
Interestingly, most of the technologies cited as "meaningless buzzwords" are derivatives of one concept: code reuse. What are classes? Structured code reuse. What are decorators? A form of metaprogramming; in its mechanics, it's general and flexible, but in usage, it's most often a means of refactoring something so you don't have to write the same code more than once. Generators are a specialized form of iterator class - you can always rewrite a generator function such that all locals become instance attributes, and execution state is maintained in more attributes, and then put all the work into __next__. Closures let you generate functions on the fly, saving you the hassle of creating them all as classes. Comprehensions let you avoid the boilerplate of iteration and appending. Metaclasses let you push all the coolness of class instantiation up a level, and mess with the class's class. The only one that *isn't* largely about code reuse is exceptions, and even then, you can argue that structured exception handling is a means of eliminating the boilerplate of return value checking. (Personally, I see it more as a simplicity and correctness thing, because return value checking is NEVER done thoroughly enough.) Now, asynchronous programming and databases, they're completely different beasts. But it's fascinating how many cool technologies we have just for that one purpose of avoiding code duplication. ChrisA -- https://mail.python.org/mailman/listinfo/python-list