Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Have you ever had this feeling that your code is bad, the whole project is a mess, and you just want to step off? On your daily job you can explain this feeling away with your coworkers, asshole boss, or something like this. But with side/pet projects there is really no excuse.

For example I'm currently maintaining my Firefox extension - fixing bugs and adding new features. Quite frequently when I go back to the code written months ago the feelings that arise inside me are quite controversial - "Did I write that? Really??" Knowing that proper implementation of new feature "the right way" requires throwing away whole module and still putting together a quick hack - sometimes I don't even hesitate.

As the project grows, features are added there remains less and less room for refactoring...

Do you have any recipes for dealing with this kind of emotional state? Do you just pull yourself together and give the whole project another thought, rewrite version 2? Or maybe just ignore all this - "working code is better than perfect code"?

share|improve this question

closed as not constructive by Jim G., gnat, Kilian Foth, Martijn Pieters, MichaelT Mar 26 '13 at 14:01

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

Maybe you could look at it from another angle. If you look back at code go "OMG did I write that", then think instead of how far you have come as a programmer to be able to see the flaws in something at the time might have seemed like the only way to do it. – dreza Mar 26 '13 at 2:01
Treasure that feeling, the only reason you have it is because you know a better way, the alternative is looking at the code and thinking "This is kind of crappy, but I can't think of any better way to do it". The former is a sign you're coming up with new solutions to problems, the ladder is a sign that you're out of ideas. – Jimmy Hoffa Mar 26 '13 at 2:37
ignore the mods, this is most definitely a constructive question – lkptrzk Feb 3 '15 at 14:46
up vote 4 down vote accepted

Don't hate. 2nd tier programmers hate. Craftsmen look at code without bringing ego into it. Code is not a reflection of who you are. It is a means to an end. Try to learn from your past mistakes and try not to repeat them but you can't do that if all you are thinking about is how shitty of a coder you are. So don't be a hater, don't be a 2nd tier programmer. Be a craftsman.

share|improve this answer
Related to this is the book 'Inner Game of Tennis' - a truly awesome book. But one of the first lessons is - you don't look at a shot you played as good / bad - you purely observe whether it was in / out. Become interested if there is a smell in your code - but just observe it, fix it and repeat. There's nothing bad, just stuff you can improve. – icc97 May 18 '13 at 8:56

From what you're saying, it sounds like you have accumulated techincal debt.

I think everyone has thought "did I write that". I suggest the following for doing what you can to improvide it:

  • Refactor where at all possible
  • Make sure your naming is consistent
  • Format the code to make it more readable
  • Add a peppering of comments if it needs it

Take it in chunks as you come across what you're unhappy with.

Do you have any recipes for dealing with this kind of emotional state? Do you just pull yourself together and give the whole project another thought, rewrite version 2? Or maybe just ignore all this - "working code is better than perfect code"?

I think most people have these feelings. You need to push past it and remember it is "just code" and it works for you, not the other way round.

My advise from what you've said is to take a few days and refactor and rewrite what you're unhappy with before adding any features or fixing bugs.

share|improve this answer
Well said! We all learn as we progress. This means seeing old code from when you didn't know better... It's normal. – Jeanne Boyarsky Mar 26 '13 at 1:26

As said already, you've accumulated technical debt. Refactoring may be a good tool, but it can also be abused. In the extreme, you could refactor all the 1s in your code into an interface constant named Constants.ONE. A contrived example, but one that serves to warn against refactoring as a silver bullet. What you're really after is technical debt containment. Keep a high quality architecture and you'll find that your mess, albeit always present in your code, remains confined to a certain module and is most often out of your sight. That realization always helps me enjoy my code.

I don't know at what pace your programming techniques evolve, but when I realize I wrote bad code it's not because I'm suddenly seeing a better way to solving a problem. Nowadays, I just don't learn a great deal in terms of programming techniques anymore - whether good or bad, my techniques are more or less established. It's more likely that I recognize my bad code as soon as I write it. You may be writing the code with the wrong mindset if you end up realizing the hacks later on. Code quality may not be a concern at the time you write it, perhaps because you write it under pressure.

I code at the highest level I can even for such things as Chrome extensions. I can rest assured that, due to architectural separation, I end up enjoying most of my code, because it stays focused and cohesive. I noticed a tendency to the contrary in fellow developers, especially Java or .NET developers, who sometimes think of Javascript as a lesser language and just whip together the quickest code they can write. I learned my lesson as early as high school, when my informatics teacher said when sitting at my computer to fix my crappy program: "all programs are worth salvaging". That mindset gave me a respect for all the programs I write, even throwaway scripts or SQL statements, which deserve comments and properly named variables. I warmly recommend giving this mindset a try, and you'll enjoy your programs a whole lot more.

share|improve this answer

Great question and I can feel your pain and emotions because I was into the same scenario few months back. Initially I was so upset and frustrated and feeling so bad for cleaning someone’s mess I asked myself several time “what the hell I am doing? I can’t take it any more…” but suddenly a very good suggestion was fired from my frustrated mind and as per that idea I created an XLS file with some common mistakes and their regular occurrences and then defined priorities to these line items so that I can go for all the cleansing in a managed way. During implementation my mind tried to pull me back by saying that this idea is also not going to work this is bullshit, but within 2 days the no of lines in the XLS reached to the healthy count of 40 and after observing those 40 line items in one go I found some great coding standards that every developer should follow in their day to day coding practices because knowing a concept is different but implementing that particular concept Is awesome like “LAZY INITIALIZATION” I know that concept or the whole development team knows that concept but no one follows or implement this. Those 40 line items motivated me a lot and ones you got motivated you are into the learning process and you will find that this time wasting cleansing activity actually brushed up your coding skills and you will always remember few of the common mistakes made by any programmer and even you will come up with some great ideas and suggestions for you future projects and their implementation so indirectly you are learning from someone’s mistakes. You are working for the means of organization benefit apart from your personal moral values.

Hope this will help you as well. Cheers


share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.