How do you maintain a poor codebase?

In order to maintain the code that I write, I have to specify variables well, document my code, make sure that nothing repeats, that abstractions work, so that hacks are not needed .. and comment sparingly because comments often interrupt I read the code .

But many of the other codebases I've seen are more like a whirlpool. Variable names foobar, material is calculated even if it is not required, many hacks and patches are applied, abstractions fail, deployment scripts fail ... Code is an incomprehensible and almost unusable soup.

So! I am curious. How do you manage to maintain a low-quality code base?

+6
refactoring maintenance
source share
13 answers

discipline

+5
source share

Constant refactoring when you open the code file and you see something strange, you can spend a few minutes to improve the design of the existing code.

Having a set of unit tests can help you with this, as it gives you the confidence that the code you are changing is still working or breaking due to your changes.

This is a bit like the story of a broken window in a house. When you see a broken window, you have to fix it. If you do not fix it, everything will start to tear from there, and this will lead to an incredible mess.

Most of my projects are also added to ContinuousIntegration; next to building and running unittests, static code analysis (fxcop) is also performed. From time to time, I review the results and try to fix some of the reported violations.

+8
source share

Typically, you describe the natural tendency of any code base to increase entropy. This happens in every project due to the fact that it is developed and maintained. To combat this constant growth, I would suggest the following:

  • Someone with a team with sufficient authority should take care. This is the most important part. If no one cares, it will not be done. This point seems obvious, but it is not.

  • Set standards and best practices. Most languages ​​have a book written by someone about best practices. For example, PERL has a very good Perl Best Practices book by Damain Conway. If you do not, each person in the team has his own way of writing code, variable names, comments, etc.

  • Code Reviews. You will need a checklist to view the code. It is not enough for your changes to work, and it must be consistent with the list of best practices. We created two-level code reviews, the first level is peer-code reviews, and the second level is the release manager, which takes care of the quality of the code.

  • Design reviews. When an error or improvement is filled in by the error tracking system, it is important that it is viewed by the change control panel, which decides on the planning of work, as well as who needs to review the design of the work. Here you support code abstractions and make sure that the changes are consistent with the projects and project goals. The team software architect or lead developer must be part of the CCB.

  • Triggers quality control code. Some best practices can be directly applied by codes. Write small scripts that check your code for things like formatting, using tabs / spaces, etc. This will help you understand code quality differently.

A little reading for reference.

+5
source share

Peer-to-peer reviews quickly establish a code quality standard that is difficult to measure on a piece of paper. Unit tests make it easy to change code. Discipline, a lot of it.

+4
source share

A related question: how do people go about writing low-quality code?

Here is the answer.

A good strategy for incompetent people in our industry is:

  • Develop your ability to sound impressive, especially for non-technical and semi-technical people. Being able to sound believable enough for technical people is enough to keep them in balance.

  • Make a complete mess of the code you touch.

  • Now this is the important part: Leave and find the best job elsewhere before being recognized. The best time will depend on the specific circumstances.

+4
source share

I would like to introduce you to the term that I heard a few years ago - Technical Duty . Here (1) is a Wikipedia entry , and the other is from Martin Fowler (2) .

In fact, I do not think that people are starting to gather to build crummy software. What usually happens is that time frames are compressed, requirements are changed or replaced by average development, and any number of other commercial bite realities is the basis for the development and design of quality.

From Fowler:

“doing things quickly and dirty installs us with technical debt, which is similar to financial debt. Like financial debt, technical debt carries interest payments, which come in the form of additional efforts that we must do in the future development due to the quick and dirty choice of design "

From Wikipedia:

“Activities that may be delayed include documentation, written tests, participation in TODO comments, and a compiler and static analysis warning code. Other cases of technical debt include knowing that does not apply to an organization and code that is too confusing to be easy to modify. "

What I saw (and led several development teams) is to reorganize and clear the base code base at the beginning of development iterations, usually at the start, before the development of a new work.

Peer reviews, unit tests, and professional software testers help pay off some of this technical debt, as well as good forecasting (and good code reuse).

If you have a budget, automatic testing can be a reasonable investment if you are willing to pay for maintenance (time, effort).

Today there are many high-quality tools, such as fxCop (and others like it), however you should carefully choose which approaches you are going to entertain.

It is necessary to take into account efforts to maintain quality in the design and in the code base, so carefully think about the most effective and useful for your development team / product / company / client, etc.

[(1) http://en.wikipedia.org/wiki/Technical_debt ]
[(2) http://martinfowler.com/bliki/TechnicalDebt.html ]

+3
source share

This is the case when you write code and other people read it.
1. Leave bad habits
2. Use a meaningful procedure, function, variable name

3. Use documentation on how this works (procedure / function / calculation / etc), and what came of it, do not make unnecessary comments

4. Try to style your coding so that people can recognize it (for example, using the GNU style code)
or
Use a code decoder to do this.
5. Think of working as a team (even if you were alone), and not just you who will read your code (even if it were)
6. The refactoring code should be good, as well as 7. Consult your teammates about the code you write, can you read it?
8. Learn from the OpenSource community how they work and share codes and patches.
9. If you can, use SVN or CVS to support your code.

and remember the KISS principle ( K eep I t S imple, S tupid)

and, of course, Simple, Lean, Mean and Beautiful

if it has changed (other people write, you read), I did not know what to say: D (maybe give people more tips LOL)

+2
source share

Documentation, source management, unit tests and a good programmer.

+1
source share

A complete set of unit tests that allows you to modify and refactor without worrying about breaking existing code.

I recommend compiling a copy of Michael Peer's Effective Work With Legacy Code.

+1
source share

Fredhemaget says: "Dumb programmers have flawless code bases."

+1
source share

You can get rid of poor maintenance of the code base when you are a very small (less than 10-20 people or so in one project) development team. If your project grows and your team grows, either your practices will increase, or you will fail.

The change you are asking for is the transition from hacking to programming, and finally, Software Engineering.

With Software Engineering, you learn that not everyone on the team is perfect. You look at the code, you guarantee that others test, you cross-check each other.

You begin to see the need for an architect who can digest the wishes of clients and translate them into a project document. It can easily be eaten in a month before anyone else is added to the project (but months or even years can be saved during development time!). He is sure that everything makes sense and will fit well.

You have project documents, usually UML, so different parts of the team can understand the integration points. You acknowledge that everything that has been done, you may have to redo it without the people who did it, so you document it.

Your quality process becomes much more stringent, and they begin to apply the rules as you check for changes that address specific errors during testing.

Testing, refactoring, etc., are obviously key, and their re-application is carried out by an expert review and team.

I'm not saying that this type of material is always necessary, obviously it is not, but in your question you are discussing the basics of cruel code, and these good practices are often the solution to this problem.

Usually, these good practices are implemented after the GIANT project, which fails completely because the code base is so bad. Then they fire all those who cannot shy away from guilt, hire some managers who hopefully have some experience working with larger projects and (if they don't have money) restart from scratch.

At least my experience. Ymmv

+1
source share

You just need practice, good tools, the ability and willingness to break bad habits and learn.

0
source share

Coding is very similar to handwriting. Each has its own style. One of the biggest problems I encountered while saving legacy code is trying to figure out what is going on. Usually this boils down to a lack of consistency in the code base.

0
source share

All Articles