Here are four ways in which I remedy hating the code I'm writing, and what you should do if you hate the code you're writing.
If you hate the code you are writing, why are you writing it?
I've experienced four scenarios in my career in which I've hated the code I've written:
And here's what I did to remedy each of these situations, respectively:
I quit the job in search of a place where I had more control over the code quality.
I powered through until I was either good enough that the language/framework was fun or advanced enough to accept that it is no fun for anyone.
I have three approaches for dealing with a language I don't like.
If all these fail and I approach a last resort, I weigh my options. If I want to keep my job, I just do the work in that language (the suck-it-up approach). Otherwise, I'd quit. I've yet to hit a last resort with a language I don't like yet.
I refactor the code.
There are so many programming languages out there today. You couldn't even learn enough to know which ones you shouldn't use, let along figure out which one is best for the the job. And there are an abundance of tools, frameworks, and jobs for every popular language.
So, if you find yourself writing code you hate, ask yourself why. Attempt to remedy the situation. And if it comes to a last resort after the remedies dissipate, weigh your options and either suck it up or move on to something new.
Life is too short to write unsatisfying code.
Write code you love.