Ask Slashdot: How Can I Explain To a Coworker That He Writes Bad Code?
An anonymous reader writes "I have a coworker who, despite being very smart, and even very knowledgeable about software, writes the most horrible code imaginable. Entire programs are stuffed into single functions, artificially stretched thanks to relentless repetition; variable and class names so uninformative as to make grown men weep; basic language features ignored, when they could make everything shorter and more readable; and OOP abuse so sick and twisted that it may be considered a war crime. Of course, being a very smart person who has been programming since before I was born makes him fairly impervious to criticism, so even a simple 'Do you see how much better this function is when written this way?' is hopeless. How can I make him see the light, realize the truth, and be able to tell good code from bad?"
Unless he's making your own job a lot harder or you're his boss (or project manager), it's not your place. Your "help" will likely only piss him off more and more and cause problems in the office. Not only will it in *no way* benefit you, but it will very likely *hurt* you and your career--since your manager will come to view you as a source of headaches, your co-worker(s) will view you as a pretentious little prick, and (contrary to popular belief) the guy who helps produce better overall product is almost never rewarded for it anyway. About the fastest way for anyone to piss off their co-workers and bosses is to walk around with a "I'm the best coder here" attitude all day, whether it's true or not. Don't do it.
So, STFU and let management deal with him (or not). That's what they're paid for, not you. Don't offer *any* unsolicited criticism, and even if solicited, offer only a few minor criticisms at a time.
In short: Lighten up, Francis.
What political party do you join when you don't like Bible-thumpers *or* hippies?
Fire him
When the foot seeks the place of the head, the line is crossed. Know your place. Keep your place. Be a shoe.
I GET IT!!! My code sucks. You have made this clear. You don't have to start posting on forums you know I read. Sheesh....
There's a reason why he's a seasoned programmer and still has a job. Think about it. Who else can maintain that cluster fsck? No one, that's who.
If Bad Code did not exist it would be necessary for Good Coders to create it.
TL;DR: job security
Since programmers must maintain code, read it, understand it, and write more than work with the existing code, the top priority of code is to be well written, and easy to understand for humans. You maybe can help him take ideas how to make his code better for other programmers.
-Woof woof woof!
People are very proud of their work, and do not take criticism well. One way is to ask for his advice on your work. In reviewing it, he may pick up some of your ideas and implement them. Be tactful.
our SQL devs write the longest most headache inducing code and never listen to reason. and they use the most evil invention ever, temporary tables. when there is no reason to
Leave him an anonymous poem:
Roses are red,
Violets are blue;
The C obfuscation contest produces bad code,
And so do you.
When did /. become Dr. Phil for nerds?
You haven't made it clear here if you're talking about Bill Gates or Linus Torvalds. Either way, you're got more moxie than anyone I know. Good luck with your new career outside of information technology. :-)
conduct code reviews here is a good tool http://www.atlassian.com/software/crucible/overview , although it is not necessary to use a tool.
And hire a new one who hasn't been stuck in their misguided ways for decades.
Require that code be run through code analysis and compliance tools that look for the basic things, like function naming, function decomposition, pointer use and other pitfalls.
Then when code reviews come around, you have data instead of arguments and suggestion. "You've got 500 warnings from the code compliance tool. Clean them up before bringing the code to code review."
I should use this sig to advertise my book ISBN-13 : 978-1501515132.
He'll sleep all day and stop coding. Problem solved. http://dilbert.com/strips/comic/2003-06-19/?CmtOrder=Rating&CmtDir=DESC
That's what code reviews are for. They aren't to berate someone for writing bad code but identifying as a team areas for improvement (of the code, not the developer).
If you notice a lot of repetition, suggest refactoring common code into a function. Suggest renaming poorly named constructs. Code reviews should be a team effort with backing and consensus of the team with a focus on code quality and not any one developer's ability (or lack thereof).
Ascalante: Your bride is over 3,000 years old.
Kull: She told me she was 19!
Run his code through a static analysis tool with default, or best practice, settings, and then have him explain why the detected problems are false positives.
The best way for people to learn that their code sucks is to have a 3rd, impartial, party tell them. Static code analysis tools are the best, because they have no ears.
Telling them directly their code sucks is the worst way.
If the code really sucks, it'll either teach him why it's bad code, or it'll bog him down enough that he doesn't have time to write new bad code.
If the code's working ... then you don't have to look at it. (but he still has time to write more)
Build it, and they will come^Hplain.
For example, you tell him his code code not functional or elegant, and then, you ask him what he thinks about that.
And then you write the goddamn login page yourself.
Instead of criticizing him, say "I'm really struggling to read your code, could you do x y z to make it easier for me to understand? Thanks".
You'll find way to the explain it to him right next to the section with answers to questions from the wife, such as "does this make me look fat?"
Make code reviews mandatory for everyone. If he can't deal with that, he knows where the door is. On my team we use git, and contributors are not allowed to push their own code to the main branch. They must submit a pull request which gets reviewed and pulled by another member of the team.
Find other job with good programmers, if not when you want, when you can.
Dude, your code sucks!
Get the hint? He's talking about you, or maybe me.
Take things one at a time. And learn how he likes to learn.
If he learns through books, loan him a copy of Code Complete.
If he learns by doing, show him that factoring out repeated parts of his code makes his code less buggy and easier to maintain.
If he learns by other people's mistakes, then give him some code of yours 'to review' with one oy his big mistakes. Ask him if there's a better way to do things, and see if he realizes the mistake in others.
And if none of those ideas work, use his code to summon Baalzebub.
Why don't you convince him to start using deodorant, shave his neckbeard, and start dating a supermodel?
You say you ask him whether he can tell that your code is better, but it sounds like he can't.
Maybe you should ask him WHY he coded a function the way he did (maybe he has a good reason). Depending on the answer, explain WHY you think your way is better.
It's easy. You do what a professor of mine did.
"Dude... Your code is horrible. Yes it works but nobody know how the fsck it works. Here's a book on writing effective comments and coding conventions (sorry can't remember the name of the book)."
Now I know your not in a school environment but as his boss you need to explain to him that the code has to be readable by others. This is his first verbal warning. Give him a book on writing readable code and comments. Give him a couple of months to clean up his current code. If nothing happens then give him his first written warning. If nothing happens then the second written warning. Finally if he's still hasn't quit and still hasn't cleaned up his act give him his walking papers. Where I am you just need to give 1 verbal and two written warnings and show how you tried to help get the employee on track then you can fire them and not have to pay severance.
Pair Programming might help by showing him other approaches. Just be sure to man the keyboard more often than not.
To worker: "You write bad code."
See, by choosing the right language for the problem, the solution was very simple. And I did it with just four keywords plus one terminator!
Simply get a group of tough guys together, wait for him after work, drag him into an alley and make him understand. Works every time.
Pretty good is actually pretty bad.
What happened to you? You used to talk about REAL problems before...
Post his code to the DailyWTF then send him the URL
For example, nothing was said about GOTOs being liberally sprinkled throughout the code. If he's working in a non-optimal language that doesn't support GOTO, he should try hacking in the functionality with preprocessor defines. Maybe even hack in a preprocessor if the language designer forgot one, or add another preprocessor if not. With a few stacked preprocessors one can even write his own (better) computer language, and what seasoned programmer doesn't aspire to have one or two of those under his belt?
Try not. Do or do not, there is no try.
-- Dr. Spock, stardate 2822-3.
You double-down. You take two-year old code that he's writted, and you ask him to walk you through it today. If he can, at reasonable speed with reasonable prep, you lose and you'd better start learning to read his code which conclusively isn't bad it's just different.
it wastes your time and annoys the pig.
You said he's older than you, so if you're planning to stay with your current employer, just wait for the bad coder to retire. You won't be able to help him, it isn't worth trying really. You might well cause yourself a fair bit of harm by even trying to resolve the problem.
Damn_registrars has no butt-hole. Damn_registrars has no use for a butt-hole.
Ask him to explain the code.
That will not be easy for him and should show him why coding standards are important.
Seriously that is how I started writing good code. If it was code he hasn't looked at in years it works best as then he has to suffer through his own problems and wondering what the hell is going oin. I learned this very early on when I was still in school and was trying to create my own game on the side that I would work on periodically. After dealing with some of my own early garbage code (piss poor names, no documentation, shit structure) I learned real quick to make my own life easier and write better code. I know I write better code now than I did then and am always trying to be better.
Time to offend someone
With his lack of skills, he'll either be out the door or in management before too long.
The world's burning. Moped Jesus spotted on I50. Details at 11.
Do a code in his style, and ask him to maintain it, specially doing changes where that way of programming show why its wrong.
Sit next to him, and code together. Don't forget to let him have the keyboard. Even if he makes mistakes, it gives him the opportunity to practice (and you have a chance to refactor his code when it's your turn to have the keyboard). If he's really smart, there is a chance he's willing to learn. Don't give up on him.
Coding Standards and Code Reviews. Then you'll have some more process in place that he won't care about. From previous experience they'll probably all get waived in favor of the almighty deadline anyways!
Yeah yeah... I know the horrors of maintaining somebody else's junk code... but what coder hasn't left behind them a trail of woe and destruction? Also, have you ever considered that it might be you? It sounds like more of a potential ego problem than a who is doing it write. Sure the code may suck to maintain, but if the guy is hitting deadlines and the sky isn't falling (until the maintenance crew touches it)... well who's to say who is write or wrong? Unless you get management to sign off on a specific plan, or can explain why OO is better than monolithic scripts... you're not going to have any way to show this or that.
At any rate... rewriting something that works (even poorly) is a massive undertaking... and you'll be fighting a losing battle of playing catch up. Unless you really like coding a lot, and overtime even more you should really consider if it really is worth the fight for you. I worked at a place that I convinced management to convert from procedural code to object code, and even with full backing everything went to hell over two years... and guess what the old system was still functional while the development team went of to write code for new features of the system because they wanted to solve interesting problems and not port code over that solved current problems we needed.
What you really should be focussing on is how do you put yourself into a position to write 'beautiful' code so that everybody else has to be stuck maintaining your code.
This space for sale
Make him maintain the code. That's how I learned to write code that's easier to work with.
I went to eat some animal crackers and the box said, "Do not eat if seal is broken." I opened the box and sure enough..
Didn't Linus set an example just a few days back?
Simply get a group of tough guys together, wait for him after work, drag him into an alley and make him understand. Works every time.
I was thinking mafia style. Take part of the fingers till he gets the picture. It might make a few fingers shorter, but sooner or later he'll figure it out or quit.
Be seeing you...
To me, writing code is about expressing and organizing thought processes. Actually, so is the spoken and written language. To improve one's ability to think, improving the use of all language, written, spoken or even programming will invariably improve the process of analyzing and understanding things which fit within those frameworks.
But also, the way people speak, write and code also reflects their current thought processes. A person may or may not be open to such new ideas. Telling a person who speaks "ebonics" about this notion will not likely result in their improved use of English and will not likely result in thought or behavioral improvements. (I know, I have tried... I once attempted to correct someone saying "aks" instead of "ask" and they just hated me for it.) It would also be true of improving coding styles. A person who would be open to such improvements would already be aware of his weaknesses and address them through observation of other peoples' code examples. They wouldn't have to be told. And even if they did, they wouldn't require more than a slight nudge.
Some people want to improve themselves and others believe they are good enough or are simply already the best. There is no hope for the others.
whats it to you?
Get all of the developers in a room and have them stand in a line. Then ask all the developers who develop good code to step back one step, then proceed to tell the suspect "not so fast".
He might have inherited that mess and it might be so brittle that the correct way to maintain it is with minimum changes while replacing.
Of course management usually nixes the replacing part and you wind up just doing the minimum changes part.
If he is making new messes you need him assigned to maintaining an old mess.
Also one part of your post bothers me:
Shorter can be less readable. For example C++ Template abuse. I once maintained a program written by a dude that was learning C++. He used every language feature as a learning exercise. Function overloading for no reason. etc
John McAfee 'It was like that time I hired that Bangkok prostitute; to do my taxes, while I fucked my accountant'
Assuming he reads Slashdot, I think you've already figured this out.
Kwisatz Haderach
Sell the spice to CHOAM
This Mahdi took Shaddam's Throne
And send him the link.
I eat only the real part of complex carbohydrates.
Describe the issues to your supervisor in terms of extra time and difficulty to maintain, and/or poor performance and production bugs/issues. If the code works well enough and nobody has to maintain it, then management wont care. It becomes a simple matter of how much you care about the "sanctity of code." Back to the question... Rewrite a portion of the code to show how much better it can be.
make him document it!
Why not post a representative sample to TheDailyWTF, and when it shows up, call him over with: "hey, come take a look at this shitty code someone posted, how could anyone write something this awfu... wait, isn't this yours??"
Have you tried telling him that his code is as painful to go through as running naked backwards through a corn field? Honesty is always the best policy.
How long have you been working on the code? I was convinced my boss's code was total garbage for a year until I started reimplementing it 'my' way to find that alternatives were worse, now I mirror his style closely and am producing the results I need much faster than I could otherwise.
"Your code makes my eyes bleed."
All submits should start with a score of 100 and should be able to slip into negative infinity.
Your coding standards should be written in such a way that they can be difficult to understand and abused for your own purposes. Always allow for exceptions to any rule, but that they have to be allowed by a select few (only yourself if possible).
You should use things like poor comments to beat people over the head to show them how much smarter you are as well as deduct points.
Don't actually give out the coding standards or code review documentation to anybody, make sure that you make a power point presentation that 'dumbs it down' for everybody, this will make them feel better about the doing the reviews but still allow you to nit pick over every little detail.
Remember to ensure that your submits come in from 90-100, so that you can beat everybody else out but still show improvement from time to time.
Finally, you should always wait until the last minute to do any code reviews and enforce standards, this way you can ensure that you really only review the people who you want to chastise with a lower chance of repercussion from others reviewing your own code.
P.S. also ensure that you promote people committing directly to trunk and causing the most amount of breakage possible, that way you can deduct points from their code review because you should have a note that for each code breakage infraction they lose points.
This space for sale
I perform lots of testing on my team and the ones that code well can usually find the reported bugs and fix them fairly quickly unless the logic of the code is extremely complex. But, by having another team member debug your code, the sheer amount of vocal bitching at shitty coding standards will begin to give the bad coder a clue. It will probably float up to management which will either push the employee to training, start following standards, or show the bad coder the door.
Life takes interesting turns, but the most interest is when you're off the beaten path.
If you can't explain to him why your code is so much better than his, and your argument boils down to something like "it just is" or "it's common sense" or something, then your method may not be nearly as great as you think. Your example of "Do you see how much better this function is when written this way" means nothing if you can't actually elaborate on why it's much better. Is it simply easier for you to read? Is it more efficient? Is it more secure?
A better approach would be to simply ask him why he codes the way he does. Bring up a particularly "bad" example of his work and just ask him about it. Maybe there's actually a reason you hadn't considered before. Or maybe he'll tell you why, and you can constructively offer an alternative method to see what he thinks. It's very possible he's just stuck in his old ways of coding, which is a situation you'll probably find yourself in sooner or later, but it's also possible there's a reason. Simply accusing him of bad coding practices means you'll never know.
BZZZT! Answer was not in the form of a HOSTS file update.
And send it to Slashdot for him to read, then again, your the one that's having problems reading his code so maybe your stuck in a mode of trying to get everything perfect! *har*
Good leaders run toward problems, bad leaders hide from them.
Take code he wrote 6 months ago and ask him to explain what it does. If he can't do so in under 10 minutes it should be obvious his code is poorly written and not maintainable. Or, just list all the bugs associated with his code base he has had to fix over the last 6 months.
It seems its a recurring theme that every software firm has a smart ass that assumes he knows everything but writes code that even a junior code monkey fresh out of diapers wouldn't write.
Let me guess, this same guy is advocating coding style that matches his style rather then adopting more widely utilized coding standards.
I haven't thought of anything clever to put here, but then again most of you haven't either.
This is what Slashdot is. if you don't like it, go elsewhere. I'm tired of people going on about why something is on Slashdot, obviously the 100's of comments suggest this is the kind of content people want to read and write about on Slashdot.
Also don't be that guy that defends a bad developer by using your own poor coding habits as an example.
I haven't thought of anything clever to put here, but then again most of you haven't either.
Yeah. My boss was that bad.
For those who seek perfection there can be no rest on this side of the grave.
That type of coding is a result of management encouraging speed and something that "just works" over maintainability. It could be argued that he "could" be faster and have less bugs if coded more conventionally but not without extra education on his part (violating the speed objective).
The only argument you can likely make (unless his code just doesn't work) is the maintainability one. If management doesn't go for it then they actively don't care about maintainability as much and as offensive as that might be to you as an engineer it is their choice to go down that route.
Overtime your style will win out if it truly is the superior choice for their needs. The parts that you coded versus his should be easier to refactor, debug and have less general issues overall. If this is not the case then your assumption that your style of code is better than his may be wrong (at least in terms of the company's needs).
10 PRINT "Your code sucks."
20 GOTO 10
Have gnu, will travel.
...the book Code Complete
Take something he wrote several months ago, that he's not likely to have on the top of his brain. Then ask him to debug, add to, modify or analyze his own code. Or just ask him to give you an explanation of how it works. It might dawn on him that his own code is unreadable and hard to maintain, if you do it right.
I'd also push back on your manager, to make it policy that until this guy gets his code in shape, he is the one who has to maintain it. Bad code is bad even to those who wrote it. Make him work on his own code.
Since I'm arrogant like that guy and sometimes write less than beautiful code, I bet what works on me would work on him. He won't change radically overnight, but you can affect change without drama. .... . D you think I should break this function into two, maybe buildSpreadsheet() and saveSpreadSheet()?
Would that be better, it terms of "Functions should be short and sweet, and do just one thing", do you think?
Two days later you ask him to look at your variable names and tell you if he can tell what each is for, or if he thinks you should rename any of them to make it more clear. He's helping you to make sure your code is readable and clear.
Work with, not against, his personality. He thinks he's the smartest guy around. So go with that. He's your new mentor. A few times a week, ask him about YOUR code. Say something like:
Can you look at this function I'm writing, please? Linus Torvalds says that "Functions should be short and sweet, and do just one thing, and they should have more than 5-7 local variables." The Microsoft guidelines say
Ask him if you should make the thingRetriever a separate object from the stuffDisplay in your code. He'll likely eat it right up and never realize that he's actually getting a two minute lecture on a different aspect of code quality each day. If he starts out the day thinking about these things, he'll soon notice when he's writing garbage and his ego won't let him keep putting out garbage for long once he's aware of it.
If, after a month, you see zero improvement in his new code, then ask polite, direct questions about his code as needed. "I'm working on Foo(), what is the "bob" variable?" "Hey John, what does is this function called tp() supposed to do?" (My predecessor actually used "bob" as the name of at least one variable in each project.) Those questions make it explicitly clear that his code is unreadable, so do this only after you've kissed his butt in step #1 for best results.
Or better yet use reverse indentation.
Do not look at laser with remaining good eye.
Unless you are the one paying this guy it ain't your problem dude.
I think slashdot has a post about you.
Your pizza just the way you ought to have it.
Fire him.
Did you miss the descriptive word "coworker" in the parent post ---
or the even more telling phrase "a very smart person who has been programming since before I was born?
This is the new kid on the block.
He is not the boss.
If not, then he must be his brother....
I take no responsibility for what I say. Even though I'm never wrong
If your coworker is actually really smart and experienced, maybe he has a good reason to do things his way and you're just not seeing it? Maybe he could explain that reason behind his naming convention and avoiding certain features and it would make more sense? I had a couple of interesting talks on similar topics with older programmers in our team (I'm a newbie) where they actually convinced me on most points why their style and policy to avoid certiain "fancy" language features and practices was more error-prone and readable after a while of working on the project.
And that shows that you're a shitty programmer.
If you're gut reaction to criticism, constructive or otherwise, is to behave like a 12 year old, you are a shitty programmer.
I totally agree. But we already know the guy in question is a shitty programmer. So then it would be PRETTY DAMN STUPID to give a book to someone to prove what we already know, an alienate a powerful person in the company to boot.
If someone is not reading books already on how to be a better coder there is nothing you can give them that will help, and anything you do very likely will make things bad for everyone.
"There is more worth loving than we have strength to love." - Brian Jay Stanley
It depends upon the person of course, however if he's not able to learn from the feedback you're giving him it's possible that his brain might not be wired that way. In my experience (as a lead developer and lead architect) I've found developers usually sit somewhere on the spectrum between implementationists (nuts and bolts programmers) and designers (big picture programmers); and every now and then you get someone who is just so far to one end or the other it's hard for them to see, for instance, why code needs to be elegant when it's already working (or vice versa why sometimes the performance cost of a perfect design doesn't pan out).
:-)
If you think this might be the case, it doesn't mean he needs to be fired or kicked off the team though. You just have to focus on using his abilities where he's strongest (e.g. low level code, or when you need to *get the job done now, future consequences be damned*). There will be times when something that seems obvious just isn't going to make sense to someone else, and in those instances I find it's best to think of the each team member the way I might when playing an rpg; while a dwarven warrior won't have the finesse of an elven mage, sometimes it's just the kind of character you need.
s/more error-prone/less error-prone
The only way to handle sensitive issues like this is to have standards in place to begin with. Configuration Management including coding standards and honest peer reviews. If the developer didn't follow standards, he fails his peer review. It doesn't even have to be personal. Not "Your code is horrible, fix it.", it's "We need code written this way to comply, please fix". It gives you a leg to stand on rather than dramatic phrases like "Your code is like a war crime".
Instead of criticizing the code he writes, do a training exercise where a group goes through bad code that someone not (currently) working at the company wrote, and have people who write good code point out the flaws. The idea is that this way, you've taken his ego out of the equation, but still showing him the difference between good and bad code.
I am officially gone from
Patch or hack the compiler to detect his coding style and generate plausible sounding error messages.
You suck at coding bro. Every consider a job in the fast food or hospitality industries?
* Carthago Delenda Est *
There's really nothing you can do about this that has a good chance of a positive outcome, since no one likes criticism and managers don't really like to find out about yet one more problem they've got to deal with. Because in this case you're criticizing their management practices for allowing this to go on.
I've seen some suggestions here of books to read or to give to coworker to read. I, too, will make a reading suggestion, but a very short one:
"To a Louse"
After this, you can wonder just what annoying trait you might have that annoys your coworker, and take some comfort in that. Or something.
I am not a crackpot.
And louder.
If he's been around that long, chances are that he started his career writing assembly or something nearly as low-level. That's why he writes everything in one big function --even procedural programming is a "new" paradigm that he's only half-comfortable with. Expecting him to fully utilize OOP language features and best practices is just unrealistic.
It's kind of like natural languages; even after years of speaking a new language, some folks never achieve true fluency because they can never get away from thinking in their native tongue. This guy is like that; he'll probably never be able to do more than write assembly-style programs in a procedural or OO language wrapper.
The best thing to do with old dogs like this is to give them their own little niche where they write their ancient code in peace, without bothering anyone else (or being bothered). Maybe something low-level (as in close to the computing hardware), or an older product line or obscure technology area where his ancient knowledge might be of some use. And preferably something self-contained where no one else will have to interact directly with his source code on a regular basis.
Give me his email address.
He is creating job security for himself since only he can maintain his code... You, who write perfect code, can be replaced.
Might be too late to teach the old dog new tricks.
There's only three kinds of code:
Code that works:
Code that's documented:
Code that was written quickly and cost-effectively:
Chose two:
Pay for one:
If the three items above are not part of the problem, then maybe the issue isn't the code. Maybe it's the user interface that is associated with the code.
I cringe whenever I click an item and a screen comes up that requires me to move the move pointer to a completely different part of the screen and click again in order to continue. Insane!
Ever notice that a so-called professional user-interface developer will know everything about the code and the computer part of the interface but know absolutely nothing about anatomy or the human body aspect of the user-interface? Are retards still writing mouse code that doesn't allow the mouse wheel to scroll the mouse cursor to all the clickable options in the message text box?
Thag: "Grog, I have to tell you something about Dag."
Grog: "What is it?"
Thag: "He is a terrible flint knapper. The absolute worst. His flints are all crooked, half the time they're broken, he's just awful!"
Grog: "Have you told him this?"
Thag: "Of course, but he is impervious to criticism!"
Grog: "It is part of the human condition. By the way, you're not so great at this yourself. Just saying."
Thag: "You mean the ones who are the most vocal about others' lousy work are often guilty themselves?"
Grog: "Yep. 'He who smelt it dealt it'."
Thag: "Screw you. I'm going to talk to a zillion people about this who have never actually seen my work. I'll bet they are more sympathetic."
Of course, you could always wait until he retires.
I know it's kind of a waste of time, but most programmers recognize portions of code they have worked on and will notice when the code has changed. If you consistently refactor his code in to something significantly more readable with fewer lines, it is likely he will notice the change and see your patterns and follow suit. If he doesn't follow suit, he will probably complain to management and then you can properly defend yourself when he's the one instigating the conversation.
I had a semi-junior developer from India that was overall a good coder but did some really bad things at times. As his team lead, I tried the direct approach but he just argued to my face that he was right and had been doing it that way all along and that it was no big deal.
Instead of continuing to argue with him, I just showed him The Daily WTF and laughed with him about how stupid some of these coders were. I told him that I read it every day to laugh at bad coders, as a form of therapy. After about a year, his coding had improved dramatically.
Peter predicted that you would "deliberately forget" creation 2000 years ago...
Lead by Example.
Just tell him straight out that his code is impossible to read. Follow it by explaining why its hard to understand and ask him to make it human readable and understandable. Give examples, preferably from an authoritative source such as a textbook, of ways that he can change his code.
If he can't (I don't know how to write it any other way!) or won't (I can read it just fine!) then fire him, with justification that his code is impossible to maintain and he's causing the company to lose money in the time it takes to maintain his code.
Either way, your company is going to be in the lurch when the guy leaves and the only documentation left is his shitty legacy code. Better to cut him loose now and replace his bad code with good code.
I always wonder when these types of questions come along... Who is really the bad coder? The "Coworker", or the person that thinks the coworker is a bad coder? Face it, most "bad coders" think they are good... and there are actually few "good coders" in most groups.
More importantly: most programmers actually want to write good code, but at the end of the day it's really about cost effectiveness. In some cases this might mean you whip up the crappiest POS code you can to get the job done, and in other cases it's all about quality and maintainability. I wish more programmers understood this.
Regardless, if you are not management - either STFU or bring it up with someone who is a manager.
Also, are you sure that his code is that terrible? It's always possible you just don't understand his way of thinking. Maybe ask him why he wrote something a certain way and go from there.
First off, the poster is wrong, his coworker doesn't write the most horrible code ever. Because I work with the guy who does that. He is the worst fucking coder I have ever seen. He learned hobby level coding skills sometime around 1992 in visual basic, and he is still coding the same way. The sad thing is, his boss knows he sucks and won't fire him, so every year the code base gets more and more fucked up.
I have worked with a lot of coders over the years, and there is such thing as stylistic choices when it comes to coding, and this isn't the same thing as writing bad code. I have worked with a few great coders that had style that drove me up the wall. Although I might dislike their style of doing things, I would be the first to say they are top notch coders because their code was elegant, simple, robust, extensible, scalable, etc. This is not the case with bad coders.
I'm going to go with the OP on this one and say that it probably is just a lousy coder, and not a misunderstood savant or something. Odds favor the guy just sucking...
HA! I just wasted some of your bandwidth with a frivolous sig!
At one shop we had code walk-throughs. They specifically not termed "code-walkons,"
Several programmers --- no managers --- would schedule a conference to review and comment on code.
These walk-throughs were a good idea --- the coder wasn't attacked by one person; others were (probably) more tactful than yours truly.
I learned a lot of respect for my co-workers, not to mention new ways of doing things.
Official Pi Ambassador -- inquire for details!
Chances are your code sucks just as bad.
Organize a weekly book club where you read a chapter from a book like "Code Complete" or "The Pragmatic Programmer" and everyone talks about the chapter together for an hour and relate it to current practices on the team. Get your manager to splash out for pizza and beer or peanut butter and chocolate (or both). This allows everyone to think that they have formulated their own ideas instead of having to deal with the defensiveness that is associated with (even constructive) criticism. You may also find yourself learning things that you thought you should already know.
Everyone on your team will get better including yourself.
But... It can be done.
Start with a general discussion about how you might standardise code so that it's easier to switch between areas as a team. Little things like naming conventions and code formatting. If you can't get buy in to that then abandon ship.
Otherwise, introduce tools to start enforcing those rules. Hey let him decide what most of them are.
After this hopefully you have broken the barrier of being able to speak about each others code and you've planted a seed in his head that a bit of formalisation isn't a bad thing.
Rince & repeat upping it a notch each time.
How can I explain to a coworker that he writes bad code?
It depends. Are you his/her supervisor? Did the coworker ask for your opinion or advice? If you cannot answer "Yes" to at least one of those questions, then you really should examine your own motivation as to why you feel you must explain to the coworker anything at all. Now, on the other hand, if the coworker's coding is impacting your work, then your recourse is to discuss it with your supervisor. Taking the matter into your own hands, particularly without approval from your supervisor will most likely get you branded as a trouble maker and have negative repercussions for you, while doing nothing to improve the coworker's code.
Programmers with poor programming skills usually get additional training. Programmers labelled as having a poor attitude usually get replaced.
Gently bop his snout with a rolled up newspaper and then rub his face in it.
Bad programmer! Bad! No coffee for you!
Man, you sure don't see this kind of attitude in a small company. You can only get away with it in an environment large enough for people to hide. Like aerospace! Or academia. I can assure you that this is exactly the kind of thing managers dread: employees intimidating each other out of peer review. As a rule, MANAGERS DON'T REVIEW CODE. Mangers review PROGRESS. If progress sucks, they will try and figure out what's wrong. But if they're not reviewing code, and the employees are tight-lipped about each other, than one or more of the following happens:
0) The company ignores the problem, then goes broke because unmaintainable code means permanent fire-fighting. This is what usually happens.
1) Resources get added. If this isn't actually needed, but is being used to "code around" problem people, this is going to cause serious initial slowdown while they get trained. Which your good programmers don't have time for. So guess who gets stuck training the new guy. And guess what that means.
2) Code reviews! Oh, the humanity. Watch tempers flare as the shit finally flies through the air, after years of stifling deeply-held opinions instead of discussing them with your peers! Someone will either quit or get fired, so code quality will improve. Morale, however, will go straight in the toilet.
3) Coding standards. This is your best bet, in my opinion. You go into a room _without_ anybody's code, and all gradually develop some standards and best practices. This should take about a week and it is damn well worth it. It takes all the ego out, because everyone reaches the standards by collaboration. It also means that when people "complain" about code, they have specific things to cite, and specific reasons the complain about them. This is the best way to avoid peer-to-peer fights, because everything dilutes in the team. And if you have one person who is constantly fighting the _entire team_? Well, you had better re-evaluate whether you want that person _on_ your team. This solution should result in a _short_ written document, and should not be an excuse for out-and-out nitpicking. (HINT: Use a stopwatch to see how much time people try to spend arguing about brace and bracket placement, and kill the issue quickly with a vote.)
4) Peer-programming gets added. This is popular lately, and man, this is one place managers really better earn their pay. Careful balancing of the mix of peer programming and solo time, and careful pair selection, is required to slowly teach better habits. I recommend doing this AFTER the coding standards document, so that it "guidance" doesn't seem arbitrary or egotistical.
I had a good friend who did a lot of useful programming. He was full of creative ideas which made up for his lack of programming style. I recall one piece of Fortran code which used the "3 pronged if" which bracnched to 1 of 3 lines based on an integer being negative, 0 or positive like:
if (n) 1,2,3
1 i = i -5
goto 10
2 do something for 0
goto to 20
3 do something else
Anyway he had a section of about 15 lines with 10 labels and about 8 to 10 of these if's. Most of them had 3 different labels for the places to branch to. He said that he hated to waste a branch on an if.
He took a Pascal class and the teacher told him all the code for a program could be on one line since the input was free-format. So he wrote 1 line Pascal programs.
Needless to say he was proud of his code. In this case I think his value was obvious and the best strategy was to leave him to his ways. I tried to show him a few style issues like indenting code and using the better forms of if. Unfortunately there was no while loop in Fortran at that time, so some goto's were definitely required to implement loops which didn't use simple counting for control. Today's languages generally offer nice structures, but if my friend were still alive he would probably still be using Fortran 77 and 3 pronged ifs.
Ray Seyfarth, ray.seyfarth@gmail.com, http://rayseyfarth.blogspot.com
Maybe he'll see this article and get the hint.
If it weren't for deadlines, nothing would be late.
Too many people seem to be focusing on this as a technical or engineering problem that can be fixed by education, rationalization, discipline, design, or process. The info I see above seems pretty well thought out and rational, each person focusing on one facet of the symtom, and trying to leverage a fix.
I'm not surprised - that's what I come to slashdot for.
However, this is fundamentally a communications issue with potential business ramifications.
You want it changed for the better, you need to put a price on it, and show it to management. It's that simple. I'm assuming it's in man hours spent on bugs, and lost sales due to poor quality code engendering bugs, bring-up time for new employees, migration/maintenance costs for tools, etc. Not speculation either, actual literal costs. The next best thing is to find a manager who understands the actual costs, who agrees with you, who can then put a price on it and show it to management.
The outcome may be firing, it may be company mandated coding styles, it may be enforced design process, it may even be the adoption of a new development framework or third party release management system. However, if you can't put a dollar value on it, there's no business reason in the end.
As a side note: I just left a company which had this type of problem, and were at the point where 80-90% of the dev staff were involved in bug fixing only. Management's opinion was still that refactors or other mechanisms to reduce bugs and produce well thought out designs were still more expensive than delays in releases due to lack of manpower for new features. So even when it seems apparent from a technical problem standpoint, the finances favored the mess.
Let him have his monolithic lasagna code.
Whenever I write a piece of code that pleases me by my cleverness in crafting it, I rewrite it dumbed down.
Boring code is maintainable code.
tell him Microsoft is hiring right now...
I am SO SICK of older IT workers who fail to properly keep up with whatever they do and then this is the result. The IT manager at my old company (a hospital btw) couldn't actually name most of the parts in a modern desktop. He was in his 50's. Programmers are even worse. They're too lazy to learn new languages so they just don't and sort of cruise by with a half-assed attempt at making something sort of work. The best part is, they get paid the most! I now own my own computer repair business and if someone walks in and I know nothing about Windows 8, they walk right back out. You keep up or you go work in a different field. That's IT, deal with it. I'd push very hard for him to get fired.
point him at this article.
1. You write the most horrible code imaginable. 2. You stuff entire programs into single functions. 3. You artificially stretch function through relentless repetition 4. You make uninformative variable and class names. 5. You ignore basic language features, when they could make everything shorter and more readable 6. You don't use OOP correctly. You need to be smart to write good code. Being smart does not guarantee that you write good code. Writing code since before (insert person) was born does not make someone good at writing code. Some people just can't learn new things, especially some of these old self taught programmers who were considered hackers and geniuses back in the days when computers were simpler and dealing with a few hacks here and there was ok and easily fixed through more hacks here and there. When you graduate from a bicycle to a 747, duck tape is no longer allowed (and probably didn't even belong on the bicycle either).
Everyone thinks that they have a sense of humour & Everyone thinks that they write good code.
I've worked with enough tossers who believed that a particular style was the best way and that whatever style was being used was crap that I just want to vomit. Go and fix the MS word templates because they offend you sense of style, stay out of my way. I used to get involved in these debates and found that it was better to simply marginalise the idiot until he went away. Now I run a company which makes money and internally you don't get 'pretty'.
The job of coders is to ship code. If he's shipping more code and meeting more deadlines than you he's a better coder.
Really this point of view is bigger than this, it relates to directory structures, word templates, diagrams basically if you care about these things you're a time waster and are worth keeping on because you constantly get distracted by fluff and don't make money.
Once You attain enlightenment You'll know what to do.
Make sure programmers having documented unit tests is a standard at your work. Then watch him write tests for his uber-methods. Either he'll "get it" or he'll think testing is stupid. Having a programmer proclaim "testing is stupid" usually doesn't go over well with the rest of the department.
As a guy in his mid forties this is very true. The first time you go to a doctor that's younger than you, or get pulled over by a cop that's younger than you and have to call him "sir", you feel it.
The thing is you have to recognize it and fight that impulse. Everyone over 21 is an adult. Remember that. Mozart began composing at the age of five. Einstein came up with some of his best work while he was a patent clerk. Not every good idea comes from someone your own age and station.
And it's especially important in the software industry. Younger guys have an advantage us beginning-to-fossilize programmers don't have. They're *flexible*. They can and will use the newest technology and do things we can't. If you don't listen to the younger folks in this field, you will eventually look like your parents did when they couldn't stop the VCR from blinking 12:00. That's how you'll look.
If a kid gave me a book on being a better programmer I'd read the fucking thing. Ego be damned.
Weaselmancer
rediculous.
"Your code sucks."
Oliver's law of assumed responsibility: If you're seen fixing it, you will be blamed for breaking it.
I always wondered where Mel went to when he "moved on to greener pa$ture$".
Oliver's law of assumed responsibility: If you're seen fixing it, you will be blamed for breaking it.
svn blame
Talk to this guy
It's not wasting time, I'm educating myself.
Depending on your relationship with your coworker, you could try something like this:
"Dude! What the fuck is with this? This whole module reads like it was written by David Foster Wallace after sustaining a concussion!"
Then, having gently broached your general concern, you could offer a few helpful suggestions. "How about actual English names for some of your variables, instead of packing everything into a global array called "Stuff"?"
I'm actually only half kidding here. I'm lucky enough to work with guys with a sense of humor, so when one of us screws something up we expect a certain amount of ball-busting. I really do feel that this is a valuable practice, so long as the critics don't go too far with it and the critiqued can keep a good sense of humor.
indeed, this article is just one of jealousy. the old-timer will be there long after the kid is outsourced, for his wares are running the place
Nowhere did you say the old guys code didn't work, had serious bugs that weren't being fixed, or was noticeably behind the rest of the team according to the project schedules. Until that happens, and as long as the old guy is solving problems with his skill set, management may well consider your "good coding" criteria to be bad for the company, thus making you, not the old guy, the troublemaker for suggesting changing what works. Businessmen have been burned by too many trendy sounding academic fads, such as all the good coding practices recommended here.
Wait till you can out-code him, solve major problems he can't, and get promoted above him (or he dies or retires). Even if his smelly pile of code crashes and burns, if he can tape it back together faster (running) than you can rewrite it (feature complete), he's the hero, and you're the troublemaker.
He needs to learn:
Just because something is different doesn't make it bad or wrong.
For all we know the guy he's complaining about is a demon APL programmer. Or a guy who was partitioning FORTRAN so it ran decently on a super. Or maybe the guys an oldtime LISP dude and all the languages he's coding in makes him lament the loss.
When I see bad code, I fix it, test it to make sure I didn't break something else, and check in my changes. If the guy who wrote the bad code objects, then he's asserting that he OWNS the code in question, so made damned sure that any bugs in that code are on his plate to fix. If he doesn't fix his bugs, escalate.
-jcr
The only title of honor that a tyrant can grant is "Enemy of the State."
You don't have to embarrass anyone. Just fix what you want to fix.
-jcr
The only title of honor that a tyrant can grant is "Enemy of the State."
I really agree with this. Especially that last statement. It's the manager's job to handle this and fix it. If he can't see the problem or doesn't at least discuss why he would permit it (perhaps business reasons that are valid), then you are in the wrong place. If he goes, yes i know, I want to fix it, but we have to do it my way as the problem employee is actually valuable, then you have to trust in him to do it.
Have you fscked your local propeller head today?
Is it just the coding? Does he neglect to say hi or bye. When you are talking to him about something, does he just go back to work without giving you feedback because he is really busy. Does he skip using an IDE environment because he can just read and compile the code into an app. He's totally happy to do this over and over.
Does his odd ball brain make him superior at some tasks? Can he juggle 15 projects at once? Can he stay nose to the grindstone for 10 hours with a 30 minute lunch? Does he eat the same thing every day for lunch?
I'm describing my co-worker. Same coding issues. Same lack of interest in anything he doesn't write. But he is a valuable member anyways because he keeps things going in the old world while we write a new platform. Originally, he totally pissed me off, but I realized my manager understood my points and my desires to have a better organized team and environment. At the same time he explained he was working against the gun to reach milestones for our mid size firm.
Now i just understand this guy better and focus my attention on the more average personalities on my team that need a good code review or the benefits of my experience and talents.
Have you fscked your local propeller head today?
If you lead and no one follows then you're just out for a stroll. You're problem is leadership. Sounds like you already discovered that criticism isn't an effective method of exerting influence. Only after you win his heart will he be open to logic. This dude is probably sensitive about the age gap between the two of you. Play off of that by learning COBOL or something. Only when his age difference makes him feel intelligent and respected will he start to come around to appreciate what you know. It'll take weeks, not days, to win someone over and only then should to start talking about modern software design.
Patronize him, but only if 1) you are his boss AND 2) he's really so good that he's earned it.
Things like "Most of us aren't smart enough to read through this code and understand it quickly. One of the things keeping me from recommending you for promotion is that right now, if the team loses you, we couldn't maintain the code that you've written. For all future projects, I need you to 'dumb down' your code so less experienced programmers can jump in and maintain it if necessary."
Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
Good and bad code is all in the eye of the beholder.. what looks like great code to you can look like utter crap to another..
There are so many ways to do code, and also there are so many different views on what's good practice and what not.. Yes stuffing everything in one big function which spans multiple pages normally isn't considered good practice, but splitting every single thing up into separate functions is also not good. Also some people think using lambda expressions is great, others just think it makes it unreadable and you should just put it in a separate function (in the end, a lambda expression is nothing more than a function without a name)..
Just like declarations, some swear by hungarian notation, other actually swear at it (to me it all depends on what programming language you are using).
In most cases just talking to each other and explaining why a specific way might be better is the way to go, maybe the other person than explains why their way which after explaining makes sense to you.. As I said everybody has different views on what constitudes to bad/good code..
If you want to force your way of development on others in a company than you should have a document in place which tells exactly how to do some stuff..
I for one always say, at least comment your code as good as possible, as even having great descriptive variables doesn't mean the code is readable.. and a person once told me: 'well good written code explains itself' I responded with 'well bad written code also explains itself, because the compiler can understand it so it must be good written code'...
Here's reasons why I don't like this topic:
1) There is no bad code. Every programmer has written the best code they can write. If you have trouble reading it, buy some better glasses.
2) Complex code is not bad code. The programmer you're trying complain about is smarter than you think. He saw some complex problem in your software architecture and his complex code fixed it. You still can't even see the problem, much less the solution. It works, and any complaining about the details is useless.
3) Reading someone elses code is always difficult. about 90% of programmers think they write better code than others simply because reading ideas from other programmers is difficult. This accounts large portion of "bad code" out there. You need to find better criteria for labeling someone elses code bad. How about check test cases that fail... Oh wait, where's our test cases?
In our company, code reviews are mandatory and that restriction is built into checkin triggers (clearcase). No exceptions. When this process was instituted about an year ago, expert programmers wanted to checkin without code reviews. They only wanted to review new-hire or inexperienced programmers' code. However, the new-hires all knew the 'right way' that they are taught in school, though they should be reminded to keep following those good ways (in school you lose points for writing bad code in programming assignments and your grade is at risk). Over the last one year, after the triggers were instituted, the team culture has changed from having lengthy email disputes to something more like teamwork. Every comment is greatly appreciated and good reviewers are rewarded. The only ones people still don't agree upon are indentation and code-formatting related. People still have different opinions about those (we found a different solution for it that everyone agrees with). However, there is almost no dispute in our team about what constitutes good, working, maintainable code. Everyone in the team has learned and would not want to live without mandatory code reviews any more. If the expert programmer disagrees with the comment, fire him. There are thousands of other expert programmers out there that work well with the team and lead by example.
The coworker is NOT smart.
Only smart programmers can write simple code.
Kim0+
You (and every other development shop) need:
* A coding standards document. Using one from a large open-source project (such as http://framework.zend.com/manual/1.12/en/coding-standard.coding-style.html or http://www.kernel.org/doc/Documentation/CodingStyle) is a good idea. This ensures that you do not have to spend any time being surprised or misled by how a piece of code is formatted.
* Unit tests. They make sure that your code continues to work the same way as you develop it. They also exert pressure to make sure that your units (individual functions to be tested) remain small and concise (or else the unit tests become a bear to write).
* Code reviews. This ensures that more than one person understands how a piece of code was written. It also means that the reviewee learns from your comments and you learn from his code and you both are better programmers for it.
And, most importantly:
* A manager who believes in all of the above and is willing to support and defend it.
If you have all this, then it ceases being a personal "you vs. him" issue, because you can objectively point out (to him, to your team lead, or to your manager) where he's violating the coding standards, where his unit tests are not adequate, or where he is ignoring his code reviews.
The alternative is what it sounds like you have now: cowboy programmers, quickly cranking out code that satisfies a need right now but will take huge amounts of time and money to maintain and extend in the future.
I've never heard the term lily-padding but I've worked with those sorts of folks. They have to be removed at least from the team if not the company, sidelined into solo projects that don't require maintenance (because they never completely work in the first place ;-) A development team needs cohesion, not necessarily conformity. I work with 3 other coders and we debug each others code when needed and over the last 7 years have mixed and matched approaches into something that is a lot more standard than any possible set of standard coding practices written up!?!
/* that does not sound like the OPs issue tho*/
It happened organically. If you debug your own code two years later, you should have learned a lot (if you've been coding that time) whether on your own or working in a team. There are folks tho who do have what they call 20 years of the same 1-year experience, never learning anything after the first program.
some code needs to be maintained and some doesn't.
;-)
speed of coding vs maintainability vs robustness are always in a tradeoff in a professional programmer's mind.
If this is a simple conversion routine that won't be used again, git her done..If robustness is important, spend some time thinking about the over-all design. If you have snarky developers with some kind of religious affiliation to a language or operating system, don't waste a lot of time arguing (assuming you want to win an argument (you know facts, logic, that jazz). If you just like arguing, then there is no one better to fool with
For a loser programmer, suggesting refactoring can backfire. We told one gal (who was finally fired after waaaay too long) to use a library file (in Perl) for the common routines for the reports she was 'writing' (cutting and pasting). The next day, instead of 20 files in our report directory, we had 40, a new .lib for every .pl!?!
We refused to make any more suggestions.
Been there! Every time you have to fix his garbage code, make sure to let management know. Push them to deal with it. It might be as simple as sending him to a basic course in OOP fundamentals - far too many old-school coders have no formal instruction and just don't "get OO" and insist on writing procedural code in OO languages. Bad OO code is much harder to work with than bad procedural code and management must be made to understand the cost of letting him continue to write bad code. If he still doesn't get it, you could suggest he be moved to architecture or some other team that can use his knowledge and experience while keeping his fingers out of the actual code.
You: "Knock knock"
!Coder: "Who's there."
You: Yuri
!Coder: "Yuri who?"
You: "You really can't code."
Where are we going and why are we in a handbasket?
How about just telling the fellow directly? Why the hand-wringing over this? I appreciate it when someone tells me where I need room for improvement and any reasoned person should as well, no?
-- I fear explanations explanatory of things explained.
Sounds like good case for https://en.wikipedia.org/wiki/Pair_programming
Casteism
"Are you still having problems with people reverting your commits at your new job?"
"No good deed goes unpunished"
In 99.999% of the cases, every engineer thinks every other engineer's work is a piece of sh*t. So what else is new?