views:

2451

answers:

28

I'm the only programmer at work. A result of downsizing, I have to work on programs that have been created/maintained by many different past programmers. When I look at the code in some of them, I shudder to think that I worked with these people and they produced code like that. Now if I sound big headed and demeaning, well, I'm trying not to, but one would think that a programmer claiming 20 years of experience would write half-way decent code. Code that meets a minimum of standards.

What bothers me, is that I think other people's code really sucks. Am I a good judge of other people's code? I suppose I have been in the trenches long enough to judge.

The funny part is, I am almost always able to modify their code to do what I need, albeit, if the code were structured more correctly, it would be easier and less time consuming, but the fact is that I can modify the ugly, nasty, good for nothing code to do what I want.

Perhaps that says something about my ability as coder, or perhaps it says something about code in general.

At any rate, I still have that little voice within me saying, "if only they would have done it this way or structured it that way, I wouldn't be spending all of this time figuring this stuff out."

Is that attitude/thinking wrong? How do you rid yourself of that way of thinking?

+44  A: 

A good way to rid yourself of that thought is to realize that the other person probably would think the same way about your code, if they were in your shoes.

Everyone can make better sense of the code they've written themselves, than code that was written by someone else.

Pride yourself on the fact that you can puzzle out someone else's code.

Moose
Nice answer. I agree that I need my code judged more often.
These answers win on SO because they perpetuate the question -- here it assumes everyone's *does* indeed suck. In other words, some *groups* of people's code is readable and doesn't suck. That should be answered.
ashawley
I didn't say the code sucked. I said other people may feel the same way about your code. It's a perception problem, not a code quality problem.
Moose
Agreed with Moose here
andy
@ashawley - Interesting. Not to start another conversation, but what makes those groups of peoples code readable? Is it really just perception? Has a study every been done ATL where 100 programmers are given several different ~2000 line programs, asked to modify them and rate their modifiability?
@neodymium I don't think you will find a study. That said, it just take to have worked with one well crafter code base written by other people, to know you weren't so wrong - added an answer. Btw, you have to agree that it is easier/harder to work with some specific code bases.
eglasius
Some people's code does suck, but it's definitely easier to write code than to read code. Without a common sense of standards and collegiality, code bases can be fragmented and not very interoperable very quickly.
James Thompson
"Perception", eh? I'm sorry, but the OP may be correct that some code is not readable, and could be better. Saying, "Your code sucks in other people's eyes, too", ignores the story on why bad code exists. James Thompson's last point is cogent. We should learn from mistakes.
ashawley
I agree with the OP that some code is not readable, and I agree with you that we should always learn from mistakes, including others'. Realistically, I can't change how other people code, I can only change my perception of their code. Life's too short to get bent out of shape about this. Breathe.
Moose
I had never suggested shape bending.
ashawley
Now if it's benders you're talking about, that's something I can get motivated for.
Moose
+3  A: 

By educating others and introducing them to better * ways of tackling problems.

*better dressed up as alternate

Russ Cam
+39  A: 

It's not a problem as long as you also understand that your code sucks.

Yes it does.

recursive
+1 because my code sucks.
geofftnz
Some of *my* code sucks and blows at the same time. Beat that!
paxdiablo
Haha so true. If you don't see the bugs in your own code its because you haven't tested it enough.
ldog
+19  A: 

I would say it is a matter of maturity and job satisfaction. Like you yourself, previous programmers were learning as they go, under deadlines, or maybe just lazy on a sunny July afternoon. It happens. You can whine and frown and hate it, or you can accept it and start enjoying your job just a little bit more. And maybe work to institute standards that would make it easier for future programmers on the project to write better code.

nice answer joe !
Al pacino
+1 sunny July afternoon, I know I fall under that one.
ldog
+31  A: 

Look at some of your code circa two years ago.

chaos
I have the inverse problem where at I look at code that old and go 'Wow, this is so clean and simple! Why does my code suck so much more *NOW* '
Kent Fredric
Sure it could be crap, but do you fix it? Most people won't or don't care enough to know it's crap code.
rball
This is exactly what I wanted to say. Sometimes I curse the author of a particular piece of code before realizing that the author was myself!
James Thompson
BT, DT. There's a project I work on that I first started contributing to in 1993. You should hear the things I say about me sometimes.
chaos
+1  A: 

Most of the time, you just bridle at the code being different to how you would have done it. It's rare that it's anyway near as bad as you think it is.

Travis
No, it really is that bad. I never mind different, especially when it teaches me something new.
rball
+9  A: 

Yes you may find other people's code sucks, and yes you might be right, from your reasoned approach I think you propbably are. So embrace that, there's nothing wrong with finding problems and fixing them, I'd suggest moving forward with a couple of positive thoughts.

1) Just because their code was rubbish, does not make them rubbish people.

2) It was your good fortune to be the eagle surrounded by chickens, you're the one left when all others have been re-trenched - that's a pretty good place to be, or would you rather be looking for work?

3) Your final point "...I wouldn't be spending all of this time figuring this stuff out..." - that's your job, if it was easy someone costing half the money would be doing it. When IT gets hard, remember that's why we're well paid.

MrTelly
+3  A: 

Take a look at this article by Joel

Also, as an exercise, force yourself to list (mentally, or on paper) why you believe the code "sucks".

  • Does it use different coding conventions?
  • Does it have a lot of "whiskers"?
  • Is there significant duplication?

Sometimes it’s the code that sucks, but sometimes the problem domain "sucks" - it’s really complicated and inconsistent.

Mo Flanagan
This is also my sentiment. I would go further however; mimick the coding style until you can give clear justification why the coding style is incorrect.
SmokingRope
Then stay late fixing it.
SmokingRope
+1  A: 

Humility: "It's what you learn after you know it all that counts."

Attributed to Harry S. Truman

Gordon Mackie JoanMiro
+1  A: 

Yes, yours, and mine, code sucks a little to other developers.

As a programmer, one always starts with good intentions of clean simple code, but eventually one becomes slightly constrained in the internal coherency of their personal logic...

andy
+9  A: 

It's within yourself to adjust your attitude - just make a decision to accept the way things are and simply get on with the job. And I mean really acccept it, not just tolerate it.

You seem to be blaming the other developers for writing poor code... dude, you worked with them - why did you not know what sort of code they were writing??

The real problem happened long ago. Where was your coding standard? Where was your code reviews? Where was the quality control?

It's not the code that sucks, it's your software development practices.

You were part of this failure. Rather than point the finger at people who no longer work with you, realise that you were indeed part of the problem, so you can be part of the solution. Make your attitude positive - strive to improve the code base and don't dwell on how it got into that state in the first place as you can't change that. Stop playing the victim and start being a good software engineer.

I'm sure you could find a consultant who could come in once a month and do code reviews with you, or mentor you in the ways of good software development. If you need it, tell your boss and make it happen.

Daniel Paull
"why didn't you know what code they were writing?" -- Sometimes you never get to see other's code, sometimes the programming "team" work as individuals.
Assembler
dude, quote me properly: "why did you not know what *sort* of code they were writing.
Daniel Paull
+22  A: 

Stay on a project long enough to you reach the point where you say "What idiot wrote this code?!" and then you look back through the source history to find it was you.

Daniel Auger
+1 Wish I could upvote this again. :)
Dusty
I'd say if this doesn't happen, you're not improving fast enough :)
Jeff Davis
+1  A: 

Assume that, somehow, your own code still sucks and you still can learn from others. This is not to say that some other peoples code doesn't suck, but I can assure you

  1. You're not perfect
  2. There are people better than you

I'd even tell that to Jon Skeet (from inside a very large glass house though)

johnc
+2  A: 

You need to go back to the basics. Back to 1970 to be exact.

There is a chapter in "The Psychology of Programming" which talked about the history of a piece of code.

Yes some code is hard to work with, yes it is sometimes because of the skill of the original programmer, and sometimes because of programming process.

Sometimes, though it is because of the history of the program.

Some original constraint forced the program to take an unusual turn, and subsequent modifications didn't make it better, but only made it worse.

this situation is the mark of a poor programmer. leave things tidier than you found them.
Tim Williscroft
+2  A: 

Remember that in our field we are all continually learning/improving. That said I don't think you can say that about all other people's code.

If you have looked/worked with lots of other people's code, there is the rare code base that you look and feel really well about it. Most likely it can be improved, but you can tell its well crafted software.

I am sure that even with your own code, you will have projects that you feel good about and ones that you don't. The type of experiences each person brings is an important factor, but also mistakes can come into play.

Keep learning and understanding how you can get better code and how you can explain that to others. Keep working with other code bases, if you think all the code you have access to is like that, look at open source projects. You will surely gain some skills/understanding that will make you look back and remember that you were also (and still are) on the path of learning.

That said, there are lots of really ugly code out there. Always improve the code you are working with at least a bit (just a little), since that continually improves the situation. You will notice this will challenge your skills for some scenarios.

eglasius
Most of the time it's open source code that's pretty nice. It's almost like the people specifically thought about how everyone was going to see it and decided to make it as clean smelling as possible.
rball
@rball I wouldn't say open source == nice code. I am sure people think it twice though :). I have seen nice private code by third parties, rare but happens :). With all the stuff going on lately in processes/practices/principles I have hope those will increase in the middle term.
eglasius
+1  A: 

Just find another coder to show you how badly your code sucks. In other words: Code Review.

Vulcan Eager
I'd love the opportunity but when the review turns into "what is a Dictionary<string, string>?" it just goes south...
rball
Ha ha. I go through the same thing almost everyday but even the guys who've never used a Dictionary have shown me places where my code sucked badly.
Vulcan Eager
+1  A: 

just remember you were once like that when you first started coding.

the real difference between you and your nasty coders is that you're learning and looking for ways to improve your coding skills. while they just don't bother too much.

tnafoo
The biggest problem I have with that is most of the people have been coding far longer than myself.
rball
Well that comes from them not caring about it like you.
Matthew Whited
+2  A: 

I think there is an "absolute" law that explains your (and our) problem: Code is more difficult to read than to write.

So, it's hard for you to work on old code written by someone else? Me too! Us too! Try now to slowly refactor that code your working on: It's a good way to appropriate ourselves an "ugly" code.

"Code is more difficult to read than to write" -- maybe like music? I think we need to study reading code?
Assembler
Unless you're a computer, that is.
Jeff Davis
+2  A: 

I honestly think my problem when I see crap code is, why did they want to make it a pain for everyone else including themselves? Then I get to thinking that either a) They didn't care to write it any better or b) they have no idea how to code. With b) I'm usually left with: who the heck hired this person, and then how can I teach them without looking like I'm teaching them. Hey, I know my code sucks, as I can tell about every 6 months when I go back to what I wrote before. My issue is, I then clean it up to be better, and they don't. This continues it seems for YEARS and we're left with a steaming pile of crap when I get hired on.

When I do encounter crap code I just start with my refactoring hat on and just go to town. I really try to clean up everything I can before I check it in. Most often, I have the extra hour or 2 it takes to get this done so I use it. If I don't have the time, I just shrug it off and try my best to not care. It's the caring about it that always gets me.

The best thing about your situation is you don't have to explain to anyone why you changed something. Sure, I'm all for teaching others, but a lot of times when you're on a group of 6 other people it's pretty daunting when they are all doing it.

I guess that last thing I'd say to you (and keep reminding myself) is that at least you care enough to strive to be better, and typically when you are "better" you are rewarded more than others. Focus more on the caring about improving your skills and use the opportunity of crap code to learn how to break dependencies, write great tests, and refactor like super-man.

rball
+6  A: 

On another note, you could think of it this way:

At a prior job, I did so well that the program had very few bugs (we'd find 1 every few months) and the code was pretty clean. 96% test coverage, and hadn't had a bug in 5 months.

Since it worked so well and didn't need someone maintaining it, I was laid off!

In other words, that crappy code you're mad at is keeping you a job. Oh the irony :P

rball
Good point! Sometimes writing really bad code makes for really good job security. No one wants to inherit an ugly beast.
ScottE
+1  A: 

Two things are there.

Craps are always craps. Throw it away. You may have better solution for the problem you're dealing with. The solution should be judged based on various parameters like performance, reliability, readability, ease for further enhancements, budget and time available etc...(which all matters)

If you feel each and every peice of code is not good, that's again problem with the attitude, I believe

There are few facts that

  1. The whole lifecycle of a project is not one man show. There are many other stake holders and programmers who should contribute to develop complete softwares. So none of these components are avoidable.

  2. All contributions should well taken and corrected by management over time.

  3. Respect other's knowledge and experience. If you've a better solution, suggest it while respecting your coworker.

  4. Realize that, no one is really smart programming computers.

  5. After reading 'Themese in Software Craftsmanship' and 'Personal Character' from Code Complete (2nd edition), lot of my perspective got changed. I'd suggest you to read taht.

  6. Jeff Atwood made a great post on - Nobody Cares What Your Code Looks Like

So as I said before, categorize a code as 'crap' only by proper judgement.

Sarath
+1  A: 

I got cured of this fairly quickly when I got told that my code sucked in a code review. :-)

Jason Baker
+1  A: 

the simplest answer is be open minded and work to help others to come to a common style somethings that may really help are

Doing Code reviews, if other people are going to see your code, you will code better and by review code and making the author explain why they did something the way it was done may give you better appreciation for what they are doing

pair programing (your basically doing on the fly code review)

Bob The Janitor
+2  A: 

Remind yourself that the existing code is often a result of evolution. That means different developers came and went, requirements were changed, enhancements added, bugs fixed, rushed schedules, hacks around the original architecture, code ported from a different app. It may have actually been well written code at one point, but simply degraded over time, the software equivalent of bit rot. The architecture, which might have been well articulated initially, might have gotten jumbled through all of this. It may not be the fault of any one developer. Code ripens itself up for some refactoring every once in awhile. That being said though, there are plenty of poor programmers too, so what you see might be some combination thereof.

no-op
+1  A: 

Experience doesn't mean much. It's a fallacy to think that having lots of experience makes someone good at anything. Lots of people slide by on personality or are only good at very specific parts of their job, and they suck at the rest. A lot of everyone else's code does suck.

The only way I could think to get over this attitude would be to take some sort of mind altering drugs on a regular basis, and then you would be as stupid as the people who's code you are reading that sucks and so you would no longer notice it sucked, but I don't recommend that.

+3  A: 

The best programmer I've ever known knew that his code sucks.

He was always mourning about how badly he had written something.

Maybe that's why he's so good.

Nosredna
+2  A: 

Often, I look at a piece of code, and ask "what idiot wrote this?" More than once, I've looked up the file history, and the answer has been "me". Remembering things like that helps keep you humble.

+1  A: 

Another thing to think about is that sometimes code was orginally written under constraints that no longer apply. What looks bad now might have been the only way at the time to get the thing to work. But you have better hardware now or a newer framework with cool new features or a database that supports some better ways for handling oh say recursion that weren't available in 1997 when the orginal code was written. Sometimes the constraints aren't even things you can know about at a later time like the time someone had to put this together on Friday afternoon to meet a deadline when they didn't give him the requirements until two hours before the deadline but wouldn't move the deadline. Or maybe he had a requirement that was ridiculous but for political reasons (i.e., it came from the CEO's girlfriend to pick a not so random example) was stuck with that made the system cludgier than it needed to be. You are likely judging without knowing all the pertinent facts.

HLGEM