We've all been there: 


Your project failed or got cancelled. 
The code you spent days working on got rejected by your team. 
The design pattern you introduced to the team created chaos. 
Everyone ignores your ideas.


My question is, what is the most productive way for a programmer to handle development-related failures such as these?


  Your project failed.


Software development is highly prone to project failures, and depending on the severity, this is best handled by management. 

Many projects have failed and many more will fail, so take notes! Learn why your project failed so you don't make the same mistakes next time. You learn much more from your failures than from your successes. 


  What you have spend coding days on was rejected by your team.


Save your work (for later). There are two possibilities: (a) It sucks, and the fact multiple people responded the same way is indication of this (b) It's truly genius work, but far ahead of what people are used to or can understand. People generally do not like what they do not understand. Perhaps  its better to show it when the time is right OR in a different place with a different "Culture"


  Nobody listen to your ideas in your company.


Its probably a bad idea, OR the culture is not aligned with your thinking. Either move to a place that supports your culture or critically evaluate your idea again (objectively without your own bias) -> is my idea really that good? <- Kill thy ego


  The design pattern you introduced with force in your team created a mess.


Be honest, you tried your best but it did not turn out how you planned it. It may be better to start again or learn from the mistakes made in the design as a team and move forward.
