- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
I strongly disagree, only because often the new guy isn't exposed to the myopia that tends to creep into established companies wherein nobody looks to improve and just continue to do things the old way because they don't know better.
A new developer with experience who is just new to THAT company is usually a godsend as they have a fresh face, a fresh pair of eyes and fresh ideas that aren't mired in stagnation. It's a different story of course if you're hiring a junior or entry-level guy.
Admin
Only if it actually needs to be maintained. It's not clear this particular code does.
Admin
Second that!
In my case, the long-time developer badmouthed me to our boss and weeks later I was on the way out.
Admin
CAPTCHA distineo - Having a destiny equadistance to Neo's.
Admin
In a perfect world, yeah, we would fix ALL of the crappy code, but honestly, we seldom have that luxury. My general rule is, if I have to touch the code for any reason, I'll refactor and improve the surrounding code as well. If I'm fixing a bug, or adding a new feature, then they are already going to have to test this piece, so this is an acceptable time to make improvements. I typically don't go digging through the code base looking for all of the bad code, just searching for something to improve. Rather than "If its not broke, don't fix it." I tend to believe "If its not broke, fix something that IS broke, and refactor the crappy code there while you're at it."
Admin
Any skilled developer with a few years experience knows that a general solution to this problem can be trivially tested and proven more reliable than hand-coding a field-by-field copy every time you need one. And the end result is that now you have tested code doing your lifting, and your code becomes incredibly simple to maintain and extend.
There's some real WTF gold in the comment, though:
aj clearly understood how to solve this problem in general, but instead of implementing it, which would've taken 5 minutes + the test, he proceeded to copy/paste 40 lines of get/set and then manually hardcode the types for each.
But lastly, TRWTF is that there's any code for this at all. What relational database worth using doesn't let you insert the results of a query into a table?
Captcha: ingenium. This code is not it.
Admin
I saw comments like that at my old job fairly frequently. Our "senior" dev (senior as in tenure, not experience) would often have comments stating "could probably do this better" or "why is this here?" or "don't know what this does". Instead of doing things right he'd instead copy/paste dozens of lines of crap and finish a task immediately, then spend weeks fixing bugs that cropped up because of his half-assed solution.
Admin
It happened to me once as well. The "login" procedure for the application was intended (originally) for hard copy terminals, and for "security" had a bunch of X's printed where the login stuff was to be typed in. Fast forward to display terminals (or windows with terminal I/O in them) and the overstrikes themselves get overwritten. While this wasn't bad, the prompt was overwritten with the spaces to put in the X's, so there was no prompt. Silly me, I tried to "fix" it and have the prompts be the last thing printed so you could at least see them, and everyone raised a hissy fit. The problem was that the "tests" that were run expected the old prompts, and they weren't willing to change anything. My attempts to explain were futile and I reverted the code.
Silly me for trying to "improve" things to attempt to make the program correspond to the written documentation that had been published years (parts were probably over 30 years old) ago. Don't try that again!
Admin
I don't see a WTF here with just what has been presented. I see perhaps a junior or inexperienced programmer with disregard to environment, priorities, resources, etc. If I were in that meeting I would have smacked the greybeard's hand though. Presentation is everything.
As I've progressed over the years I have realized that every bit of code, even a WTF, has extenuating circumstances. And any decent development process would exclude changing working code just to change it. There has to be a compelling reason other than bad code to commit the resources all the way down the line to introduce new code to the system. If you have spare bandwidth, go for it. But every development shop I have been in has always been in a resource deficit. And we've always managed to progressively produce better and better code. But there are always those blocks of code that rogues put into your system just to make you cringe and frustrated that you don't have the time, money, or people to fix (right now).
Admin
TRWTF is using Java. Even worse? Using Java with databases!
Admin
Agreed. Especially if your procedures for filing a change request, the meetings to approve the request, assigning and scheduling the request, making the change, demonstrating the fix, code review, testing, documenting, etc. all add up to an unacceptable expense, don't touch it! Of course, in that case TRWTF is the procedure... <sigh>
Admin
The 'graybeards' did have a point. I would be curious to know how that conversation actually went. It was spun for this story in such a way as to dismiss their point.
What isn't mentioned is what does recent code look like and is it well tested? I have never worked anywhere (other than a few baby startups) that doesn't have some mission critical legacy junk floating around that is messy, often written in a bygone era and merely ported to the current platform (along with so much other stuff that fixing it wasn't possible at the time of porting.)
Legacy code can suck sometimes and merciless refactoring for the sake of refactoring often does introduce bugs that cost the business money and the team additional headaches unless it happens to be well tested (but usually well tested code isn't crappy.) I have worked with developers, who while generally competent, refactor needlessly and break things. That causes problems for the business.
Really as a team they should strive to move forward ensuring that all new code is clean and well tested. Time must be allocated to not fall into the mindset and traps that produced that bad code to begin with. Michael was absolutely right to be annoyed by not doing things right to begin with.
That doesn't mean it can't ever be fixed. A good rule of thumb is to refactor legacy crap code only when maintenance requires it to be modified anyway, consumed by something new, or perhaps a dependency needs to be modified. Working but messy code is only a problem when it needs to be maintained for something. Lump the work of refactoring and the required testing together with the modification. That is an easier sell to the business.
I'd prioritize adding good test cases (since I get the impression this isn't well tested) over refactoring since it will help you tremendously when it does come to be time to refactor.
Admin
Not sure where it originated, but this is one of the truest axioms in software development: "There's never time to do it right, but there's always time to do it over again."
Admin
Sounds like SOP to me. But remember, before an official change request form can be printed, a 1 year feasibility study must first be conducted.
Also, change requests must be printed on official greenbar paper, on the official 'change request printer', which is available only 3 months out of the year.
This is for...security purposes...if you could print a change request form on just ANY paper or printer...then it would introduce unnecessary risk! After all, you can't just go around printing change requests for building hyperspace bypasses on just ANY paper, can you?! The Galactic Hyperspace Planning Council would be most displeased.
Admin
'Cuz I'm seeing Tommy Chong.
Admin
I'm thinking more of a rather-stoned George Carlin
Admin
At first I thought if he couldn't understand it, how did he know if he rewrote it correctly? Also, if you are unfamiliar with something, why not learn it? Then I thought, meh, whatever.
I'm going to keep using what I'm comfortable with, and if he wants to change it, what do I care? Paycheck is the same. Exactly. The. Same.
Admin
Admin
Isn't that the very definition of "unmaintainable"?
Admin
This is completely opposite of yesterday's TRWTF which is where the boss actually agrees to a change in the codebase
Admin
If it makes it so new people can't understand it, them you should fix it ASAP
Admin
If it makes it so new people can't understand it, them you should fix it ASAP
Admin
If his criterion is that he refuses to take any job where he might be asked to work on code that is poorly written, I think that would considerably narrow his job prospects. If you can find an organization where ALL the code is beautiful and elegant, let me know. Well, they probably wouldn't hire me, because I've occasionally written bad code myself.
It's one thing to say "I hate working on sloppy code". It's quite another to say "I refuse to work on sloppy code".
I hate it when a toilet gets clogged. It's ugly and smelly and unpleasant. But this does not me that I refuse to live in any house where the toilets ever get clogged. There is no such house on planet Earth.
Admin
Thems the guys that taught me to 'Fus Ro Dah' harder.
Admin
The "if it ain't broke, don't fix it" approach ignores one of the fundamental natures of program code - it is mutable. Most of the time, code you write today will be modified in the years to come, probably by other people. Rewriting bad code is usually a good investment of time. Writing good code in the first place, of course, is almost always a good investment of time.
As for the ternary operator, would the following be better written code? foo = ( (bar > 0) ? baz : qux ) ;
Admin
Ditto. If the code works, then changing it just to make it cleaner is asking for trouble. If the code works as desired, then by definition there is zero chance of improving its functionality, and a non-zero chance of breaking something. You may make it more maintainable, but if it doesn't need to be maintained, so what? Maybe it will never need to be changed before becoming obsolete and being thrown out, so the effort will be wasted.
Even if I was sitting around with absolutely nothing to do, I would be reluctant to "fix" code that isn't broken, because if I break something, then my productivity is negative.
Now when code needs to be changed, and therefore will have to be tested, NOW is the time to do clean-up.
Admin
Exactly. Unfortunately the problem so often arises that when the time comes for the code to be modified, there "isn't time" to do the clean-up because whatever feature was promised yesterday or you just have lazy developers who are afraid to tell the manager "Hey this will take a few extra days so we can do some housekeeping of the code and make future changes like this easier". So you run into ALWAYS putting off the clean-up because there are "other priorities".
Admin
I often run into legacy code too, and it is often a mess. I won't try to whole-scale fix anything that isn't my direct responsibility, but when I touch a file, I always try to leave it better than when I started. So any new code I write, is 100% according to the company coding standard, and well documented. If I ever have to do band-aid hacks, I will precede them with a big comment saying, essentially, "Yes, this is a hack, here's how it works, and here's how it could be done better if you ever get time".
I also run the code through the beautifier (formatter) before checking it back in, after confirming with the code review tool that that step only affects whitespace (e.g. NO impact to the code itself or to any CM merges that may follow). Our diff tools are smart enough to know that changes in whitespace don't change anything else.
I consider coding to be a kind of art form. I want my code to work, but I also want it to look good (in the sense of readability and maintainability).
Admin
It really depends on what the cost of downtime is. In this case it sounds like they have some potentially costly SLAs to maintain. Some applications are more tolerant of downtime and bugs than others. This should be considered in the 'to refactor or not to refactor' question. There isn't a one size fits all answer. Where I work downtime and the introduction of new bugs is extremely costly to the company and we have legacy stuff that is bad (our recent stuff is not so bad and is well tested.) We comment hard to understand code as we discover what it does, and only refactor when we need to change that code for some other reason.
Admin
... and the answer is "Umm, I think so. God I hope they never ask me what it does."
Admin
Sadly sometimes that is what the customer wants. They just want to get the monthly report out today with the new changes that they forgot to ask before the end of the month. If the report spits out but takes 2 hrs to run, or crashes the server immediately afterwards they don't care.
Sometimes they only want to see their "get report" dialog and let you spend the next month fixing it so it actually works. If you wait till the end of next month to show them something you fail because you didn't meet their emotional needs of seeing jump up and say "yes boss right away boss."
Admin
Fortunately I haven't been forced to use Windows since XP, so I'm fine. Next you'll be telling me they're planning to fart around with the familiar Office interface for no apparent reason. Thank the gods of open source we have Open/Libre Office so people can have a comfortable, time tested interface.
Admin
Productivity isn't measured in functionality and bugs alone. It's also measured in time savings. If you spend 2 years implementing N features, and someone else spends 3 months developing a library but 0 features, then implements those N features in 1 week, they're many times more productive than you. It's unlikely their solution will have 0 bugs, as it is unlikely yours is to have 0 bugs, but what's almost certain is that if they approached solving common problems in a central, maintainable, and clean way, their code can be more easily tested. More importantly, given that it took a week to implement those N features, adding more in the future or changing them is trivial.
Negative productivity, then, isn't just introducing bugs, it's making future work with the codebase more expensive than it should be, as well. A very common idiom fits this situation perfectly is "penny wise but pound foolish". A bug that takes 30 seconds to fix is nothing compared to perpetuating a design flaw that requires people waste hundreds or thousands of hours debugging, hacking, or just maneuvering around due to an unnecessarily massive/verbose codebase.
Admin
Based on her other support requests ("I can't print" means she accidentally dragged the icon of her favorite document to a slightly different location on her desktop, and now, can't find it to open it) I'm pretty sure that she couldn't get out of a burning building if somebody moved the doorknob two inches.
I had to wait for her to retire before I could upgrade her system off of Windows XP Service Pack 1. You don't know how badly I wanted to install Icon Fright late some evening. (It makes icons flee the mouse pointer.) She probably would have had a heart attack.
Admin
I learned very early that you should not separate the cleanup and the update of the code. They are one and the same, and your estimate should not be "20h cleanup, 2h update". It should be "22h update". You wont even be lying, since fubared code tends to be unneccesary hard and slow work, so just bolting a new gadget onto the ugly is sure to be brittle and break in interresting ways making a 2h update in reality be 22h anyway, but leave the code a bit uglier instead...
Admin
this should be featured!
Admin
Admin
"Wait what?! You think i will apply emergency patch at 2AM, fuck this!" walk out
Admin
orly? with macros... burn in hell!
Admin
Admin
a. You think I will be there at 2am to apply an emergency bug fix? b. You think if I was there at 2am I would be in any shape to apply an emergency bug fix that doesn't cause more problems than the fix is worth?
Admin
Admin
Because the original author even realized it was sloppy and should be refactored. It also sounds like they would NEVER have time for a refactor because they'd never consider it a priority, even if maintaining old messes took more time.
Admin
Only if we ban everyone who isn't American. Just because a word is not in common use in American English doesn't mean it isn't in common use in other locales.
More importantly, can we ban anyone who says "Let's see if we can't do X"? That would get rid of all you daft Americans, instead.
Admin
He left his job because of that? I think his standards were too high.
Admin
Why all the hate against this WTF? This entire website is about making fun of terrible code, people or procedures. This code qualifies for the WTF. But instead of actually pointing out that fact to his colleagues, you think the programmer should have just ridiculed the code online without actually attempting to better the organisation?
TRWTF is not supporting his actions. Bravo to Michael.
Admin
Refactoring prime numbers is hard.
Admin
Those reminded me of why I left a place after a couple of years a couple of years ago. Since it was a public-facing website, and I wanted to gauge how it would look on my resume, I've ended up watching the slow-motion trainwreck play out as bug was followed by crash was followed by "offline for servicing" notice was followed by feature removal (which triggered a new rash of bugs). As of a couple of months ago the site has been totally unresponsive. I think maybe I should drive by the offices sometime and see if they're still occupied.
Admin
LOL. What a coincidence. I also had the experience of working in a company like this. The company invented their own proprietary framework that mimicked Entity Framework 4.0 but using only Arrays. No generics since they wanted the whole framework to be .Net 1.1 compatible!!!
Admin
A problem is that such clean-ups only apply to specific bits of code at the time they need maintaining. An effective clean-up may involve changes elsewhere to, well, refactor common code.
Otherwise, similar stretches of the code end up getting written differently (maybe they started out as conceptually distinct, or one was written by someone unaware of the other, or it would have Taken Too Long to alter the original code to handle the new case). You end up with three or four implementations of what seem to be the same thing - but not quite - and ending up with a lot of glue to go back and forth between them and/or a lot of duplicated functionality.