django - How frequently should Python decorators be used? -


I recently started experimenting with dragon decorators (and higher order function) because it seemed that they could do more to my Django unit. brief. For example, instead of typing:

  def visit1 (): login () do_stuff () logout ()  

I can do this instead < However, after using some experiments I found that the decorator was not as easy as I had hoped. First of all, I was confused with different decorative syntax which I found in different instances, until I did not think that decorative people behave differently, then I tried to decorate a method, and In the end it was discovered that it was not working because I had to first by adding the __Matching <__ method. During this entire process, I have been confused more than a while and it has still found that it is more common to debug this "decorated" code because it is usually for Python. Now I am evaluating again whether I really need decoration in my code, because my initial inspiration was to save a little bit, because not really because of the high-order function required.

The question is whether decorative should be used generously or in short order? Is it ever more to avoid using Pythonic?

Decorative are fine on your location and certainly do not save - when appropriate ;-) I have your question Essentially "OK, when they are looking as appropriate"?

Some classes and some of the sections on adding some prefix and / or postfix codes All methods do not have a good example. Did it have all the methods, class decorator, @thessenetu to wrap all the methods It will be better than repeating ;-) If it is once in a blue moon, then it is not repaired for rappers (decorative or otherwise). In the middle, there is a large field where the decorations are really suitable.

It sprouts one of the golden rules of programming - dry, because do not repeat yourself. When you see your code repeating, you should reserve the recurrence again - and the Knowing is an excellent tool, though they are only one (Supporting methods and works, custom metallases, generators and other etacitors, reference managers ... In the last few years we have added some features to Python, / Em> can be thought of as dry-assistants, this is the easy and easy way of this type of duplication or again!).

If there is no recurrence, there is no real call to refactoring, so there is no real need for decorators (in particular) - in such cases, YAGNI (Y'An't Gonna Need It can dry trump; -).


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -