Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Not All Bad Code is Spaghetti Code

Hugh Pickens writes (1984118) writes | more than 2 years ago

Programming 2

Hugh Pickens writes writes "Judah Johns writes that many programmers interchangeably use the term “spaghetti code”, with “bad code” and while all spaghetti code is bad code, not all bad code is spaghetti code. 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. On the other hand people usually use “bad code” to mean “ugly code”, but if it’s possible to determine why a piece of code is bad and ugly, and to figure out a plausible fix, it’s already better than most spaghetti code. "Spaghetti code is incomprehensible and often unfixable but if you know why you hate a piece of code, it’s already above spaghetti code in quality, since the latter is just featureless gibberish." What causes spaghetti code? Goto statements were the leading cause of spaghetti code at one time, 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 Johns 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. "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.""

Sorry! There are no comments related to the filter you selected.

How about (1)

fireman sam (662213) | more than 2 years ago | (#41404375)

A C++ header that also contained the implementation (and was not wrapped in ifdef/define) where in the constructor, a pointer to itself would be stored in a global variable (also defined in the header) and any calls to member functions would be routed through this global variable.

If anyone using this were to create more than one instance of the object, the code would become very unpredictable - yet it was written by a supposed "expert" and was almost used in a commercial product.

This guy is an idiot (1)

edxwelch (600979) | more than 2 years ago | (#41404453)

He came across one case where an intern used inheritance badly and concludes that all code that uses inheritance is bad.

Check for New Comments
Slashdot Login

Need an Account?

Forgot your password?