Become a fan of Slashdot on Facebook


Forgot your password?

Submission + - What Causes Spaghetti Code? (Not the GOTO)

Hugh Pickens writes writes: "Michael O'Church writes that spaghetti code is an especially virulent but specific kind of bad code related to the dreaded and mostly archaic goto statement, a simple and powerful control flow mechanism that makes it difficult to reason about code, because if control can bounce about a program, one cannot make guarantees about what state a program is in when it executes a specific piece of code. Goto statements were once the leading cause of spaghetti code, but goto has fallen so far out of favor that it’s a non-concern. "Now the culprit is something else entirely: the modern bastardization of object-oriented programming," writes O'Church adding that inheritance is an especially bad culprit, and so is premature abstraction: using a parameterized generic with only one use case in mind, or adding unnecessary parameters. Object-oriented programming, originally designed to prevent spaghetti code, has become one of the worst sources of it (through a “design pattern” ridden misunderstanding of it). An “object” can mix code and data freely and conform to any number of interfaces, while a class can be subclassed freely about the program. "There’s a lot of power in object-oriented programming, and when used with discipline, it can be very effective. But most programmers don’t handle it well, and it seems to turn to spaghetti over time," concludes O'Church. "I recognize that this claim – that OOP as practiced is spaghetti code – is not a viewpoint without controversy. Nor was it without controversy, at one time, that goto was considered harmful.""
This discussion was created for logged-in users only, but now has been archived. No new comments can be posted.

What Causes Spaghetti Code? (Not the GOTO)

Comments Filter:

"More software projects have gone awry for lack of calendar time than for all other causes combined." -- Fred Brooks, Jr., _The Mythical Man Month_