6 ms·
Decorators should be higher on this list. I work with Python daily and I absolutely loathe people's custom decorators that obfuscate functionality away, like ST
by hacknat 9y ago
Decorators should be higher on this list. I work with Python daily and I absolutely loathe people's custom decorators that obfuscate functionality away, like STL in C++, except no type system of course.
Also, preach on duck typing it's a python myth that is absurd. If it quacks like a duck means I had to figure out what it was.
This language is slowly destroying my soul, one painful unit test at a time.
- thegeomaster 9y agoWhy do you think the STL obfuscates functionality?
- solipsism 9y agoI'm with you except "like STL in C++". What does that mean? STL is not custom, it's by definition standard. Maybe you meant to say TMP?
- hacknat 9y agoI have seen some ridiculous templates in C++. Isn't STL Turing complete?
- solipsism 9y agoYou're definitely talking about TMP, template metaprogramming. The STL is a set of useful libraries that do specific things. Like represent strings or vectors. Or sort, or generate random numbers. If anything the STL is too small. TMP, on the other hand, is an entirely separate language within C++ that allows you to create monstrous, arcane code that's incredibly hard to debug or understand. Some of the STL uses TMP. But it sounds like custom TMP is the thing you don't like.
- majewsky 9y agoC++ template metaprogramming is Turing-complete, except that in practice your loops are going to be cut short by the maximum recursion limit of the compiler (900 in g++, see -ftemplate-depth option).
- nerdponx 9y agoDecorators are just higher-order functions. Of all my frustrations with Python, decorators are not one of them.
- sametmax 9y agoExactly, decorators are just a syntaxic sugar for foo = bar(foo). Nothing bad about it.
- solipsism 9y agoNot true. Decorators hijack your function surreptitiously. They turn y = f(x) into y = g(f, x) in a sneaky way that doesn't require you to adjust to call site. In this way it's more than "just higher order functions".
- Waterluvian 9y agoI love decorators so much (when used well). For example, I used a decorator the other day that I called `@logperf` that I can pin to any function, which will `logger.info` the approximate time it takes to run the whole function. It doesn't mutate what the function does, it just adds a side effect.
- yxhuvud 9y agoIt doesn't take away the argument that neither decorators and with would be necessary if lambdas was a language feature.
- Daishiman 9y agoThe point isn't about the functionality of a lambda. The point is that the syntax for a decorator denotes semantic meaning that you don't get when composing a lambda on your own.
- SmirkingRevenge 9y agoClasses, objects and functions themselves all obfuscate (or rather encapsulate) functionality away in similar ways. What is so particularly bad about decorators?
- crimsonalucard 9y agoDecorators are good when used properly and functionally as in it returns the composition of two functions. In one django project one of the old coders created this decorator that adds this huge context object that automatically folds little tidbits of info from cookies and GET query params as an object stuck into an attribute that's part of the request parameter, then proceeds to use that context object everywhere. We get mysterious view functions that has lines that looks like this: request.context.start(), and will utterly fail if you removed the decorator. Literally, please do not do this shit. Your function should be modular and able to be useable with or without being decorated.
- scriptkiddy 9y agoThat honestly sounds like a very poorly written decorator to me. I work with Django professionally and have been for years now. I'm not going to say I know the framework like the back of my hand, but I'm pretty damn close. Django already supplies the request object to every single view regardless of whether or not the view is class or function based. Why you would need a decorator to replicate existing functionality is beyond me. It's possible that the decorator was created for an older version of Django that was missing some important part of the request object, but I can't for the life of me figure out what that would be.
- rhaps0dy 9y ago>This language is slowly destroying my soul, one painful unit test at a time. So we're two! I'm trying out Rust for a side project now and so far it's fun. Lots of compile-time checks, non-crippled lambdas, and you can use itertools too!
- dizzystar 9y agoI like decorators. I don't quite understand the author's complaint about this specific case of decorators. An initial read makes me wonder why he doesn't use dynamic routes, which is where the decorator / function-name pattern really starts to shine.
- kafkaesq 9y agoThis language is slowly destroying my soul, one painful unit test at a time. At the end of the day, Python is just an abstraction. It isn't destroying your soul, or doing anything else to it. OTOH, your conscious decision to stick it out in a job that makes you work with a language that you find "absurd", and where people do things you "absolutely loathe" but have to put up with, anyway? That's what's destroying your soul, man.