Why Is So Much Code So Bad?

I've been in the position to read a lot of code written by many different developers. And most of it is terrible.

When I first noticed this I figured I was being too hard on the developers, they didn't have as much experience as I did, they didn't get any training, nobody else on the team was capable of mentoring them, etc.

But after many years of seeing the same stuff I just have to assume that big ball of mud procedural coding is the state of the practice for the average developer, even those with many years of experience.

Why is this? And more important, how can we change this?

Personally I find the best way to improved someone's coding ability is to pair with them extensively on a real project (hands on mentoring). But this only works if the project team is really small. I can't pair extensively with everyone on an 8 person team.

Training seems like a possible solution, although it seems to have limited usefulness.

Ultimately I think it comes down to an individual's drive and willingness to learn/change. All of the really good programmers I've met are self taught.

Is this something you've noticed in your workplace? What are you doing about it?

11 Comments

  • How long ago was the code written? Personally, I have discovered that code even I have written perhaps 3-4 years prior often seems crusty when I look at it again. Then again, SOME of my code does hold up, and as I see that, I try to jump onto whatever seems to have caused that code to continue to look OK even years later.

  • Also, I do concur that programmers who are good are often those who are driven to learn and grow. How many programming related books have they read in the last year? Do they have a development setup at home?

  • >How long ago was the code written?



    I agree with your comments, but I am talking about freshly minted code, version 1.0 and all that good stuff. And still the code smells to high heavens.

  • I quit.



    Not long before I handed in my resignation ( 3 more work days, and then I start the new job), I said to the new Architect/Manager and Buisness Manager. "Do you know what the difference between me and them is? Last night they were watching the new extended version of Lord of The Rings and I was writing code."



    My old code sucks (most good programmers will agree that their old code sucks), but it can be fixed, by me or by you, without trouble.



    There are a lot of people who write code because it is their job.



    Programming is my craft.



    It isn't about willingness, it is about hunger.

  • Yes I get this all the time.

    My current role is pretty much making sure the development teams do things that make sense.



    We also do code inspections. This is not ideal as it's usually too late in the process to have them change their code.



    Basically I think it comes down to someone's attitute to learning. If they are not interested in learning, then they won't be good programmers!!

  • SHIP !!

    That's just the sort of attitude that is at the root of the problem.



    What a terrible reply !

  • There is always a bigger dog, and the code can always be better.

    I'm going somewhere where I wont be the big dog, just one of the medium dogs. This is good, because I realy am a medium dog (with the potential to grow).



    I know more today than I did at the start of the day yesterday.



    I didn't know the best way to do it, but when you look at what I did, you will say "he did this because he wasn't aware of the ABC123 pattern".



    Shiping the product is not really the end of the project, you also have to fix the bugs when they come in.

  • xyz,



    You are absolutely right - "SHIP!" is a terrible attitude. The problem is that it's the attitude of many managers. How many programmers are eager to cut corners and release stuff before it's done? Not many, I'd bet - they are the ones who'll have to deal with all the bug reports, after all.



    In my experience, programmers cut corners and write sloppy code because they are struggling to meet unreasonable deadlines set by incompetent managers. It's a sad fact of life, but you aren't going to get anywhere by blaming the programmers in this situation.

  • Bad code is due to a couple of reasons...



    1) There are sloppy and lazy programmers out there who are just bored or otherwise uninterested in there jobs. Why can some mechanics fix that noise when others can't?



    2) MANAGERS and unreasonable DEADLINES. I dont know about any of you but I am never done with a project. I am picking through code up untill the very end, and even then it is never done to my liking!

  • Most people write bad code for several reasons -- be it a bad design, insufficient knowledge, boredom, or plain simple stupidity. However, from what I have seen, programmers who think through the problem before writing even a single line of code, code better on an average. Also, programmers who can think of programming without associating it with a language do write better code. These are the folks that think in terms of algorithms before thinking in terms of code.



  • Honestly, here goes.  People skip the basics.  Do they learn programming logic first?  If not do they go back and pick up a book on generic logic?  I know many programmers that have years of skill sets and projects completed, that all say...I would have done that so different, or been faster, made less mistakes if only I learned or read this years ago.  Also the advent of the script kiddy.  "This looks good, so lets copy and paste"  It was not honestly good, you just did not know any better.

    Programmers and coders also need to start looking at the bigger picture more often.  Security is not a check box.  It is an ever changing way of life and there is no one way destination.  Many programmers have the I built it, it worked, I am done attitude.  It worked on your PC or your small controlled environment, now what about a large network or world wibe web?  Lets define what "it worked" actualy means.  You made a form.  It passed data on.  Is that data safe?  Is it reliable? Is it a copy paste one size fits all, and you just changed the text?  Are you reading about exploits and understanding how many months of your work may need a simple adjustment to stay viable to your work environment.

    Bad code will happen.  Bad programmers keep using it.  Good code is the result of always researching, learning, and adjusting.  There are no finished projects, unless they are retired from service.

Comments have been disabled for this content.