DEV Community

sumandari
sumandari

Posted on

When should I refactor my code into a decorator

Continue reading the book, this is a very good book. I suggest you to read it too.

It says:

  1. don’t create a decorator in the first place. Wait until you see the pattern.
    Yes, I totally agree. I created a decorator for user login and payload validation after I used it everywhere and found the pattern.

  2. Create the decorator if it will be used more than three times.
    Okay, that also make senses. Why should I create a decorator if I only use the logic once.
    Not sure if it’s twice. But three is a fair number for me.

  3. Keep the code in decorator minimum.
    Too much line and logic will give me a headache when applying a decorator.

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay