5 ms·
I've inherited 200K lines of spaghetti code—what now?
- Kilimanjaro 14y agoDump it and rewrite it in ten thousand lines of beautifully crafted code.
- eps 14y agoAlso known as "Russian refactoring". Every self-respecting Russian programmer will always try and convice you to rewrite everything from scratch. Regardless of the context. I'm pretty sure it's in their DNA.
- YuriNiyazov 14y agoWhere is it known as such? Googling "Russian refactoring" brings up nothing related. This is not strongly exhibited amongst me and my friends. Maybe we are not self-respecting.
- huhtenberg 14y agoYou are young yet :) Virtually every Russian dev over 30-40 I know is like that. I am myself that way too. It always seems easier to redo from scratch than to waddle through someone else's code.
- zeroonetwothree 14y agoThis is true of non-Russians as well.
- eps 14y agoChill, comrade Yuri :) It's a joke. Though... not really.
- deleted 14y ago[deleted]
- vineet 14y agoSorry, but this is really bad advice. It is very tempting to redo something from scratch, but in doing so you will end up spending a very large amount of time fixing issues and adding details that were already done in the original code.
- antidoh 14y agoI think the advice was sarcastic.
- vineet 14y agoOh, In that case... (I can't tell you how many times I have heard the same advice being given seriously)
- antidoh 14y agoSame.
- TillE 14y agoIt can sometimes be the right approach. It's not a decision to be taken lightly, but it should be on the table. Especially if your goal is not to duplicate the functionality of the old software precisely, but to provide a significant upgrade. It really depends on the requirements.
- cjdentra 14y agoOh yes, I have seen where re-writes are actually done. Developers start to talk about the lack of "scalability" and "maintainability" of the application with the best solution being to rewrite the app. I've also seen Java-to-Microsoft stack ports being bandied about. Generally it is a really bad idea but some of the decision depends on the language(s) preferred by the firm inheriting the app and the size of the app.
- greenyoda 14y agoHe can't do that, since he doesn't have the hundreds of man-years of domain knowledge that the authors of the code have accumulated. As a software developer, he probably doesn't know the first thing about how a chemical plant works. ("The program itself is a physical model of a complex chemical processing plant; the team that wrote it has incredibly deep domain knowledge but little or no formal training in programming fundamentals.") Understanding 200K lines of complex code well enough to be able to rewrite it is hard enough, even if it's just pure database or graphics software. If it's about something you know nothing about you're going to have to learn something about the domain first, just to understand if the output you're seeing is anywhere close to correct. You're going to need to know whether some odd behavior of the code is essential to its correctness and must be preserved, or an accident of its particular implementation which can be changed or removed. Also, you can't just dump some system that people depend on to get their work done. You have to maintain it and fix bugs while writing its replacement. Given that he's just a lone developer and doesn't have the budget or authority to hire a large team of professional hackers to help him, his only chance for success is to start learning about the system, adding tests and making small refactorings.
- Groxx 14y agoThis is worthless. It's a copy and paste of this question on Stack Exchange: http://programmers.stackexchange.com/questions/155488/ive-inherited-200k-lines-of-spaghetti-code-what-now http://programmers.stackexchange.com/questions/155488/ive-in... but with broken formatting, and nothing else.
- falling 14y agoNo it’s not. The article gave the question visibility outside Stack Exchange, where I (and I’m sure many others) would have never seen it. Also, it’s by Stack Exchange, as stated in the byline and right at the top of the article. Edit: cool, I was wondering why I hadn’t been getting any reactions to my comments in the past weeks. Today I realized I’ve been hellbanned, most likely for this http://news.ycombinator.com/item?id=4208283 http://news.ycombinator.com/item?id=4208283 This is bullshit.
- vineet 14y agoYeah. There is no value being added beyond just copying Stack Exchange. Is Ars Technica in trouble these days that they are just copying content?
- mattdeboard 14y agoI think every news wire service in the world would disagree with the perspective that you and the GP are espousing. edit: I have made the mistake of using an analogy on the internet. I realize it's not exactly the same, ok?
- Groxx 14y agoHah! You're probably right. I'd be interested in the thoughts of the people running this show, if they'd drop in :| It would be an interesting debate, in any case. I'm really having trouble seeing how this (particular instance, not necessarily in general) is a good idea, or at all in line with SE's design.
- TazeTSchnitzel 14y ago
- fredsanford 14y agoI'd update my resume and start looking for a new job. I've been in this situation twice in my career and neither ended well even with me busting my arse making real improvements. You have to be the super-hero every day...
- SeanDav 14y agoAgree totally. I came here to post exactly this sentiment and saw it had already been done. I have also been in this situation and I can say that this is NOT a technical problem, this is a political problem and the only person that is going to lose is the new guy - namely the OP. Of course the problem has a technical solution but the huge red flag is that there is no consensus. This means that whatever solution is put forward is going to upset someone and guess who the target of that ire is going to be. The only way this is viable is if someone with real power is backing the project and what he/she says goes.
- reinhardt 14y agoFully agree with the solution. What I don't get is how one ends up in this situation in the first place. "I am newly employed as the sole 'SW Engineer'...". How on earth did he go through phone screenings, interviews and finally accepted an offer without any idea of the mess he got himself into from day one?
- SeanDav 14y agoCan't really blame him. Unless you been through this sort of mess before it is very easy to see this as a lovely technical challenge where the SW developer is the knight in shining armour that will end up as the hero after he slays the technical dragon. Of course that is the fairy tale and in reality the technical dragon will eat the knight and use his sword as a toothpick.
- coliveira 14y agoUnless you're very senior, it is hard to know exactly what you'll be working on when interviewing for a company. And even when information is released, companies usually paint a rosy picture of your new position and responsibilities.
- InclinedPlane 14y agoYou'll want these: http://www.amazon.com/Working-Effectively-Legacy-Robert-Martin/dp/0131177052 http://www.amazon.com/Working-Effectively-Legacy-Robert-Mart... http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672 http://www.amazon.com/Refactoring-Improving-Design-Existing-... http://www.bevmo.com/Shop/ProductDetail.aspx?ProductID=1282 http://www.bevmo.com/Shop/ProductDetail.aspx?ProductID=1282
- snorkel 14y agoYou can't teach old dogs new tricks. Introduce best practices slowly in order of priority otherwise if you overwhelm the old timers with lots of new coding policies that they don't understand then they'll just dismiss it all as useless bureaucracy.
- greenyoda 14y agoSince the guys who wrote the original code are scientists or engineers, they probably learn new tricks all the time within their own profession. The fact that they realized that their code has become an unmaintainable mess and have hired a software developer to help them out seems to indicate that they might be open to listening to what he has to say. If the software guy comes in and starts insulting the scientist guys' code, the game is over. If the software guy shows no desire to listen to what the scientist guys have to say, or learn anything about the problem domain, the game is over. But if the two sides can learn to work together toward a common goal, they might have a chance of success.
- tlb 14y agoG2 is hardly "Pascal with graphics". It's Gensym's expert system for real-time process controls: http://www.gensym.com/product/G2 http://www.gensym.com/product/G2
- vineet 14y agoI have found a particular/simple solution very helpful and I am surprised that people don't talk about it (or perhaps don't know it). The basic idea is to, try to spend 1 hour on each of: 1. examine the code very quickly (try to do it in an hour or so), and based on the scan to guess what the top 4-5 subcomponents of a system are. 2. do quick code examinations to figure out what each subcomponent is supposed to be doing, and how each subcomponent is supposed to depend on the other subcomponents. 3. Now modify the code to reflect the above components. At the simplest, just move code into new directories for each component, but at more detailed levels you can make sure that there is never any single source file that has implementation for more than one component. Now you are done. You can clean up code more if you want, but do that slowly. Just make sure to not put new code in bad areas. Yes, you will possibly have spent more than 1 hour on each part. But you should have a much better grasp of the code, and the code will not keep on deteriorating. I am not really talking about badly documented code or code with bad naming conventions, or other related problems. However, when the big problem is the 'spaghetti' (and cyclic dependencies) - this has really been the only solution that has worked well.
- Zenst 14y agoSlowly over time clean up the code and educating though examples and approachs and standards and all agreeing and understanding them would be a good start, nomatter the direction. Also if its viable to document, albeit organicly in a way that you have a process to control changes, it can only help. One day you will have it fully documented or cleaned up. Slowly, slowly catch the monkey was a comment a COBOL programmer I worked with in the 80's would put in all his code (along with naming all his procedures after drinks, but lets not go there - shudder). I now, know why. Knowledge based systems are great, but they do end up mixing the data into the code in a way that over time is fun. I had to work on a real crazy bit of C code once that was larger than I cared for. I mearly found the parts that effected what I needed to do and changed that. It worked, no idea what most of the code did but the aspect of being to work with more than one radio controler was easily enough to change. No documentation and was a bit spag bowl. But it was a easy change and in many ways it was due to design of the programmer who had written it. He had allowed for such a change, not documented but was easy and changing a few variables mostly. Leason there is you can have code that makes no sence, but it gets the job done and if you need to change a particular part, if you can locate that part then you can read the effecting code and change what you need. If when codeing you plan ahead of possible future changes. Well nobody can ask any more. If it works, why argue. If you can slowly and saftly make it work better then fantastic. Remember not all new wheels go faster or better than the ones they replace. Think about that incase you argue a rewrite. Rewrites for the sake of it one day and next you will be flying with the seagull managment. Also worth factoring in that spaghetti code saves jobs and lives, I understand that joke now.
- smashing 14y agoTwo words: Bath Salts.
- Zenst 14y agoA important question you have to ask yourself above all others: Is this something that is portable skills wise, will you learn about the subject and will that skillset be something of interest and marketable down the line? Reason I ask that is if your not interested in it and/or if it is such a niche feild that the knoweledge you will gain on the subject is not portable. Well, unless its a pasion, just remember one important thing: probation periods work both ways.