You get a bonus - 1 coin for daily activity. Now you have 1 coin

Spaghetti code

Lecture



Spaghetti code is a poorly designed, poorly structured, confusing and difficult to understand program, especially containing many GOTO operators (especially transitions back), exceptions and other structures that worsen the structuredness [1] . The most common anti-pattern programming.

The spaghetti code is named like this because the flow of the program is like a bowl of spaghetti, that is, tortuous and tangled. Sometimes called “kangaroo code” ( kangaroo code ) because of the many jump instructions.

Currently, the term applies not only to cases of GOTO abuse, but also to any “multiply connected” code, in which the same small fragment is executed in a large number of different situations and performs many different logical functions [1] .

Spaghetti code usually occurs:

  • from the inexperience of the developers;
  • from serious pressure on the terms, as set by the management (for example, in the system of motivation adopted by the company to work faster), and established by the developer himself (the desire to do everything in the fastest way).

Spaghetti code can be debugged and work correctly and with high performance, but it is extremely difficult to maintain and develop [1] . Editing spaghetti to add new functionality sometimes brings such a huge potential for introducing new errors that refactoring (the main cure for spaghetti) becomes inevitable.

Content

  • 1 Example
  • 2 Related Concepts
  • 3 See also
  • 4 Notes
  • 5 References

Example [edit]

Below is an example of a spaghetti code in BASIC that performs a simple action - printing numbers from 1 to 10 and their squares. Real examples of spaghetti code are much more complex and create more problems when accompanying programs.

  10 i = 0
 20 i = i + 1
 30 IF i <= 10 THEN GOTO 70
 40 IF i> 10 THEN GOTO 50
 50 PRINT "Program complete."
 60 END
 70 PRINT i;  square =;  i * i
 80 GOTO 20

The same code written in the structured programming style:

  FOR i = 1 TO 10
     PRINT i;  square =;  i * i
 NEXT i
 PRINT "Program complete."

The same functional style code using the iteration method written in Ruby:

  (1..10) .each {| i |  puts "# {i} \ t square = # {i ** 2}"}
 puts "Program ended."

Related Concepts [edit]

By analogy with the "spaghetti code" programmers came up with a few more concepts, not yet generally accepted.

  • A baklava code or a lasagna code is a code in which there are too many (for a given task) abstraction layers.
  • Catamari code - a code that was once clean, but in the process of development, stuck around with functionality, like “catamari” from the game for the Playstation.

See also [edit]

  • Goto
  • IOCCC

Notes [edit]


Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Software and information systems development

Terms: Software and information systems development