GOTO pushing the dark side

We have a situation where developers working on an outdated (main) system are pressured to use GOTO operators when adding new functions to existing code that is already infected with spaghetti code.

Now I understand that there can be arguments in favor of using “just one small GOTO” instead of wasting time refactoring on a more convenient solution. The problem is that this isolated “only one small GOTO” is not so isolated. At least once a week or so, a new “one little goto” appears to be added. This codebase is already horrifying to work because of code dating back to or before 1984, which is riddled with GOTO, which many Pastafarians would have done , believing it to be inspired by Flying Spaghetti Monster himself.

Unfortunately, the language it is written in does not have ready-made refactoring tools, so it makes it difficult to promote "Refactor to improve productivity later," because short-term wins are the only wins that have paid attention here ..

Has anyone else experienced this problem when everyone agrees that we cannot add new GOTOs to translate 2,000 lines into a random section, but does Anaylsts constantly insist on doing this only once, and the approval of the management?

TL; DR;

How can I solve the problem when developers are forced to constantly add GOTO statements (adding, I mean add, to go to random sections on many lines), because it "performs this function faster"?

I'm starting to fear that we will lose valuable developers from predators over this ...

Credit: XKCD

Clarification:

Go to here

alsoThere: No, I'm talking about a goto view that jumps 1000 lines from one routine to another in the middle of a loop. Go to somewhereClose

there: I didn’t even talk about what gotos you can intelligently read and determine what the program does. Go to alsoThere

somewhereClose: This is the code that makes midpoint: meatballs midpoint: If the first time here is Goto nextpoint detail: (each one is almost completely different) Go to pointlessReturn

here: In this question, I did not say that sometimes you can use goto. Go to there

tacoBell: and he has just returned to the drawing board. Go to Jail

elsewhere: When it takes a week of analysts to decrypt what the program does every time it is touched, something deeply mismatches your code base. Actually, I actually before my hell: if not updated goto 4 , giving the specification goto detail pointlessReturn: goto tacoBell

Jail: Actually, just a small update with a small win. I spent 4 hours refactoring parts of this particular program a single label at a time, storing each iteration in svn as I walked. Each step (about 20 of them) was small, logical and easy enough to go bypass nextpoint: spontaneously jump out of your food and onto the screen through some strange kind of magnetism from a meatball spaghetti. Go to elseWhere bypass: it is wise to verify that it should not introduce any logical changes. Using this new, more readable version, I sat down with the analyst and made almost all of these changes now. Go to end

4: first * if the first time goto hell here, not the second if the first time goto hell here, there is no third, if the first time goto hell here the fourth is now updated goto hell

end:

+61
goto legacy
May 26 '10 at 4:13 a.m.
source share
10 answers

How many errors were introduced due to incorrectly written GOTO? How much money did they cost the company? Turn the problem into something concrete, not "it's bad." As soon as you can recognize it as a problem on the part of those responsible, turn it into a policy such as “no new GOTO for anything other than simplifying the exit logic for a function”, or “no new GOTO for any functions that do not have a 100% unit test reach. " Tighten policy over time.

+28
May 26 '10 at 4:18
source share

GOTOs do not make good code spaghetti, there are many other factors. This discussion of the linux mailing list can help put a few things in perspective (Linus Torvalds comments on the wider picture of using gotos).

Trying to implement a “without goto” policy just to have gotos will not achieve anything in the end, and will not make your code more convenient. The changes should be more subtle and focused on improving the overall quality of the code, think about the principles of using best practices for the platform / language, unit test coverage, static analysis, etc.

+12
May 26 '10 at 4:19
source share

The reality of development is that, despite all the floral words about how to do it right, most customers are more interested in doing it in a quick way. The concept of a codebase advancing quickly to the unleashing point and arising as a result of its business is something they cannot understand, because it will mean what you need to think outside of today.

You have only one example. How you stand on this will dictate how you will develop in the future. I think you have 4 options:

  • Accept the request and accept that you will always do this.

  • Accept the request and immediately start looking for a new task.

  • Give up and get ready to fight to fix the mess.

  • Resignation.

Which option you choose will depend on how much you value your work and your self-esteem.

+4
May 26 '10 at 4:22
source share

Perhaps you can use the boyscout template: leave the place a little cleaner than you found it. Therefore, for each featurerequest: do not enter new gotos, but delete one.

This will not spend too much time on improvements, will give more time to find new errors introduced. It may not cost much more if you remove goto from the part that should have spent some time understanding and bringing in a new function.

It is argued that refactoring within 2 hours will save 20 times 15 minutes in the future and allow for faster and deeper improvement.

+4
Jun 03 '10 at 11:50
source share

Back to principles:

  • Is it readable?
  • It works?
  • Is it supported?
+3
May 26 '10 at 7:23 a.m.
source share

This is a classic conflict of "management" and "techies."

Despite the fact that I was in the “techies” team, over the years I firmly decided on the “managerial” side of this discussion.

There are several reasons for this:

  • It is possible that a well-written easy-to-read correctly structured program with gotos! Ask any assembler programmer; a conditional branch and a primitive do loop are all they have to work with. Just because "style" is not current and does not mean that it is poorly written.

  • If this is a mess, then it will be a real pain to extract the business process rules that you will need if you are going to rewrite the full record, or if you are doing technical refactoring of the program, you will never be sure that the behavior of the reorganized program is “correct” those. does exactly what the old program does.

  • Return on investment - using the original programming style and making minimal changes will require minimal effort and will quickly cope with customer requests. Spending a lot of time and effort on refactoring will be more expensive and take more time.

  • Risk rewriting and refactoring are hard to get right, extensive testing of the reorganized code is required, and all that looked like “errors” may have been “functions” in relation to the client. A particular problem with “improving” legacy code is that business users may have well-established solutions that depend on the errors that exist there, or use existing errors to change business procedures without notifying the IT department.

Thus, all managers are faced with the decision - “add one small goto”, test the changes and get it into production as soon as possible with little risk - or - get involved in the main programming efforts and the business yells at them when a new set of errors appears.

And if you decide to reorganize in five years, some snotty university graduate will moan that your reorganized program no longer meets the requirements for fashionable words and requires that he be allowed to spend weeks rewriting it.

If it does not break, do not correct it!

PS: Even Joel thinks this is a bad idea: things you should never do

Update -

OK, if you want to reorganize and improve the code needed for proper use.

The main problem is that you tell the client: "I want to spend n weeks working on this program, and if everything goes well, it will do exactly what it is doing now." - This is a difficult sale, to say the least.

You need to collect long-term data on the number of crashes and crashes, the time spent analyzing and programming seemingly small changes, the number of change requests that were not fulfilled because they were too complex, business losses were lost because the system could not change fast enough. Also, collect some data on the costs of spending well-structured programs, as well as how to get lost.

If you do not have a waterproof case to present to banks, you will not receive a budget. You really should sell this management to a business, and not to your immediate superiors.

+2
May 31 '10 at 2:05 a.m.
source share

Recently I had to work on some code that was not the same, but the habits of the former developers, of course, were and, therefore, GOTO were everywhere. I don't like GOTO; they make a disgusting mess of things and make debugging a nightmare. Worse, replacing them with regular code is not always easy.

If you cannot relax from your GOTO, I certainly recommend that you no longer use them.

+1
May 26 '10 at 4:20
source share

Unfortunately, the language it is written in does not have ready-made refactoring tools

Don't have editors with macro capabilities? Don't have shell scripts? Over the past years, I have done a lot of refactoring, very little with browser refactoring.

+1
Jul 18 '10 at 20:10
source share

The main problem here is that you have “analysts” who describe the apparently necessary functional changes in terms of adding goto to some code. And then you have “programmers,” whose work seems to be limited to introducing this change, and then complains about it.

To do something else, this dysfunctional distribution of responsibilities between these people must change. There are many different ways to divide the work: classical, traditional (which is quite likely an official, but ignored policy in your work) is that analysts write a specification document independent of the implementation, and programmers implement it as much as possible.

The problem with this theoretical approach is that in many common situations, it is virtually unrealistic. In particular, this “properly” requires that employees see the youngest in order to win a dispute with colleagues who are older, have better social connections in the office and are more business oriented. If the “goto” argument is not implementation independent, as the analyst simply cannot say that the word “does not fly in your workspace”, then this is presumably true.

In many cases, much better than alternatives:

  • Analysts write client code, and developers write infrastructure.
  • Analysts write executable specifications that are used as reference implementations for unit tests.
  • Developers create a domain-specific language in which analysts program.
  • You throw his distinction between one and the other, having only a hybrid.
+1
Jul 18 2018-10-18T00:
source share

If a change in the program requires “just one small goto,” I would say that the code was very convenient.

This is a common problem when working with legacy code. Adhere to the style in which the program was originally written or “modernized” the code. For me, as a rule, you should adhere to the original style if you do not have a really big change that would justify a complete rewrite.

Also keep in mind that some of the "modern" language features, such as the throw java query or SQL ON ERROR, are really hidden.

-one
May 26 '10 at 5:53 a.m.
source share



All Articles