Previous programmer died unexpectedly; how do I pick up where he left off?

I have recently taken a job finishing the development of a .Net application. The delivery of the application is two years behind schedule. The previous developer died before I had a chance to meet him. I have been given copies of directories from the deceased's laptops. There are many directories of code (including seemingly duplicate directories), two SQL Server databases, and some Visual Studio project files. A quick wc shows about 300,000 lines of .Net code. There is no source control, no documentation, no licenses for third party controls, no unit tests, no build scripts, no release scripts, no install, and no real software development process to speak of. Maybe some of these things did exist, but I can't find them. I am an experienced software developer, but I have never been in a situation quite like this. Lastly, I have budget to buy tools as necessary, but not more staff. _What would be your 90-day plan to get this project moving again?_ Obviously I have months or years of work ahead of me; _what should be my priorities?_


Why does TDD work?

Test-driven development (TDD) is big these days. I often see it recommended as a solution for a wide range of problems here in Programmers SE and other venues. I wonder why it works. From an engineering point of view, it puzzles me for two reasons:   1. The "write test + refactor till pass" approach looks incredibly anti-engineering. If civil engineers used that approach for bridge construction, or car designers for their cars, for example, they would be reshaping their bridges or cars at very high cost, and the result would be a patched-up mess with no well thought-out architecture. The "refactor till pass" guideline is often taken as a mandate to forget architectural design and do _whatever is necessary_ to comply with the test; in other words, the test, rather than the user, sets the requirement. In this situation, how can we guarantee good "ilities" in the outcomes, i.e. a final result that is not only correct but also extensible, robust, easy to use, reliable, safe, secure, etc.? This is what architecture usually does.   2. Testing cannot guarantee that a system works; it can only show that it doesn't. In other words, testing may show you that a system contains defects if it fails a test, but a system that passes all tests is not safer than a system that fails them. Test coverage, test quality and other factors are crucial here. The false safe feelings that an "all green" outcomes produces to many people has been reported in civil and aerospace industries as extremely dangerous, because it may be interepreted as "the system is fine", when it really means "the system is as good as our testing strategy". Often, the testing strategy is not checked. Or, who tests the tests? In summary, I am more concerned about the "driven" bit in TDD than about the "test" bit. Testing is perfectly OK; what I don't get is driving the design by doing it. I would like to see answers containing reasons why TDD in software engineering is a good practice, and why the issues that I have explained above are not relevant (or not relevant enough) in the case of software. Thank you.


How do I maintain a really poorly written code base?

> **Possible Duplicate:**   >  I’ve inherited 200K lines of spaghetti code — what now? Recently I got hired to work on existing web application because of NDA I'm not at liberty to disclose any details but this application is working online in sort of a beta testing stage before official launch. We have a few hundred users right now but this number is supposed to significantly increase after official launch. The application is written in PHP (but it is irrelevant to my question) and is running on a dual xeon processor standalone server with severe performance problems. I have seen a lot of bad PHP code but this really sets new standards, especially knowing how much time and money was invested in developing it.   * it is as badly coded as possible there is PHP, HTML, SQL mixed together and code is repeated whenever it is necessary (especially SQL queries). there are not any functions used, not mentioning any OOP    * there are four versions of the app (desktop, iPhone, Android + other mobile) each version has pretty much the same functionality but was created by copying the whole code base, so now there are some differences between each version and it is really hard to maintain    * the database is really badly designed, which is causing severe performance problems also for fixing some errors in PHP code there is a lot of database triggers used which are updating data on SELECT and on INSERT so any testing is a nightmare Basically, any sin of a bad programming you can imagine is there for example it is not only possible to use SQL injections in literally every place but you can log into app if you use a login which doesn't exist and an empty password. The team which created this app is not working on it any more and there is an outsourced team which suggested that there are some problems but was never willing to deal with the elephant in the room partially because they've got a very comfortable contract and partially due to lack of skills (just my opinion). My job was supposed to be fixing some performance problems and extending existing functionality but first thing I was asked to do was a review of the existing code base. I've made my review and it was quite a shock for the management but my conclusions were after some time finally confirmed by other programmers. Management made it clear that it is not possible to start rewriting this app from scratch (which in my opinion should be done). We have to maintain its operable state and at the same time fix performance errors and extend the functionality. My question is, as I don't want just to patch the existing code, how to transform this into properly written app while keeping the existing code working at the same time? **My plan is:**   1. Unify four existing versions into common code base (fixing only most obvious errors).   2. **Redesign db and use triggers to populate it with data (so data will be maintained in two formats at the same time)**   3. All new functionality will be written as separate project.   4. Step by step transfer existing functionality into the new project    5. After some time everything will be in the new project Some explanation about #2, right now it is practically impossible to make any updates in existing db any change requires reviewing whole code and making changes in many places. **Is such plan feasible at all?** Another solution is to walk away and leave the headache to someone else.


How to reply to incomplete requests from potential customers?

Working as a freelancer, I receive many weird, invalid or incomplete requests from the actual or potential customers. The most frequent case is this one: > Hi, > > I need a website where people can register and there are also postings and > ratings. How much will it cost to me? > > Thank you. The request sucks, but **it doesn't mean that a customer like this is not worth it**. This person doesn't know how to make a request correctly, but with **a bit of effort and a bit of learning and advice** , this person may become a valuable customer who will not waste my time. For a while, I just **replied by asking to provide details**. They never do. Recently, I decided to **reply in a more detailed way** , explaining _why_ is it impossible to give a price (except telling that it would be somewhere between $500 and $50 000). First I just made a simple explanation, telling that their description of the project is too sparse. Then I added further info, metaphors, etc., or by making comparisons with other domains which are better known by people with no technical background. For example: > “Imagine you want to build a two-storey house. Do you believe it's possible > to determine the cost of building a house just by knowing the number of > storeys? You probably need to provide much more details: is it built with > rock or wood? Are there solar panels on the roof? Is there a swimming pool > in the backyard? > > A large Victorian-style house using the newest technologies, with two > garages, a large terrace, etc. will cost much more than an tiny modest two- > storey house for a family who really don't have too much money to spend.” It's still not working: those potential customers never respond. I also tried the "let me gather the project requirements for you from scratch and do the specification and architecture, but don't forget to pay me for this" technique, but it looks like scam¹. In all cases, in my country (France), this never works with new customers for several reasons. Some hints show me that **some of those people actually succeed finding a developer and succeed with their project**. It means that my approach with those potential customers fails, while there is one approach used by someone else which works well. How to reply to such price requests, considering that those people don't know me, don't trust me yet, don't want to spend days writing a detailed document describing every functionality of the project, and sometimes don't even know precisely what they want, but are not ready to pay you thousands of dollars just for requirements, specification and architecture steps? * * * ¹ Most projects are small enough and have tiny funding; most customers don't bother to know that the source code is clean and maintainable, that it was regularly refactored, and that you have unit and integration tests. **They want to pay less, now, no matter how expensive it would be later to maintain the codebase.** In this context, talking about functional and non functional requirements, architecture etc., is perceived like the attempt either to waste half of the customer's money doing marketing jibber-jabber instead of writing code, or to scam them by making them pay for something they don't need nor understand, and then disappearing with their money when it will come to actually writing source code. They don't know that you are a professional, and they even don't care.


How to take over sizable codebase, without having access those who implemented?

I've started a job as mobile lead in a 100employee company. Their Mobile products (iOS and Android) has been developed by external teams, and now they have decided to assemble internal teams, so I'm heavily involved in hiring ATM, both for iOS and Android. I will have teams of 5 people for each of the platforms. I've been manager before, but it's the first time I'm not starting code from scratch. My question is how to handle taking over code? The iOS code is about 50 classes, many of them over 700 lines. The code quality is around 5/10. What should be my first steps for taking over the code base? Little by little or major restructure first, or both using different resources?


How do you stay productive when dealing with extremely badly written code?

I don't have much experience in working in software industry, being self- taught and having participated in open source before deciding to take a job. Now that I work for money, I also have to deal with some unpleasant stuff, which is normal of course. Recently I was assigned to add logging to a large SharePoint project which is written by some programmer who obviously was learning to code on the job. After 2 years of collaboration, the client switched to our company, but the damage was done, and now somehow I need to maintain this code. Not that the code was _too_ hard to read. Despite problems—each project has one class with several copy-pasted methods, enormous `if` nestings, Systems Hungarian, undisposed connections—it's still readable. However, I found myself absolutely unproductive despite working on something as simple as adding logging. Basically, I just need to go through the code step by step and add some trace calls. **However, the idiocy of the code is so annoying that I get tired within 10 minutes of starting**. In the beginning, I used to add `using` constructs, reduce nesting by reversing `if`'s, rename the variables to readable names—but the project is large, and eventually I gave up. I know this is not the task I should be doing, but at least reducing the mess gave me some kind of psychological reward so I could keep going. Now the trick stopped working, and I still have 60% of my work to do. I started having headaches after work, and I no longer get the feeling of satisfaction I used to get—which would usually allow me to code for 10 hours straight and still feel fresh. This is not just one big rant, for I really do have an actual question: > Is there a way to stay productive and not to fight the windmills? Is there some kind of psychological trick to stay focused on the task, instead of thinking _“How stupid is **that**?”_ each time I see another clever trick by the previous programmer? The problem with adding logging is that I actually have to _understand_ what the code does, and doing so hurts my brain in an unpleasant fashion.


We're not a software company. Is a complete re-write still a bad idea?

I understand the reasoning behind Joel Spolsky's article "Things You Should Never Do, Part I", but I always see it referenced in regards in situations where the end goal is the production of software. What if I'm a developer who maintains an ecommerce site? My job isn't writing a retail platform, but instead putting it to use. In fact, this wouldn't even be a re-write, as such, but a big database and web design transition. The software our site is based on is written in classic ASP, and is fundamentally missing many features that customers expect from a current shopping site. Rather than continue to add these features in piecemeal, my gut feeling is that I should start to transition to a more modern platform. We would lose the customizations that we've made over the years, but frankly, many of this features already exist (and have have almost certainly been implemented better!) in the package that I'd like to switch to. Am I falling victim to the spirit of Netscape, or am I right in thinking my time is better spent in places besides making our tools do what we need? To clarify, this is the equivalent of switching blogging platforms for us. Any "development" that I do is essentially rewriting the front end of our website, while the back end is out of my control. Suppose WordPress development had stopped years ago, and was missing "modern" features like commenting, static pages, clean permalinks, etc. Sure, I could write a plug-in to add those things, but after a while, wouldn't it be better to switch platforms to something that had all those (needed) features built in from the beginning?


On the process of replacing an internal framework by a public one

I am working on several applications which depends on a framework which was developed by a prior engineer in the company. The framework was mainly developed and maintained in the early 2000s, and provide the same functionality available in `boost`, `Qt` or even `c++11`. I believe the framework was developed internally because the engineer in question is an autodidact, and that at this time he didn't knew a framework which will satisfy his need. Right now the framework has reached his limit, and we plan to switch to public and well known frameworks to do the same job. The issues we are facing :   * We have to deal with custom basic data structure implementations (strings, arrays)   * We are limited by the capacity to do event-driven or clean concurrent programming correctly   * Coupling and code complexity can be very high (due to people working on both framework and apps )   * Nobody even remotely want to maintain that library   * GUI application management is just inferior to Qt. For instance it is very hard (read _we still havent managed_ ) to make a CLI based on this framework. This is an issue when we want to create CLI executables which does some of the functionality of the UI. Basically **the application is very resistent to change**. One developer joked that _the source code became self aware, and that we have lost control_. We are a small team, and want to move away from our lib incrementally. We cannot go into full rework mode, as the application has features\bugs to be taken care of in the meantime. We are lucky that the management part of the company understood the issues and is in a cooperative mindset.   * What approach or strategy should we consider?   * What should we do in order to not be stuck midway with a unusable mutant?   * What are the opportunities? Is it teh occasion to improve the architecture? To improve testatibility? Or the development process?   * If several things come to mind, which one should be done first?


Dealing with bad/incomplete/unclear specifications?

I'm working on a project where our dev team gets the specifications from the business part of the company. Both the business management and the IT management require estimates and deadline projections, as they should. The good thing is that estimates are mostly made by the actual developers who get to do the required features. The bad thing is that the specifications are usually either too simple (it turns out you're left with a lot of question marks over your head because a lot of information seems to be missing) or too complex(up to the point that you can't even visualize where everything would "fit" in the app). More often than not, the business part of the specs are either incomplete or unaware of what can and can't be done (given the previously implemented business logic). Dev team is given about a day per new spec to give an estimate and we do try to clear uncertainties, usually by meeting up with whoever did the spec. Most of the times it turns out that spec writers haven't really thought everything through, and it's usually only when we start designing and developing that we end up in trouble, as a lot of the spec seems to have holes. How do you deal with this? Are you generous on estimates in advance?


How to integrate unit testing process into legacy software development process?

I'd like you to share your insights of how have you successfully turned the direction of rotting legacy code base to modular application design where it's easy and useful to add unit tests? What I'm here trying to find out is little bit different what has been asked before. I want to hear about your own experiences on actual systems. I'm interested in hearing what were the critical points which mattered most and resulted in improvement. I have been working for over five years with a 15 year old C/C++ code where I have seen the change from old C code built as a monolith application to modularized modern C++ application, now utilizing unit testing as a development process (to simplify a lot). As I see it, critical things to reach the success (as I see it), has been   1. highly talented individuals doing great things and prototyping (somewhat outside the official process) unit testing and promoting it to others    2. management willingness to invest in architectural development (not to enable unit testing, but for business reasons)    3. heavy investment in continuous integration system (which is not easy thing to setup for large legacy C++ application)    4. dedicated people to develop and maintain unit testing frameworks, integrations and training of developers    5. and of course the developers themselves who make the progress. So, **what worked** in your case, and **what did not?**


Are missed deadlines common in programming jobs?

It was my freelancer job at oDesk. I have done several jobs earlier in given time, but is was the first time I missed the deadline. It was a very lengthy job and I tried my best but I still missed the deadline. Now, I am very scared. Because it's my fault that I missed the deadline. My question is: Is this is a big concern or are missed deadlines common among programming jobs, so I shouldn't worry too much about this?


How would you rewrite/refactor this ?

Old application that is used by 50-60.000 paying customers. Company is several hundred people big. Application has a lot of business critical code (30% of all code) written in classic asp. Application has a lot more .net code. Application has a COM+ bridge for enabling asp to "talk" to .net Organization lacks some/a lot knowledge on what is causing the 10-20% server-reset per day (might be due to COM+ ?) There is no red line through the application; no architecture, no real patterns etc. The application has been like this for at least 5 years. The asp code base is increasing, slowly but certainly. I have read refactoring stories and I have knowledge on why you some of the times should not re-write a system. I would love for the old asp code to vanish as well as the COM+ component. But the pain is that no one really knows what is going on inside the asp classic code and the attitude inside all the teams are "this is just how it is". Down the line, this causes a lot of other issues like recruiting, dev effeciency, business needs that cannot be met, scale etc. With these little facts, does that justify a re-write of the asp code and the removal of the COM+ component ? How would you go about it ?


How to ask management to increase the number of programmers in the team without sounding incompetent

I am currently working for a small-medium sized company (~50 employees) as the sole IT staff. Recently, we are on track to replace one expensive yet critical legacy system in favor of an application I am currently working on during my free time at work. However, its been very busy lately with issues spawning left and right so the development of the application has been lagging a lot. How do I ask a very thrifty management to hire more programmers to help me build the new application without sounding incompetent. FYI. I do support of all our applications, setup and administration of the network and servers and in-house application development. EDIT 1: Nature of the Critical Legacy System for added information The Legacy System is the center of our operations. Basically, all our reports, notifications and data are being handled or are passing through this system. We want to replace it for a few reasons:   1. We are bleeding money paying for support that is rarely helpful (really terrible support) plus licensing cost.   2. Ridiculous cost for adding new features (500$ to adjust the width of a column in a report)   3. System Design/Architecture problems that cause the system to be slow and unscalable (Other branches find the system unusable because of how slow it is when used outside of the Office LAN)   4. Its a program made with access '97. Need I say more? It still works but its like trying to cut something with a dull blade in terms of performance


How can I estimate how long a project will take?

I'm working as a web developer and I want to be able to determine if I'm efficient. Does this include the how long it take to accomplish tasks such as:   * Server side code for the site logic with one language or multiple php,asp,asp.net.   * Client side code like javascript with jquery for ajax, menus and other interactivity   * Page layout, html, css (color, fonts (but I have no artistic sense!))   * The needs of the site and how it will work (planning) How can i judge how long it will take to complete a website? The site has CMS for adding and editing news, products, articles on the experience of the company. Also, they can edit team work, add Recreational Activities and a logo gallery with compressed psd download, and send messages to cpanel and to email. You are starting from scratch except JQuery and PHPmailer. How can I estimate how long the job will take, and how can I calculate the required time to finish any new projects? I'm so sorry for many scattered questions, but I'm in my first experiment and I want to take benefits from the great experience of those who have it.


Strategy for reading and understanding Node.js code

Concretely I am looking at this 2000 line file of what I will pretty arbitrarily call "mediocre" code.   * It's not well-commented   * variable names and function names seem consistently intelligent   * functions are not well-documented   * functions are good length In short: its lines and small structures are readable, but it's impossible to infer architecture or design at a glance. Most code I've worked on can be described thusly, to be fair. So I need to understand this. And work on it. This is an important skill in software development I'm still weak at, and it's extremely important when working in a nascent system. So my question is, when encountering foreign code like this that I am employing as client code but now need to understand and modify, what is a quick strategy for having a good understanding?


Techniques to re-factor garbage and maintain sanity?

So I'm sitting down to a nice bowl of c# spaghetti, and need to add something or remove something... but I have challenges everywhere from functions passing arguments that doesn't make sense, someone who doesn't understand data structures abusing strings, redundant variables, some comments are red- hearings, internationalization is on a per-every-output-level, SQL doesn't use any kind of DBAL, database connections are left open everywhere... Are there any tools or techniques I can use to at least keep track of the "functional integrity" of the code (meaning my "improvements" don't break it), or a resource online with common "bad patterns" that explains a good way to transition code? I'm basically looking for a guidebook on how to spin straw into gold. Here's some samples from the same 500 line function:               protected void DoSave(bool cIsPostBack) {       //ALWAYS  a cPostBack       cIsPostBack = true;       SetPostBack("1");       string inCreate ="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";       parseValues = new string []{"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""};                 if (!cIsPostBack) { //.......       //....       //....       if (!cIsPostBack) {            } else {            }       //....         //....       strHPhone = StringFormat(s1.Trim());       s1 = parseValues[18].Replace(encStr," ");       strWPhone = StringFormat(s1.Trim());       s1 = parseValues[11].Replace(encStr," ");       strWExt = StringFormat(s1.Trim());       s1 = parseValues[21].Replace(encStr," ");       strMPhone = StringFormat(s1.Trim());       s1 = parseValues[19].Replace(encStr," ");       //(hundreds of lines of this)       //....       //....       SQL = "...... lots of SQL .... ";            SqlCommand curCommand;            curCommand = new SqlCommand();       curCommand.Connection = conn1;            curCommand.CommandText = SQL;       try {         curCommand.ExecuteNonQuery();        } catch {}       //....     }      I've never had to refactor something like this before, and I want to know if there's something like a guidebook or knowledgebase on how to do this sort of thing, finding common bad patterns and offering the best solutions to repair them. I don't want to just nuke it from orbit,


How to convince/prove my manager that a rewriting is needed rather than a refactoring

My manager wants me to refactor a **gigantic amount of terribly-coupled, macroed, full of private namespace methods, hierarchy-perverted (even 10+ levels of inheritance)** code which hasn't been (indeed) designed with a "whole-vision" concept. I tried to explain to him that this code needs to be rewritten, not just refactored but he didn't listen and stated explicitly that **I need to refactor it.. somehow**. I could dive into all the "dealing with legacy code" books but I think nothing useful would come out. How can I convince him that a rewriting, instead of a refactoring, is actually needed?


Does anyone have experience with a difficult customer?

We have a reoccurring conflict with one of our larger and strategically important customers. The company (let's call them "C" for now) sells and distributes technical articles, everything from hardware components to hairdryers, and has more than 400000 products in their catalog. The product owner, who is also the head of product documentation and internal software at "C", has at some point in the 90's taken a course in software testing, and is now writing "Requirement specifications" as user tests. These are often contradictory and error prone, but she maintains that what she writes is what she want's, until she writes something else (in same imperative but ambiguous and abstract format). Furthermore, she demands a final budget for the project, and is unwilling to work in smaller iterations of budgeting. I'm looking for hints on how to control the development-process (and our own economy) and still provide the customer with a product that gives the company most value-for-money. Normally, I'd start a project by identifying goals of the project and business use-cases of the organization - and then deriving scope from those goals, using User-stories. The details (specifications) of how user-stories should be implemented, is decided at specifications prior to the sprint including the respective user-stories. This has repeatedly proven to result in better products and greater ROI for the customers. Does anyone have experience of knowledge of techniques that can be used to "Reverse engineer" imperative user-tests, or any other input on how to handle the situation? Historically, she has been allowed to completely dominate the development process, which has blown our budgets and taught her that she is in control of our process. Our management has now asked me to control (and defend) the development process. They told "C" that there will be used no more hours than the agreed budget, regardless of how "done" she (the product owner) feels that we are, which of course will be my leverage. She will become defensive, even aggressive to get things her way - any sound arguments based on professional reference or experience would be of help. * * * Follow up: I thought I'd follow up in case anyone stumbled across this post with similar problems: We have turned the communication around, and are expecting to deliver the next project within budget and on time (I'll edit this post again if hell breaks loose later on). Initially, I focused on creating trust between me and the Product Owner. That meant choosing the relevant battles, and presenting myself as her tool to get most value for her money. Requirements are still expressed in more or less the same way (although she is open for input about syntax, she is firm about the format: Word Documents and Emails), but we are slowly trading control with visibility regarding the development process. I managed to persuade her to participate in weekly meetings for project status, backlog grooming and prioritization. Between each meeting, she gets the chance to test the newest revision, which makes her test-feedback what used to be an object for discussion, the most valuable feedback for the backlog grooming and prioritization. By having a head-to-head talk about the feedback from the tests, we're able to "weed out" misunderstandings, contradictions and scope creep before it leaks into development. The trust between us enabled us to have a constructive talk about each others organizations and the processes and intentions of these, which opened my eyes to quite a big part of the problems being our lack of capacity (professionally, theoretically, and methodically). The product owner has called management to personally compliment the progress we are making, so I'm calling success on these first steps - but constantly watching the scope and progress, as to not "rest on ones laurels"


What defines code readability?

> **Possible Duplicate:**   >  How would you know if you've written readable and easily maintainable code? It is often said that readability is perhaps the most important quality- defining measure of a given piece of code for reasons concerning maintainability, ease of understanding and use. **What defines the word _readable_ in context of program source code?** What kind of definitive aspects are there to code readability? I would be grateful with code examples of _readable_ code, along with reasoning why it is readable.


How to gain understanding of large systems?

> **Possible Duplicate:**   >  How do you dive into large code bases? I have worked as a developer developing C/C++ applications for mobile platforms (Windows Mobile and Symbian) for about six years. About a year ago, however, I changed job and currently work with large(!) enterprise systems with high security and availability requirements, all developed in Java. My problem is that I am having a hard time getting a grip on the architecture of the systems, even after a year working with them, and understanding systems other people have built has never been my strong side. The fact that I haven't worked with enterprise systems before doesn't exactly help. Does anyone have a good approach on how to learn and understand large systems? Are there any particular techniques and/or patterns I should read up on?


Taking part in an open source project

I am new to open source development. I want to add some functionality to an open source project PRISM. But I couldn't find any developer guide or code architecture guide sort of a thing for it. How should I begin use its code. I have just imported the archive file in Eclipse and began reading the code. I want to ask whether there are any specific tools which will help me?


How to handle not-quite-legacy code?

This is a frequently asked topic... And I have read through many posts, articles and am about to read the book `Working Effectively with Legacy Code`, but before that and mainly because it will take more than a couple days for book to arrive, and I would like to keep my sanity in check, here's the question: I am looking at not-that-old (1-2 years) code by a company I recently joined, and I have found so many bad practices in there that it's almost heart breaking... Massive code duplication, global variables (which are inconsistently used), and things like using a factory class to instantiate various objects that extend a parent object... and then calling methods that don't exist in the parent, but are defined in all the subclasses... The code works... It's rigorously QAed and bugs are at a minimum, which is fine... but I cringe so much looking at the code... I recently asked my boss if I could refactor the entire codebase, he asked how I would be able to guarantee the changes will not break anything, I asked we could invest some time to create _real_ unit tests, as their so called unit tests are actually end-to-end tests, so we have to trace the debug log very time something breaks. He said we don't have enough time to create the unit tests (actually the code isn't very unit testable, since there is so much tightly couple code... and I would've had to pretty much re-write most of the classes), so in effect I couldn't even do minor changes to code if it isn't listed as a bug in the issue tracker... What I'm doing right now is alot of copy and pasting... then fine tuning that since the logic isn't exactly the same... What can I do? :/ Sorry I think I'm just venting here, and there is nothing I can do in the short/medium term... sigh


How to redesign the UI of a large project?

I'm currently working at a quite big Android project (a social network, you can see it here if is useful to answer the question). We decided to restyle the whole app, changing all the UI design. The code I actually have is complex, there are many controllers, and it's a little messy too. Is it "better" in terms of time and code cleanliness to take one controller per time, and rewrite it entirely, or to _modify_ one controller per time? The layout change entirely anyway, so for that I know I've to restart from scratch. Maybe it could seem a stupid question, but with the "time" variable I really can't see the best way.


When does extracting methods from code stop to make sense?

I am currently studying the refactoring methods defined by Marting Fowler (http://refactoring.com/catalog/). He states a tip for replacing chunks of code by a single method that does that job. So far, I agree, as we all learned about the downsides of Spaghetti-code. But the example for this rule looks as follows: Replacing                   void printOwing() {           printBanner();                //print details           System.out.println ("name:  " + _name);           System.out.println ("amount " + getOutstanding());         }      by                   void printOwing() {           printBanner();           printDetails(getOutstanding());         }              void printDetails (double outstanding) {           System.out.println ("name:  " + _name);           System.out.println ("amount " + outstanding);         }      Is the readability and thus, the immediate understanding of the code really better in the latter example? There is no indication about what "details" are in reference to "owing". For example, will the name be listed or is there another method printName()? Is the interest listed as well? I would need to search for the printDetail() method's implementation to find out about that. The method printOwing() itself is already a print-method. Would it not be easier for maintaining the code to just list the System.out.println()'s in this method commenting the purpose as in the first example instead of "scattering" the code this way? Is there a rule of thumb about when to stop "methodizing" and when it still makes sense?


How to convince my boss that quality is a good thing to have in code?

My boss came to me today to ask me if we could implement a certain feature in 1.5 days. I had a look at it and told him that 2 to 3 days would be more realistic. He then asked me: "And what if we do it quick and dirty?" I asked him to explain what he meant with "quick and dirty". It turns out, he wants us to write code as quickly as humanly possible by (for example) copying bits and pieces from other projects, putting _all_ code in the code-behind of the WebForms pages, stop caring about DRY and SOLID and assuming that the code and functionalities will never ever have to be modified or changed. What's even worse, he doesn't want us do it for just this one feature, but for _all_ the code we write. > We can make more profit when we do things quick and dirty. Clients don't > want to pay for you taking into account that something _might_ change in the > future. The profits for us are in delivering code as quick as possible. As > long as the application does what it needs to do, the quality of the code > doesn't matter. They never see the code. I have tried to convince him that this is a bad way to think as the manager of a software company, but he just wouldn't listen to my arguments:   * **Developer motivation:** I explained that it is hard to keep developers motivated when they are constantly under pressure of unrealistic deadlines and budget to write sloppy code very quickly.   * **Readability:** When a project gets passed on to another developer, cleaner and better structured code will be easier to read and understand.   * **Maintainability:** It is easier, safer and less time consuming to adapt, extend or change well written code.   * **Testability:** It is usually easier to test and find bugs in clean code. My co-workers are as baffled as I am by my boss' standpoint, but we can't seem to get to him. He keeps on saying that by making things more quickly, we can sell more projects, ask a lower price for them while still making a bigger profit. And in the end these projects pay the developer's salaries. What more can I say to make him see he is wrong? I want to buy him copies of Peopleware and The Mythical Man-Month, but I have a feeling they won't change his mind either. A lot of you will probably say something like "Run! Get out of there _now_!" or "I'd quit!", but that's not really an option since .NET web development jobs are rather rare in the region where I live... * * * # Update Wow, I hadn't expected to get so many answers. Thank you all for your contributions and your opinions! As quite a few of the answers and comments point out, the type of company and the type of projects play a big role in this topic. I have explained a few things here there in comments on some answers, but it's probably better to add it here as well. The company I work for is rather small. We have 4 developers, 1 designer, 1 boss and 1 jack-of-all-non-technical-trades (the boss' wife). The projects we do can be divided into two categories:   1. Smallish websites built with our own CMS or e-commerce framework (65%)   2. Middle-sized web applications (35%) So while a lot of our projects are rather small, they are built on top of the same system. This system is about 4 years old and the code base is below par to say the least. It always is a dread to add new functionalities or modify standard functionalities for specific customers. One of the goals set by the boss is to start moving our focus to product development. So that means we'll be developing bigger applications that will serve as the base for other projects or are something SaaS-like. I totally agree that doing things quick and dirty can be the best solutions for certain projects. But when you are extending an existing CMS that will be used by all sites you will develop in the next few years or building a SaaS product from scratch, there are better approaches I think.


How to code efficiently?

I often compare my code to others and I find their solution more efficient and shorter than mine. Although both solutions work, I can't help it but wonder if mine is not adequate enough. As a result, sometimes I get a mental block when I'm about to start a project because I keep wondering if my solution is the best way. Are there any steps one can take to code in a more efficient manner?


What is the most effective way to add functionality to unfamiliar, structurally unsound code?

This is probably something everyone has to face during the development sooner or later. You have an existing code written by someone else, and you have to extend it to work under new requirements. Sometimes it's simple, but sometimes the modules have medium to high coupling and medium to low cohesion, so the moment you start touching anything, everything breaks. And you don't feel that it's fixed correctly when you get the new and old scenarios working again. One approach would be to write tests, but in reality, in all cases I've seen, that was pretty much impossible (reliance on GUI, missing specifications, threading, complex dependencies and hierarchies, deadlines, etc). So everything sort of falls back to good ol' cowboy coding approach. But I refuse to believe there is no other systematic way that would make everything easier. Does anyone know a better approach, or the name of the methodology that should be used in such cases?


Should I start refactor this messy project even if I know I won't have the time to completely refactor everything?

I have this older project (1st release 2005-ish) I've inherited that a customer asks me to fix or add something to now and then. It's a bit of a mess architecture-wise. Basically it's an ASP.NET WebForms site where 90% of the logic is in the code behind file of each view and the other 10% is in the data access layer. Although "layer" might be the wrong word, since all data access is just piled into one service, an all-in-one 3500 line class with ADO.NET code. All other parts of the site use this one service for everything. I'm still a newbie myself, with about 2 years of work exp. And every time I come back to this project it feels worse because I've learned and seen how to do architecture better in other projects. So although I've been smelling the bad code in this project pretty much since day 1, it's now almost unbearable. No business logic is testable, and there are always smaller bugs I know would've been caught earlier with tests in place and a better defined business layer. So my dilemma is that I want to refactor this using MVP (for example https://github.com/webformsmvp/webformsmvp), move the logic from code behind and data access service into a business layer, and at the very least split the big repository class into smaller repositories. The problem is that the customer is not willing to dedicate the time or money for this amount of work in one batch so I'm considering refactoring bits and pieces as I come across them so that this will be refactored over a longer period of time. However I'm not sure if I should mess up the codebase even further by introducing a lot of new concepts, architecture and frameworks if I'm not sure that I can complete the work myself. It feels kinda bad leaving a project in a kind of partly- refactored state where the guy after me might not now where to begin or how to continue the refactor (or if he even will and continues down his own path instead).


If TDD is design, how do you know your TDD is well designed?

Given a large group (50+) of programmers:   * All given the same problem,   * All using Test-Driven Development (TDD),   * All pair programming,   * All doing group-based code review, I have personally seen the wide spectrum tests that are possible for the same problem, even on the first test. So, if TDD is design, how do you know your TDD is optimal for the current problem, and how do you know it is not? Following the first test, is the approach for reviewing the consecutive tests any different, and if so, how?


How do you find your way in deeply nested, interfacey code?

I know most people hate flat and long functions, and hate when code is not full of ISomethings. The problem is that I guess my mind works in different way, and I always have problems with that type of code in any non-trivial solution. So, since most of people enjoy explosive number of functions, can you describe what is the preferred method when dealing with unknown code-bases written in this way? So far, for me, it looks like: I have a object with interface IFoo, great, I need to extend it with method Bar1. Reverse lookup, we land nowhere, global search on who implements IFoo, it's Baz1, Baz2, Baz3, Baz4, an they are created by 3 class factories. So we start one by one, definition of Baz1, looks nice, but it's behaviour is completely dependent on parameters used when object was created through class factory. And what's worse, it's just a wrapper around some other functionality of yet another class with IFooBar. Which again uses some internal implementation of classes with ISomethingElse, which again turns into an explosive graph. How do you navigate all that effectively?


OO - are large classes acceptable?

Despite many years in IT, I still struggle with OO design. One particular problem I seem to keep ending up with is large classes, often containing many hundreds of lines of code. The OO world talks a lot about SRP, and I _could_ argue that these large classes I end up with are each handling a single responsibility. The complex nature of the app (a scientific data processing system) means that one of these responsibilities requires an awful lot of code! E.g. a class might have a single public method `Calculate()`, but there could be 15-20 or more private methods to support this operation. Where possible I will extract methods into separate classes for re-usability, but often there is little or no scope for this. Part of me says I should split these large classes up purely to improve readibility (e.g. grouping similar methods into their own classes), but the times I've done this feels like a wasted exercise - all I've really done is spread the methods around, created more class dependencies, and made things a little more difficult for other devs to find stuff. But then I read articles where developers talk about how all their classes are small enough to fit on the screen without scrolling, and I worry that I'm doing something wrong! In a previous job, I worked on a system where it had been OO'd to the extreme, and it was common to see classes containing just one method, often with no more than one or two lines of code. Personally I found this difficult to find my way around the code-base and to debug, and for this reason (and sheer number of classes) I could argue that it becomes more difficult to maintain - not the aim of good OO design. I guess it's down to personal taste. So, is it acceptable to have large classes, or can you suggest other ways that I could deal with them?


Who should provide the Requirement doc / SRS?

I am creating a Mobile application (CRM) for another software company. They told me they need these these stuff from here and there, within 15-30 minutes. But they never provided a detailed client requirement document in writing. I have been asking this for number of times, but still no. As soon as I started working I realized what they told by mouth is not even 10% of the work. They first asked me to come up with my own design which is similar to another app they mentioned. I did, 100% similar design to the app they mentioned. Then they said they don't like it so they gave me their design. I completed there design and submitted it. Now they again say they don't like their own design and asking me to do another design! Apart from that, they are asking for some "Activity Sliding Animations", "Windows Like UI" etc now. In order to do this, I need to remove the entire work I did and start from the scrach, because it can be done by Fragments and mine contains Activities. I even have no idea how the backend will be. Even after one month, we are still designing and changing the designing (Because you have to send at least 3-4 mails, contact at least 2 of their team via phone to get an answer. Very slow communication). And will they pay for the trashed designs? I don't think so. So what about the other customers of mine which I said 'no' due to the lack of time I am going to have because of this project? I feel almost crazy. They always say come up with your own idea, but that is very risky in this situation. If my idea is not accepted, waste of time and money. I am so tired of this, I wasted lot of time designing two 100% different designing, and about to proceed to 3. Since I don't know how the software will be, I haven't done a cost estimation as well. So my question is, client is not supposed to give you any documented requirement? May be an SRS? (What I meant by SRS is, complete detailed document about functionality they need. Including these 'animation' stuff, because I have no super power to guess) The requirement doc they provided is useless, it only says "update", "delete", "edit". All my other clients did provide complete data, some even provided drafts of the design process, except this one. They should at lease ptovide me their requirements in details, in writing, I need some advice here.


How to deal with bad code?

> **Possible Duplicate:**   >  Techniques to re-factor garbage and maintain sanity?   >  Code maintenance: keeping a bad pattern when extending new code for being > consistent, or not? I was hired about 6months by a company that uses Agile, but after learning the code I've realized that it's bad code - methods with over 100 lines of code, duplicate code, methods that says it does one thing but does a few other unrelated things. It works, but the more we update it, the more it become like a house of cards. Refactoring one little thing requires changing lots of others, which can make program unworkable. What did go wrong and is it possible to fix it? I thought agile was supposed to make a good code.


How many days is it normal for a new hire programmer to take to get up to speed?

I have just landed a role as a C#/Asp.Net developer at a large software house. I have previously worked at a much smaller software house for about two years but it was a varied/mixed role there, and here the asp.net applications we have are a factor of 10 or so larger. As seems to be the norm, I have been given the task of fixing bugs. At the moment I am just trying to understand the system. How long , in your experience , does it "roughly" take ( and is generally acceptable) for a new developer to get up to speed? It of course varies from company to company but as a general rule, when you have hired someone/have worked with someone new, how many days/weeks would it have been normal for them to get to grips with the system?


Time required to start coding at a new company

I am a software engineer for 4 years, and I just changed my company for the first time. Company works with pair programming, and it's been 3 days, I couldn't even write a single line of code. It's so frustrating for me because I was very productive at my previous company. The codebase is large, they are using 5-6 languages/tools that I am not familiar with, like rspec, haml, jasmine and others. But still, I feel awful. This weekend I created UML to get better understanding of the application, but still I am guessing I'll not be able to write decent amount of code this week. **Is this normal?** _What is your experience when you change your job, and dive into a large codebase written with languages/libraries you are not familiar with._ **Of course I am not asking for _exact_ time required, but past experiences or things to make the process would be great.** Btw, I've already read below questions&answers, How do you dive into large code bases? http://stackoverflow.com/questions/215076/whats-the-best-way-to-become- familiar-with-a-large-codebase http://stackoverflow.com/questions/214605/the-best-way-to-familiarize- yourself-with-an-inherited-codebase **UPDATE** All great suggestions! I just came from work, I've worked a lot! _**About pair programming:_** Generally they write code, and I am trying to not miss even a second! If I try to write the code, I know it's gonna take forever, because I don't even know which files should I edit, but beside that, as I said, they are using 6-7 languages/frameworks that I'm not familiar with, and learning all these syntaxes at one is not easy. _**How well the company prepared for engineers:_** I can't say they are well organized, they kind of expecting me to start writing code immediately. _**Taking notes, being proactive:_** I'm always taking notes when they write a new command/or anything about data models. My peers are very smart and kind people, and I'm trying to ask lots of questions, even **lots of stupid questions** sometimes. _**Is this common?:_** @Telastyn, thanks for your answers, it made me feel a little better. It seems like my problem is not that uncommon, but I was really productive before this job, and now I really feel useless and not smart. I hope I can start solving bugs/implementing issues very soon. _**About frameworks/languages they use:_** I was really honest about that, I didn't say I know something that I don't know actually. But I wasn't expecting that much different things, and since I started working at the day I accepted the offer, I didn't have time to prepare myself. @Southpaw Hare, thanks alot for sharing your experience. You are absolutely right. There is no guarantee that I'm going to learn all of these stuff, but I'm trying. At the end, it's is hard to learn all of the syntax at once, and I think that is the main problem too. Because I can navigate in ruby code well since I know that language, and I navigate in js codes thanks to browser inspectors, but the problem is writing the actual codes with the frameworks/languages I don't know.


What to do with bad source code?

I have been contracted to modify an application for a software company and the source code is quite frankly, a mess. It's not commented much and the author is inconsistent with coding conventions. The guy seems experienced , but his style isn't great. What do you suggest doing to get the project done properly and to make thing easier? **Edit** I didn't mean to say _rewrite_ , I've been hired to modify the the UI in a certain part of an app. I don't think that the client cares so much abut what I do to the source code , so long as it works and so long as it's decent quality code. That said, I've expanded some > if(condition) ? TrueResult : FalseResult; for readability. While I don't think those particularly make bad code, there is an inconsistency in the style throughout the code and a few "left over" constants that don't seem to be used anywhere. There are also some arbitrary numbers where constants would Have been wise for readability's sake. It's not as bad as I initially had thought, but I still have some questions for the original developer.


How to handle bad code base

Company I worked for recently inherited a custom CMS system that is extremely buggy, no documentation, and unreadable logic in everything. The client will not have the budget to re-platform for another 6 months or more. The issue we are having is fixing bugs generally requires either patching it or completely rewriting the entire functionality/feature and is extremely hard to estimate time. Should we continue to patch until they re-platform or refactor entire functionality and add documentation?


Software rewriting alternatives

We have a legacy system to bring up-to-date because:   1. It uses an unpopular (amoung our users) non-sql database (Btrieve)   2. Provides only a text interface   3. Is written in Turbo Pascal (but compiled in free pascal) which is hard to recruit/retain developers to maintain it To give you an idea of the scale, the code base is 15MB over 756 files. All the studies I've looked in to such as those listed here suggest it is vastly more expensive to rewrite than to adapt what you have. If I thought we could encapsulate the legacy stuff behind a web service and then design new client(s), that would be fine. But I'm stuck with this legacy database which 90% of those 756 files reference. We even attempted replacing the low-level DB code with code to convert to SQL, and while it worked fine, it was too slow because the code is still accessing records one at a time generating far too many SQL statements than it would need. Plus this approach does not allow any improvements in the DB design. When faced with such an upheaval as replacing the DB that is referenced so heavily in code and the other requirements listed, can it still pay to reuse or are we better off treating the new version as a whole new product and just listing the current systems abilities as requirements (bearing in mind no handy requirements doc exists for the current system). I know it's too hard to give a definitive answer on this, so just any advice would be appreciated especially if you've experienced a similar situation.


Starting a recurring project from scratch

We have a project that keeps recurring. The client expects us to run a website twice a year and this is happened for the last year and a half. I took the last working copy and based our latest website on it. Now, a co-worker has suggested that next time we should start from scratch instead of fighting against legacy code. I have already started refactoring the existing code and so have the other developers who were on the project. The code is cleaner than before and it meets client needs. The refactoring was ongoing while we developed new features. What are some good reasons to advise against starting from scratch?


How to convince my boss to improve code quality?

The place I'm working for is a service provider. We have a lot of services, which are written to deal with deadline, so their code are really terrible:   * No coding convention, everyone codes in his own style   * No unit testing (which is really bad)   * No refactoring (which is truly worse)   * No automation build/deployment  etc and these code are used again and again, so bad code continue to spread all over my department. I really want to set up a standard quality for our code, by requiring everyone to follow "rules": every line of code which does not follow convention will be rejected, and every function of code which does not pass unit testing will not be committed,...But I don't know how to convince my boss to allow me to do this. I'm relatively new comer, so inspiring people from my works is really hard, and I think it's easier if my boss support me to this. Thank you very much for your advices


Deciphering foreign code

What is the best strategy to go about understanding some one else's code for a medium sized project, if the code is not well documented and does not adhere to many coding standards?


What can I do with a poorly coded vb6/access2003 project?

I'm currently working on a big vb6 project and since I'm not the leader of the team (we're just 2) but I'll be in the near future I've started wondering about improving the code and the data structure. There are 5 poorly coded projects with a total of 60-70 forms. The code is really bad, I've tried to improve it with the use of functions to avoid repetitions but it's still awful. It would take me a lifetime to just describe all the stuff that are wrong. The database is even worse, there are 5 .mdb (access 2003) badly designed, the person who created them doesn't know what normalization is and so Index are random, no relationship between table (some table that should be related are on different Dbs...) and so on. I feel bad for users that use this thing and whenever they type in something wrong they need to relaunch the application because there is no control on errors. Beside that it's slow as hell (DBs are on a local server, the apps are local). Where should I start? I was thinking about getting rid of Access, but what's the point if the structure has been conceived so badly?


Gathering requirements from confusing co-worker

I'm working at my first software internship, and it's great so far. One problem I'm having, however, is getting clear requirements from my co-worker (we'll call him Person A) who assigns projects. Normally, I get requirements from a co-worker/manager, design/code/test my changes, and eventually commit them for integration in our product. The problem is that, fairly often, it is virtually impossible to get clear requirements from Person A. I will ask questions to better understand what problem is being solved, and one of the following often happens:   * Person A will interrupt mid-sentence to think out loud, derailing the current conversation. Sometimes this is for good reason. Example: > Me: "So if there should be a table mapping Bazzes to Foos, what if there > were-" > > Person A: "Actually, I wonder if we actually need to add a BizzleContainer > in this here." > > [I wait a few minutes for A to think through their unrelated thought, and > try to help solve it.] This will repeat a few times, and by the time the conversation is done, I'm more confused than when we started and half an hour has gone by, so I don't want to waste the person's time any longer. Note that I wouldn't mind if the interruption was related to the current topic, but it seems that interrupting someone to take a conversation down a completely different path is poor form.   * Person A often barely understands the requirements. These factors add up to wasting a lot of development time based on simple misunderstandings of what needs to be done. Co-workers B and C are capable of clearly expressing what needs to be done, but they are often overrun with demands for their time. So rather than annoy B and C to get requirements clarifications, co-workers often go to A, and get less than satisfactory results. How do you wring clear, correct requirements from someone who understands them but does not have the inclination to take the time/effort to explain what they actually are?


How To Deal With Terrible Design Decisions

I'm a consultant at one company. There is another consultant who is a year older than me and has been here 3 months longer than I have, and a full time developer. The full-time developer is great. My concern is that I see the consultant making absolutely terrible design decisions. For example, M:M relationships are being stored in the database as a comma-delimited string rather than using a conjunction table to hold the relationships. For example, consider two tables, Car and Property: Car records:   * Camry   * Volvo   * Mercedes Property records:   * Spare Tire    * Satellite Radio    * Ipod Support    * Standard Rather than making a table CarProperties to represent this, he has made a "Property" attribute on the Car table whose data looks like "1,3,7,13,19,25," I hate how this decision and others are affecting the quality of my code. We have butted heads over this design three times in the past two months since I've been here. He asked me why my suggestion was better, and I responded that our database would be eliminating redundant data by converting to a higher normal form. I explained that this design flaw in particular is discussed and discouraged in entry level college programs, and he responded with a shot at me saying that these comma-separated-value database properties are taught when you do your masters (which neither of us have). Needless to say, he became very upset and demanded I apologize for criticizing his work, which I did in the interest of not wanting to be the consultant to create office drama. Our project manager is focused on delivering a product ASAP and is a very strong personality - Suggesting to him at this point that we spend some time to do this right will set him off. There is a strong likelihood that both of our contracts will be extended to work on a second project coming up. How will I be able to exert dominant influence over the design of the system and the data model to ensure that such terrible mistakes are not repeated in the next project? A glimpse at the dynamics:   I can be a strong personality if I don't measure myself. The other consultant is not a strong personality, is a poor communicator, is quite stubborn and thinks he is better than everyone else. The project manager is an extremely strong personality who is focused on releasing tomorrow's product yesterday. The full-time developer is very laid back and easy going, a very effective communicator, but is someone who will accept bad design if it means not rocking the boat. Code reviews or anything else that takes "time" will be out of the question - there is no way our PM will be sold on such a thing by anybody.


How to understand codebase of complex opensource application

I'm trying to develop a new feature for open source application. But the existing application uses different APIs like Qt and KDE3. And more over the existing files are also very complexand depend on each other. e.g I wanted to create an object of PlaylistBox::Item but its constructor is protected. So I searched the codebase using grep, there is one line that uses this class, but then there are initialization variables of this constructor. Now how do I create these variables when I don't have any use and way to initialize them. My constructor on github,               SyncList::SyncList(QWidget* parent)//: PlaylistBox(player,parent,stack)      now how do I initialize these variables of PlaylistBox. This is the link to PlaylistBox constructor               PlaylistBox::PlaylistBox(PlayerManager *player, QWidget *parent, QStackedWidget *playlistStack) :      and this is PlaylistBox::Item in same file playlistbox.cpp#L775               PlaylistBox::Item::Item(PlaylistBox *listBox, const QString &icon, const QString &text, Playlist *l)      This was just an example case where I face problem. I want to know the basic approach to read such huge and interconnected codebases where one class inherits another and so on. How do I figure out which class should I use. I keep on trying different values hoping one of them will fix it, but clearly I'm doing it totally wrong way.


What is a good way to refactor a large, terribly written code base by myself?

> **Possible Duplicate:**   >  Techniques to re-factor garbage and maintain sanity? I have a fairly large PHP code base that I have been writing for the past 3 years. The problem is, I wrote this code when I was a terrible programmer and now it's tens of thousands of lines of conditionals and random MySQL queries everywhere. As you can imagine, there are a ton of bugs and they are extremely hard to find and fix. So I would like a good method to refactor this code so that it is much more manageable. The source code is quite bad; I did not even use classes or functions when I originally wrote it. At this point, I am considering rewriting the whole thing. I am the only developer and my time is pretty limited. I would like to get this done as quickly as possible, so I can get back to writing new features. Since rewriting the code would take a long time, I am looking for some methods that I can use to clean up the code as quickly as possible without leaving more bad architecture that will come back to haunt me later. So this is the basic question: What is a good way for a single developer to take a fairly large code base that has no architecture and refactor it into something with reasonable architecture that is not a nightmare to maintain and expand?


It's my first week of work, I've got the code checked out and am told to look around it until I have an assignment next week. What do I do?

> **Possible Duplicate:**   >  How do you dive into large code bases? I've been in this situation before and I kind of just poke around the code while really surfing the internet. I care about this job though, and I want to excel. What kinds of things should I look for? How should I go about starting to learn the framework? In my experience, I learn by doing - but clearly they expect something out of me or they wouldn't give me this week to figure out the code.


How to understand and debug legacy software?

> **Possible Duplicate:**   >  I’ve inherited 200K lines of spaghetti code — what now? Not long ago my company placed me in a team that deals with some of the most complex bugs that are in production. The thing is that almost all of these bugs are in legacy applications I am having a really difficult time understanding and debugging, and these are some of the reasons:   * Bad software design   * Lots of code duplication   * Misleading comments   * Bad names    * No documentation at all   * The creators of the software no longer work in the company   * Really big classes and methods, very badly programmed   * Bugs are very badly documented and the operations team makes very poorly documented reports on the issues that occur. It is very time consuming and frustrating. As a TDD and ATDD developer, I try by starting writing tests to triangulate and pinpoint the problem, but there are so many things that need to be mocked that it is very difficult. Also the business analysts don't provide criteria for this software since they don't even know it themselves. The only thing they say is that it needs to be fixed. I thought that maybe here I could find somebody with experience in legacy software that could give me some advice on how to deal with bugs in an environment like this. I feel I am doing software archeology when working with this. Also it is very stressful and this big amount of frustration makes me feel useless and unproductive since it takes weeks sometimes to fix bugs. I always worked green field development and this is the first time I am doing production support. I would really appreciate some advice.


Study Doom 3 Source Code

> **Possible Duplicate:**   >  How do you dive into large code bases? I want to study the source code of a large project (for example, the Doom 3 source code) and I would like some help determining how I should navigate the code. How should I start reading it? Should I find a main() function and go on from there? Do you have any other tips that may help me?


What is the norm for introducing new hires to a code base?

After college I worked at one company for 6 months, and I've just now joined another one, bringing the grand total in my career so far to two. So the first company had a few hundred thousand lines of code, maybe, across a couple hundred files. There was absolutely no introduction to where to start learning the organization of the code base...just, "Here, go find the source of this bug." It was horrifically intimidating. I did slowly start to find my way around the front end, but 6 months in I was only _just_ starting to be introduced to the server-side code. I was really happy to leave the company...I was relatively terrified of trying to find my way around the back end, which was by far the larger part of the code. (I'm a front end developer whose work occasionally requires me to make minor modifications to the back end.) But this new company...it's a big one, focused around a website...think Amazon. 2000 employees. I would estimate millions of lines of code but there's no way for me to know for sure. One of my coworkers showed me a 3-dimensional graph of the file dependencies...I almost fainted. It looked like this: ![enter image description here](http://i.stack.imgur.com/yh6ek.jpg) The coworker was chuckling fondly as he rotated it and zoomed around. Yet again, there is no guide, no introduction, just....here you go, get coding. I am horrified and very stressed. The job seems great in every way besides this, and I am quickly starting to worry that I am not competent as I seem to be the only person who finds this intimidating. What are other people's experience with this scenario? Is it just me? What have you done in the past? How long does it take you to get a firm grasp on things? I have asked my coworkers this question and they said "a couple weeks." A COUPLE WEEKS TO LEARN A THOUSAND PLUS FILES, HUNDREDS OR THOUSANDS OF LINES LONG EACH??? Am I incompetent? Just say it.


How do you approach a new project where the code has already been written?

> **Possible Duplicate:**   >  How do you dive into large code bases? I'm about to take on maintenance and enhancements of a fairly large and complex Java EE project with a Javascript front end. I'm trawling through the code trying to work out how it all hangs together but I wondered if any of you people have come up with a methodology for doing this that works best for you? do you start with the UI and work backwards to the database? Or take discrete 'slices' through the system for particular bits of functionality? Do you take notes? How do _you_ get up to speed with a new project?


How do you go about understanding others' code?

What do you do to understand some code that you didn't write? Or code that you wrote long time ago and don't remember what it does anymore. Do you have some technique that you go about? Do you analyze the structures first, or the public methods, or do you draw flow charts, etc.? Or do you fire up the debugger and just step through it? Or do you just ad-hoc your way through until you understand it?


Prevent code from getting mess

I am a student and a freelance programmer. These days I am developing a software in VB6 which has recently crossed 100KB of source code. The main problem, I face is, many times I have to refactor my existing source code which is really very boring. Also the size of my code base is not very big (only 100KB). What are the techniques I should you use to prevent my code from getting mess?


General approach to re-factoring an large, very badly written legacy system

> **Possible Duplicate:**   >  Techniques to re-factor garbage and maintain sanity?   >  What is a good way to refactor a large, terribly written code base by > myself? Really open question here. I'm not after an answer.. only advice. Any past experience people have had with re-factoring legacy systems that they could pass on would be amazing. Here's some information about the software I am to re-factor (you'll cringe!):   * Web application   * Database driven (MySQL)   * PHP4 and PHP5   * Most of the code is PHP4   * Nearly all the code is procedural   * Code that is PHP5 isn't OO.. example: 10,000 line+ file with one class and one function   * Global variables used everywhere   * No source control was used to write the software (you can see from the comments in the code)   * Massive amounts of code repetition   * No separation of concerns - user interface and logic is combined everywhere   * Application relies on order of database tables   * Few code comments   * 250,000+ lines of code   * Application in heavy use Basically, the software is our core product and I have been hired to do a major re-factor (amongst other things). It's a massive task and I can't just dive in and fix all the little things.. I need an overall strategy. I've written some scripts to tidy indentation up, removed commented-out code everywhere and made the project into a repo but now it's time to do the real stuff. I kind of have a vague idea but not sure how to go about it. I could somehow leave the current code alone and write some layer of software over it that abstracts away from all the horribleness. It would be good if the new layer was some sort of MVC architecture. At the same time I would go into the current code, remove redundancies because otherwise the new layer would be using bad code anyway so the code could slow down even more. As you can see.. need some clues/hints/tips/advice/experiences! Thanks very much :).


Newbie to Intermediate PHP Programmer - How to Deal with Maintenance Spaghetti Code?

> **Possible Duplicate:**   >  Techniques to re-factor garbage and maintain sanity? So I was given this project for a client, but the person who wrote the site originally did a terrible job (worse programmer than I am). They've got all sorts of kludgy fixes and I'm having trouble figuring out what variables are doing what. Like, for example, one section says this:               $id = "";     $cuid = "";     session_start();     if (isset($_SESSION['id'])) {         $id = $_SESSION['id'];         $cuid = $id;         $valid_user = $_SESSION['valid_user'];         $cuname = $_SESSION['cuname'];         $website = $_SESSION['website'];         $site = $website;         $email_contact = $_SESSION['email_contact'];          }     $cuid = $_GET['cuid'];     include_once("dbfunctions.php");     if (isset($_SESSION['id']))  {         $cuid = $_SESSION['id'];     } elseif (isset($cuid)) {         $_SESSION['id'] = $cuid;     }      Which just seems to repeat the same thing, over and over. How am I, as a newer programmer (about a year experience, mostly in Python, now with about 6 months experience in PHP) supposed to deal with this sort of thing? More senior developers can't take a look at it - they've got more major clients right now.


To rewrite or slowly refactor old C++ project

Our team has recently inherited a relatively large project from another company (~250k lines). It was developed using C++Builder and we intend to port the Ui side to Qt. Most of the Ui code is separate from the business logic (yay!) but the logic side is quite a mess. There is a lot of diamond inheritance going on (virtual inheritance thankfully) but it makes understanding the code quite difficult to do. We've got very little documentation to go on, what's there is out of date (comments included). I generated class diagrams using Doxygen, here's the most complex one (I had to remove most of the class names but kept some of the more important ones and kept the standard C++ data types and std classes, yes, they inherit from std) ![confusing inheritance](http://i.stack.imgur.com/iEOhW.png) So far we've been able to convert the base program to Qt and we're at a point where we can start converting the program's functionality bit by bit. Problem is, is it worth it long term? We would like to be maintaining this software as our own long term. Is there a general approach we should take to untangling this kind of inheritance mess or should we simply redesign from scratch and only keep bits and pieces of the existing code as we go? EDIT: Some more info Zavior posted a link to an article about why we should not start from scratch but Ptolemy also brought up some good questions and I'd like to add some information about our situation. The program we have is not 'bug free.' There are known issues that users have workarounds for most. There is no 'list' of these issues, that is currently being compiled by talking to all the existing users one by one as they tend to keep things to themselves. We are all new developers to this project. Our only resource is a developer who started working on the project about half-way through its lifetime. He is available via e-mail/chat mostly. He has also put together some documentation on how some parts of the code work. The program has only been used as an internal tool so far. We would like to make it commercially viable. EDIT 2: One of the most important things we want to do is have the program be in Qt. It's currently using the VCL framework from C++Builder that no one on our team is familiar with and we only have 1 license for. It's during my work porting from VCL to Qt that I found the messy code structure and question the decision to 'convert' vs redo.


How possible is it to estimate time for programming projects?

It seems like it is nearly impossible to get close because you could run into any number of issues and things not first anticipated. How close can we be expected to reasonably estimate? Our PM wants to be able to have things like Gant charts and such mapping out weeks at a time and such... So we say we can get these bugs done, and this is how long each will take, and the goal will be Friday, but things get thrown off and pushed into the next week, like every time! How are we suppose to guess the right time?


How do you know you're writing good code?

Serious question here. I love programming. I've been messing around with code since I was a kid. I never went the professional route, but I have coded several in-house apps for various employers, including a project I got roped into where I built an internal transaction management/reporting system for a bank. I pick stuff up quickly, understand a lot of the concepts, and feel at ease with the entire process of coding. That all being said, I feel like I never know if my programs are any good. Sure, they work - but is the code clean, tight, well-written stuff, or would another coder look at it and slap me in the head? I see some stuff here on SO that just blows my mind and makes my attempts at coding seem completely feeble. My employers have been happy with what I've done, but without peer review, I'm in the dark otherwise. I've looked into peer code review, but a lot of stuff can't be posted because of NDAs or confidentiality issues. A lot of you pros might have teammates to look at stuff over your shoulder or bounce ideas around with, but what about the indies and solo guys out there like me? How do you learn best practices and make sure your code is up to snuff? Or does it not matter if it's "the best" as long as it runs as expected and provides a good UX? EDIT: Wow, I can't believe the great response and helpful answers this question generated!!! In the spirit of democracy I have selected the answer with the most upvotes as the correct one -- in reality, I wish I could accept many of these answers, since they all made some great points and helped me expand my mind a bit when it comes to my programming. Thank you to everyone who took the time to answer and comment!


Methods to understanding coding relationships and infrastructure within an unfamiliar codebase

I have recently begun studying a codebase which I will soon be working with. The current codebase has been written by a team of about 5 rockstar developers (whatever that means), and it hasn't really been documented for a newcomer like me. I have a general understanding of what technologies are being used, but not enough to begin coding and adding features. I first need to understand the general architecture that's employed throughout the code, all the basic relationships, and the process flow from input to output, as well as read and write - from the server to the client and from the client to the server. When I'm able to understand their system at this level, developing on this codebase should be much more do-able. I'm not concerned with reading through the code and studying their use of the language. I know that I can Google syntax and a library or an API if I need to figure something out. But what are some approaches to understanding the architecture and all the important relationships for code that doesn't specifically document it? The codebase has been written by advanced-level developers who've used a lot of top-down method, so how does a newcomer come and understand it from the mind of the developer who initially wrote it? You'll find this quite often in code- bases that are hosted on GitHub and such. A lot of code. Little documentation. So where does one begin? What are some suggestions, and what has your experience been?


Maintenance code needs improvements

I am currently maintaining/enhancing a project a bit old speaking of the 1990's. Atleast 15 developers would have worked over it. Going through the code for understanding is bit difficult.   1. No coding standards being followed.   2. OOP concepts not clear.   3. Too many unnecessary methods and functions, also unused files.   4. Worst of all global objects (hard to determine when its created and destroyed). At times I feel should I be correcting the code so its better to work on, but my PM says we should not bother about it. As we have to finish the tasks within deadlines. This also leads to difficulties in tracking the bugs occurring. Any suggestions on how should I approach it?


How should I go about "overhauling" a large legacy application?

> **Possible Duplicate:**   >  I’ve inherited 200K lines of spaghetti code — what now? For my next project, I've been tasked with "overhauling" a large legacy web application with many parts. It is a JSP application written in 2004 and it is used heavily by my company. This application was designed badly in that there is no separation of concerns; no service layer, no DAO layer, no MVC structure. Just a bunch of JSP files loaded with scriptlets containing logic and database queries mixed in with HTML. It's a mess. My boss has defined "overhaul" as basically rewriting the entire thing using the technologies we use for our more recent applications, which are:   * Maven   * Spring    * JPA (w/Hibernate)   * JSF **AND** add a bunch of new features. My question is: How do I go about this? What should be my strategy for completely redoing a large application that is currently in use AND add a bunch of features? Should I rewrite the existing application first and get it working with the updated technologies and THEN worry about adding new features afterward? Or should I go about it like I'm creating a whole new application and implement the new features WITH the old features? Has anyone done this successfully? If so, what strategies were instrumental to your success? * * * **Edit: More info from comments:** How bad does the design have to be to justify a rewrite? This design is pretty bad. There is tons of business logic hiding in the application. No specs, no logs of requirements changes, no list of bug fixes, no list of open bugs, no test suite, no documentation. And the guy who originally wrote it is now in upper management.


How to accurately predict release items?

We are having a disconnect between development and business needs. Business is asking me to produce an accurate list of deliverables for a fixed date and development being difficult to predict is pushing back saying that can only produce a list 80 or 90% accurate. So my question is, how do we solve this problem? How to provide an accurate list of deliverables weeks before they are completed and fully tested?


How to set more accurate "deadlines"?

Context: My work is to build financial reports using mostly Excel spreadsheets. This consists mostly of formulas and a good deal of VBA. Each person is built by a single person. We service many sub-departments under the finance / accounting department and we often have many projects lined-up. I have had a rough time in the last few months because of projects taking longer than expected, then projects overlapping and getting very close to critical deadlines. Question: Obviously, we try our best to plan our projects so that we have a little bit of room to breathe but I always feel helpless when I have to estimate how long a given project will take me to complete. Are there techniques that can be used to better estimate how long a project can take to complete ? Analysis: I am thinking that one way to get a better idea of the length of the project would be to look into our process for getting requirements which could be infinitely better. It would help to get a clearer picture but it would still not give us a measurement. Then I thought that maybe isolating and measuring the average development time of different tasks that need to be done for most reports (e.g. build the queries, write the functions, construct the report, automate the process) would be one way to achieve this but it does not take into account the variability in complexity of those tasks. Some reports have very simple queries while others are extremely complex. Obviously the more complex the query the longer it would take. Note: Most of the time we have to deal with legacy code / inefficient reports which can cloud the waters even more.


When do code hacks become bad?

When you begin a new project/function/object you mostly have an idea of the model you want to build. It can be based on the clients' wish, on your ideas for the app or whatever. In the middle you often realise that your model will not work. There may be new requirements, you didn't think of something etc. Then you have two options. Either you rewrite your code to work with the new specifications, or you "hack" the current code to do what you want. A rewrite is time consuming, and you may need to do it several times, but in the long run it often pays. Hacks are fast and often effective for the moment, but many hacks will make the code really bad, and after a while they may come back and bite you in the behind... How do you determine when to do what? _(Pardon my very non-academic way of explaining this, but I hope you understand what I'm getting at.)_


How to organize a one-man project?

Every once in a while (read: about every day) I come up with a new idea, start a new project in my favorite editor/IDE, start coding and the next day I delete it and start something new. I've been programming for about six years now and in those six years I have only really completed one very small project (a Dashboard widget for Pastebin.com). Though this might be great for learning coding, I really want to complete something. What are some things I should do before, while and after the actual coding? What are good resources that teach me how to organize such one-man projects? * * * If it matters, I want to do web or Mac development.


Is eval the defmacro of javascript?

In Common Lisp, `defmacro` basically allows us to build our own DSL. I read this page today and it explains something cleverly done: > But I wasn't about to write out all these boring predicates myself, so I > defined a function that, given a list of words, builds up the text for such > a predicate automatically, and then evals it to produce a function. Which just looks like `defmacro` to me. Is `eval` the `defmacro` of javascript? Could it be used as such?


Is it fair to say that "macros don't compose"?

On this blog post aphyr (who is a brilliant programmer) states: > Clojure macros come with some important restrictions. Because they’re > expanded prior to evaluation, macros are invisible to functions. They can’t > be composed functionally–you can’t `(map or ...)`, for instance. The classic example of this is:               (reduce and [true true false true])     ;RuntimeException      Yet we can write:               (reduce #(and %1 %2) [true true false true])     ;false      **Is 'macros don't compose' a valid claim?** Surely the only valid point is that macros are not first class functions and shouldn't be treated as such.


How do International Call Rerouting Apps work?

Since DTMF seems impossible on Android devices, I really wonder how it is possible to setup a direct dail service like Jinggling (http://www.jinggling.com/how_it_works.html). I realize one registers his phone number, but to what end? Say a customer now dails an international number, the App intercepts the call, reroutes it to their own service but how gets the desired number transmitted? The whole point is that this is works without wifi-/data-connection, no VOIP. The only way I can imagine this to work is using SMS to exchange auth and other related data. Or am I missing something?


Gradual Typing: "Almost every language with a static type system also has a dynamic type system"

This claim by Aleks Bromfield states: > Almost every language with a static type system also has a dynamic type > system. Aside from C, I can't think of an exception Is this a valid claim? I understand that with Reflection or Loading classes at runtime Java gets a bit like this - but can this idea of 'gradual typing' be extended to a large number of languages?


TypeScript or JavaScript for noob web developer

Following the recent release by Microsoft of TypeScript I was wondering if this is something that should be considered for a experienced WinForm and XAML developer looking to get into more web development. From reviewing a number of sites and videos online it appears that the type system for TypeScript makes more sense to me as a thick client developer than the dynamic type system in Javascript. I understand that Typescript compiles down to JavaScript but it appears that the learning curve is shallower due to the current tooling provided by Microsoft. What are your thoughts?


Does Apple own any rights to software you create with their developer tools?

Or do you own the rights to any software you create, regardless of whether you used tools supplied by a third party? Thanks


I'm struggling with abstracting my animation code in my game using a functional style. How can I do this?

My game is a top down 2D shmup programmed in a functional style. I'm struggling with abstracting the code that is responsible for animating the projectiles. There are many types of guns with many types of projectiles. Here are a few that are very different:   1. A **standard gun** that shoots a bullet that travels a distance over time.    2. A **laser** that shoots a line that goes from start to end in an instant.      * This is different from the **standard gun** projectile because its projectile doesn't travel over time. It's drawn as a line. Unlike the standard gun, the laser beam animation should last after the projectile hits something.    3. A **psychic shockwave** that forms a circular blast wave around your body and damages anything in range. The size of the circle is variable.       * This is different from the **standard gun** projectile because its size is variable and circular. Also, it doesn't move. I'm struggling on how I can use a sprite sheet for this. It seems like the best way might be to draw a circle on the screen. All the other projectiles are sprites.      * This is different from the **laser** because it's a circular shape rather than a line.  If this were object oriented, the path I'd take is straight-forward: I'd create an `Animation` class that is responsible for animating itself. The client code would have no idea _how_ the animation occurs, it would just pass in the necessary objects in order to get it done. But I'm not sure how to do something like this in a functional style. Right now I represent everything as data. A `projectile` contains `animation` data like so:               projectile: {       type: "laser"       animation: ...     }      But what feels very wrong is I have to have one switch to create this projectile, and then in my rendering code, I have to have _another_ switch to decide how to use the data to animate it. EG:               if projectile.type is "standard gun"       rotateBulletTowardsVelocityAndAnimateAtPosition(projectile)     if projectile.type is "laser"       rotateLaserTowardsTargetAndAnimateFromStartToTarget(projectile)     if projectile.type is "psychic shockwave"       drawCircleAroundProjectilePosition(projectile)      This doesn't seem very abstract to me. What's a better way to code this while still being functional about it?


Difference between Yesod and Ocsigen web frameworks

I have been looking at web-frameworks in functional languages and eventually found Yesod and Ocsigen interesting. As far as I understand, they leverage the type system to statically prevent basic errors such as invalid HTML or internal dead links. My question is are there practical differences such as feature focus or maturity between these two frameworks? What does one have that the other miss? For example, with Yesod, can I write the entire web-application in Haskell and have the appropriate component compiled to Javascript? Thanks.


Unit testing statically loaded data

Scenario: I have a configuration file containing some structured data that is loaded in at runtime and is **not** modified by the application, but is referenced in many places. There are functions that retrieve specific data from the configuration file (after it's been loaded into memory). I'd like to write unit tests that ensure that data has not been changed inadvertently by a developer, is this good practice or overkill? E.g. `Assert(GetDataForKey("SomeKey") == "MyValue")`


How to prove that following practices and industrial standards are profitable, and investment in refactoring are good

I started working in a company not much time ago, and what I see a lot inside a project is a high amount of low quality code and some custom ideas instead of industry standards and selected best practices. But when I trying to talk with manager about that, I often see the answers, that guys who doing that make things quick and they are good etc, etc, etc


How can I study C# from Stack Overflow

How can I study C# from Stack Overflow?   I have only the basics of the C# language with some simple exercises; now I want to go to the highest level C# through Stack Overflow, reading any questions tagged "c#". The questions are not ordered from easiest to hardest. Do you have any idea on how to learn C# from Stack Overflow?


C++ Multithreading on Unix

I have two related questions:   1. Are there any good books for multithreading in C++, especially now that C++11 contains multithreading in the standard library?    2. I have the Wrox Programming on Unix book (1000 pages fat red one) and within it, it uses the Unix Thread class.      * How does this code relate to boost and the C++11 multithreading libraries?      * Is it better/worse/just specific to Unix etc?      * Is the performance the same?


What is the actual purpose of MVC?

I've seen a lot of stuff that describes how it's done, but not a lot that tells WHY it's done. Is it just a way to keep the code readable, or is there a better reason?