There's always a combination of things that impact your motivation and productivity - including context. So it will vary with days and times.
I have begun to see a lot of this through the lens of self-care and burnout. So the thing I do is ask myself three questions:
What am I LEARNING from whatever task I am doing right now = even if I fail, even if people don't appreciate what I did, even if no one notices - as long as I gained knowledge, I already won. And there is always something to learn from every situation.
What is the OPPORTUNITY COST of the time I spend doing this task = is there something else that would bring me higher value (where value can be impact, happiness, health .. whatever you need) in that time time frame.
How much CONTROL do I have over the situation = if I don't have control then I need to shift to either a coping strategy (find ways to get through this till the next time slot of happy work comes along) or a comfort strategy (find ways to add things to the task that make me happy, so that it becomes less stressful)
From the self-care perspective = good sleep, healthy eating etc. are all good places to start. But I also recommend you read "When" (Daniel Pink) to see if you are an early bird or a night own. In other words, every human apparently works on a cycle of productivity (some being better in early mornings, other at late night) and knowing your behaviors can help you adjust the kinds of tasks you give yourself for each part of the day. Decision fatigue is real - as the day goes on your brain tires and you make worse decisions and have less resistance to stress triggers. Being aware of these goes a long way to blocking or overcoming them.
My strategies for coping are currently in three buckets:
= CONTROL = use #30Days habits to train myself to do things differently so I control triggers like eating bad food or not sleeping enough. Do one tiny thing consistently (e.g. sleep 8 hrs) and see if it helps. I am doing this with food (see my #30Days #SelfCare series on Twitter)
= COPING = find ways to block stressors I cannot control. Toxic people and situations are high on that list. I cope by sketching. I love to sketch and it keeps me focused and happy. So I doodle. And now I am trying to incorporate that meaningfully into my work so I can find ways to be creative within constraints.
= COMFORT = find people and situations that bring you joy and always always take a minute to remember them and be grateful for those things in your life. I've found that oftentimes when I feel really demotivated or frustrated, it helps to sit with my 10yo and talk about various topics. And I always feel recharged after. It's remembering what makes us all unique and why, given a chance, none of us would trade who we are for anyone else.
Hope that helped - and wish you all the best!
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.