First is the sheer joy of making things. As the child delights in his mud pie, so the adult enjoys building things, expecially things of his own design.
Second is the the pleasure of making things that are useful
to other people. Deep within, we want others to use our work and to
find it helpful.
Third is the fascination of fashioning complex puzzle-like
objects of interlocking moving parts and watching them work in subtle
cycles, playing out the consequences of principles built in from the
Fourth is the joy of always learning, which springs from the
non-repeating nature of the task. In one way or another the problem is
ever new, and its solver learns something: sometimes practical,
sometimes theoretical, and sometimes both.
Finally, there is the delight of working in such a tractable
medium. The programmer, like the poet, works only slightly removed
from pure thought-stuff. He builds his castles in the air, from air,
creating by exertion of the imagination. Few media of creation are so
flexible, so easy to polish and rework, so readily capable of realizing
grand conceptual structures.
Pretty much sums up my motivation.