Writing software is fun—just like a game. You get to analyze and invent. You can do new things with the latest technology, creating something that didn't exist. It's no wonder so many young people take an interest in the field.
Having fun is a good enough reason to do something. But more importantly, having fun is a determining factor in how well you work. Most psychologists would agree that people perform their best when they play. When a task is intrinsically pleasurable, when the activity itself is enjoyable, people take to it and do it well.
Motivational psychologists Edward Deci and Richard Ryan, of the University of Rochester, point out that when you introduce either a stick or a carrot, the fun goes away and productivity drops. If you studied computer programming at school, from the moment you started being graded for your work, writing software was no longer a game.
Then, when you became a professional software engineer, the coffin was nailed shut. Programming became something you do for a reward, or to avoid punishment. Deci and Ryan say that when we feel coerced into performing a task, we lose our sense of autonomy, which is one of three things we need to feel happy. (The other two are a sense of competence and a sense of belonging. I'll get to those in a moment.) This loss of autonomy results in diminished happiness, an it causes us to be less productive.
In your professional life, work is frequently forced on you in one way or another. You rarely get to start a project from scratch, you almost never get to decide on your own what features to include, and you always have to answer to the person who's paying you. This coercion weighs even heavier when you have an abusive boss or a pushy client.
How can you motivate yourself in an environment that's less than ideal? Let's look at what scientists have found.
A Primer on Motivational Psychology
Laboratory experiments have demonstrated that if you ask people to perform an uninteresting task, but you provide a meaningful rationale, they'll motivate themselves to do the work.  When the subject understands the reason behind the demand, he or she feels involved in the decision and can do the work with a sense of choice.
Other studies have shown that when people receive positive feedback, they become more motivated; whereas, when they receive negative feedback, they become less motivated. The effect of the positive or negative feedback is regulated by how competent people perceive themselves to be at the task. 
These studies suggest that if we feel as if we've chosen to do a job, and we're capable of doing it, we perform well. But that's not all—we also need to feel approval and a sense of belonging.
Experiments have shown that in the presence of an indifferent adult, children who are performing an otherwise interesting task lose their motivation.  In other studies, students who perceived their teachers as cold and uncaring were less motivated. 
Based on these kinds of findings, a growing number of motivational psychologists agree that three things are necessary for happiness:
- Autonomy: We want to feel that we can freely choose what we do.
- Competence: We want to feel that we're good at something.
- Belonging: We want to feel that we're part of a group.
If all three of these elements are present, we're happy and productive. If one is missing, we're unhappy and try to compensate.
Bosses and clients who use intimidation and humiliation tactics to get people to do work threaten all three of these components, either directly or indirectly. How can you feel that you've chosen a task if you were coaxed into doing it? How can you build a feeling of competence if you aren't in an environment that fosters good work? How can you feel a sense of belonging when the prospect of being removed from the group is always hanging over your head?
Five Practical Tips for Self Motivation
Strictly speaking, whenever you do something because somebody else asks you to do it, you're no longer self-motivated. Your performance is diminished; and the work is likely to be less satisfying. Since none of us lives in a vacuum, we have to face the fact that most of what we do is the result of a request coming from somebody else.
The best you can achieve is what Deci and Ryan call "self-regulation of extrinsic motivation." Depending on the degree to which you accept the value of the task, you react in one of three ways: complete rejection, passive compliance, or active commitment. When the boss or client who asks you to do something is abusive, it's even more difficult to take on the task wholeheartedly.
To improve your chances of becoming actively committed to work that someone else has asked you to do in an awkward way, follow these five rules:
- Avoid confusing the person with authority figures who've troubled you in the past. Even if the boss or client is unpleasant and pushy, he or she isn't someone else that you previously knew. Don't add more resistance. Take this person for who he or she is, and remember that the person may be somebody you'd like, outside of work.
- Don't reciprocate if you feel that the other person is being rude. Nobody stands in front of the mirror in the morning and tells himself or herself, "I'm going to be nasty today." These people usually perceive the situation differently than you do; they generally aren't aware that they're being rude. Consequently, if you start acting in the same unpleasant way, the other person will think that you're the instigator.
- Ask questions to try to get to the reasons behind what the other person wants you to do. No matter how awkwardly they make the request, most of the time there's some logic behind what other people ask you to do. Sometimes, by getting them to explain the issues more clearly, you help them think things through, and you might even help them find better ideas. The more you get to the bottom of what's being asked, the more the request makes sense to you, and the easier it is to accept.
- Remind yourself of your own goals and see whether the request fits into what you're really trying to accomplish. Your bosses and clients' objectives aren't your objectives. You want to accomplish other things. But what bosses and clients ask you to do probably fits into your goals: Are you trying to get a raise or a promotion? Are you trying to become an independent consultant? Think of what you're being asked to do in the context of achieving your personal goals.
- Compartmentalize bad feelings. Don't let your displeasure spill over to your other tasks, and separate the awkward way demands were made from the work that needs to be done.
If you follow these five rules, chances are that you can get back to having fun writing code.
An affiliated professor at the Grenoble Graduate School of Business, Pat Brans also provides corporate training on time management and personal effectiveness. Most of his in-house corporate experience focused on applying technology to enhance workforce effectiveness, as he demonstrates in Mobilize Your Enterprise: Achieving Competitive Advantage Through Wireless Technology. Now he takes productivity to another level by unveiling the secrets of high achievers in his book Master the Moment: Fifty CEOs Teach You the Secrets of Time Management (BCS Press, 2011). Check out Pat's Master The Moment website to learn more about how to make every moment count, and the six steps to take for greater ROI on your efforts in business and in life.
 Edward L. Deci, Haleh Eghrari, Brian C. Patrick, and Dean R. Leone. "Facilitating Internalization: The Self-Determination Theory Perspective." Journal of Personality Vol. 62, No. 1 (March 1994), pp. 119–142.
 Robert J. Vallerand and Greg Reid. "On the Causal Effects of Perceived Competence on Intrinsic Motivation: A Test of Cognitive Evaluation Theory." Journal of Sport & Exercise Psychology Vol. 6, No. 1 (March 1984), pp. 94–102.
 Rosemarie Anderson, Sam T. Manoogian, and J. Steven Reznick. "The Undermining and Enhancing of Intrinsic Motivation in Preschool Children." Journal of Personality and Social Psychology Vol. 34, No. 5 (Nov. 1976), pp. 915–922.
 Richard M. Ryan and Wendy S. Grolnick. "Origins and Pawns in the Classroom: Self-Report and Projective Assessments of Individual Differences in Children's Perceptions." Journal of Personality and Social Psychology Vol. 50, No. 3 (March 1986), pp. 550–558.