If/else, etc can be an indicator, but it's really more of a subjective term.
Labels and gotos or jumps are usually a bad sign, UNLESS you really know what you're doing and are going for low level optimization. If you're asking this question (and, really, I mean no offense by this), you probably don't have those sorts of problems yet.
There are other ways to hop around in code, of course. Setting up sets of delegates or function pointers, and then calling them in such a way as to be confusing, or constantly reassigning the variables that hold them can create a code path nightmare without a goto in sight.
Depending how strict you want to consider the term, you might also include poor state management. A piece of code that assigns a load of global variables, sets them in confusing or hard to trace ways, and uses or changes them all over the place may also be termed spagetti code, even if the actual execution paths are fairly simple.
Code that generates code, and then calls said generated code is generally considered something different, but it can produce similar effects (headache, nausea, all sorts of stuff that make you wish you hadn't done that). This is useful for very specific problems, however, and can be done well.
So, my advice? Go nuts. If you think you need goto's, go for it. If you think the best plan is to set up a block of function pointers and call them by wierd pointer arithimatic logic, do it. If you think you should generate code based on your problem's input parameters, load it as a library, and then make calls into it, by all means. If/when things don't work quite right, and you load up the debugger and can't trace what's going on, you'll get to learn all about why these things are generally a bad plan :)
2006-10-12 21:02:53
·
answer #1
·
answered by Ryan 4
·
0⤊
0⤋
Definition of Spag code: Program code that keeps jumping from one place to another in the program without any apparent organization
Definition of Spag code: Spaghetti code is a pejorative term for a computer program code with a complex and tangled control structure, especially one using many GOTOs, exceptions, threads, or other "unstructured" branching constructs.
This is a sample of spaghetti code
If then
...procedure
If then
...procedure
else
If then
...procedure
else
...procedure
end if
end if
else
...procedure
end if
you know it is spag code when you read the code you dont exactly know where the next statement go.
2006-10-13 03:32:24
·
answer #2
·
answered by Anonymous
·
0⤊
0⤋
Classic spaghetti code has blocks of code with multiple entrance and exit points. If-then-else isn't bad in itself, but if your else comes three hundred lines after the if, pass the Parmesan.
The way to avoid spaghetti code is to use some variety of structured programming.
2006-10-13 04:42:16
·
answer #3
·
answered by injanier 7
·
0⤊
0⤋
Spaghetti code uses a control flow that jumps around a lot in the program and breaks out of common structures like loops and if/else. In many languages, the jumping command is called "goto", and its use is forbidden by many programmers.
Having one or more goto statements is a clear sign of spaghetti code.
2006-10-13 03:32:58
·
answer #4
·
answered by يا حسين 4
·
0⤊
0⤋
Hi,
There are actually metrics used to rate code quality. They were created by NASA about 30 years ago, and are still used to measure code complexity today. The most basic measurement is to simply count all the possible distinct paths of a function.
Last year, there was a grad student from Harvard who created a tool which measured code complexity for Java programs. It is currently used by several professors to assist in the grading of student assignments and help them develop strong coding practices.
Hope this helps,
Leo
2006-10-13 03:32:29
·
answer #5
·
answered by Leo R 2
·
0⤊
0⤋
In my own opinion, when you say Spaghetti Coding, it coding without using proper indention so as the codes are hard to read. As if there's no beginning and end.
KaBalweg
http://smartcoder.awardspace.com
2006-10-13 10:45:36
·
answer #6
·
answered by dabsani 3
·
0⤊
0⤋
depends on the program requirement. if you can't avoid them. you can use alternates like switch etc.
2006-10-13 03:27:09
·
answer #7
·
answered by Arif 2
·
0⤊
0⤋
You know just by looking at it - it's a mess! Hence the name...
Rawlyn.
2006-10-13 04:14:35
·
answer #8
·
answered by Anonymous
·
0⤊
0⤋