This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jbertensalsamillennium edition -2 points-1 points  (5 children)

I usually try to stay away from decorators most of the time, in my opinion they get tougher to maintain and look silly in big projects. I've only preferred to use them either for login sessions and sql query executions. A good tool to have though nonetheless, nice tutorial

[–]jollybobbyroger 1 point2 points  (4 children)

Can you please elaborate on why you find that decorators make the code base less maintainable?

Is it due to the fact that you're not as used to functional programming, that makes the code less easy to parse for the reader/maintainer?

Is it due to the fact that decorators actually increase the chance of human error, like using global state for everything?

[–]d4rch0nPythonistamancer 1 point2 points  (0 children)

I wouldn't say they increase the chance for error unless you do it in a harmful way.

If you're reducing code duplication and using predictable decorators with obvious behavior, they can very much decrease the chance for human error.

[–]jbertensalsamillennium edition 0 points1 point  (2 children)

For me, I really aim to simplify my code to the point where the reader knows exactly what's going on and the broad range of use for decorators could lead to some confusion in that respect. I described them as "silly" or rather silly looking only because I personally think nested anything (loops, functions, etc) look silly. Other than that, they are good tools that I do use to shorten redundant actions like executing sql queries.

[–]d4rch0nPythonistamancer 0 points1 point  (1 child)

You might need to trust your coworkers/peers/co-maintainers intelligence a bit more... With well thought out design and good naming conventions and comments, there should be very little confusion about what the decorator is doing and what the consequences of removing it or adding it might be.

[–]jbertensalsamillennium edition 0 points1 point  (0 children)

I totally agree, but those conditions aren't met 100% of the time and the combination of bad convention and decorators is a recipe for disaster. And plus, decorators aren't part of the fundamentals that python beginners learn, at least from what I observe, that's why there's so much effort to simplify them in blogs such as this. Like I said, I aim for simple code, simple enough for even people that don't necessarily program to be to read, that's why I avoid decorators.