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

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay