Всички дискусии > Steam форум > Help and Tips > Подробности за темата
Почему Соурс называют Спагетти кодом? \ Why is Source called Spaghetti Code?
Почему именно спагетти? С чем это связанно? \ Why spaghetti? What is the reason for this?
< >
Показване на 1-3 от 3 коментара
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)
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
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.
Последно редактиран от Ettanin; 20 ноем. 2024 в 23:03
< >
Показване на 1-3 от 3 коментара
На страница: 1530 50

Всички дискусии > Steam форум > Help and Tips > Подробности за темата
Дата на публикуване: 12 ноем. 2024 в 0:25
Публикации: 3