O. Henry, the famous short story writer, had a secret for writing short stories, which can apply to writing - in general. O. Henry's secret was writing to entertain William Sydney Porter. O. Henry reportedly shared:
I'll give you the sole secret of short-story writing, and here it is: Rule 1. Write stories that please yourself. There is no rule 2. [...] If you can't write a story that pleases yourself, you will never please the public. But in writing the story forget the public.
And Harlan Ellison, the New Wave writer, agreed with O. Henry in that one should write stories that are self-entertaining, because if you can't write a story that amuses yourself, you may never wow the public. Ellison reportedly advised:
Write for the most intelligent, wittiest, wisest audience in the universe: write to please [i.e., engage] yourself.