Почему Соурс называют Спагетти кодом? \ Why is Source called Spaghetti Code?
Почему именно спагетти? С чем это связанно? \ Why spaghetti? What is the reason for this?
< >
Visar 1-3 av 3 kommentarer
cccrewmalt 20 nov, 2024 @ 22:53 
Spaghetti code is a pejorative phrase for difficult-to-maintain and unstructured computer source code. Code being developed with poor structure can be due to any of several factors, such as volatile project requirements, lack of programming style rules, and software engineers with insufficient ability or experience. (from wikipedia)
cccrewmalt 20 nov, 2024 @ 22:55 
Here follows what would be considered a trivial example of spaghetti code in BASIC. The program prints each of the numbers 1 to 100 to the screen along with its square. Indentation is not used to differentiate the various actions performed by the code, and the program's GOTO statements create a reliance on line numbers. The flow of execution from one area to another is harder to predict. Real-world occurrences of spaghetti code are more complex and can add greatly to a program's maintenance costs.

1 i=0
2 i=i+1
3 PRINT i;"squared=";i*i
4 IF i>=100 THEN GOTO 6
5 GOTO 2
6 PRINT "Program Completed."
7 END
Here is the same code written in a structured programming style:

1 FOR i=1 TO 100
2 PRINT i;"squared=";i*i
3 NEXT i
4 PRINT "Program Completed."
5 END
Ettanin 20 nov, 2024 @ 23:03 
it's called like that because of how the code winds through each other, jumping from function to function with no apparent sign on where it starts and where it ends, like the noodles in spaghetti bolognese.
Senast ändrad av Ettanin; 20 nov, 2024 @ 23:03
< >
Visar 1-3 av 3 kommentarer
Per sida: 1530 50

Datum skrivet: 12 nov, 2024 @ 0:25
Inlägg: 3