4 ms·
"To me, an abstraction is a piece of code that’s expressed in high-level language so that the distracting details are abstracted away. If I were to see a confus
by mannykannot 3y ago
"To me, an abstraction is a piece of code that’s expressed in high-level language so that the distracting details are abstracted away. If I were to see a confusing piece of code littered with conditional logic, I wouldn’t see it and think “oh, there’s an incorrect abstraction”, I would just think, “oh, there’s a piece of crappy code”. It’s neither an abstraction nor wrong, it’s just bad code."
Of course, if bad code is not an abstraction, then there can be no such thing as a bad abstraction!
More to the point, code littered with conditional logic might well be both good code and a good abstraction. There's a somewhat well-known article out there claiming that Netscape shot itself in the foot by deciding to rewrite the browser from scratch. As an example of how that went wrong, the author mentions the hapless developer trying to write code to work with some hardware component (the great many different dial-up modems that were out there at the time, IIRC), discovering that most of them had unique quirks that had to be respected, even when they nominally conformed to the same spec.
The thing is, you can no more apply abstraction to a program until everything is simple than you can apply compression to a file until its down to a byte. What's really at issue here, as Fred Brooks noted many years ago, is the difficult problem of satisfying the demands of the context's essential complexity while keeping a lid on the implementation's accidental complexity.
- tikhonj 3y agoThere are a lot of ways for good code to express bad abstractions. The abstraction could be inconsistent with other parts of the system, inconsistent with the concepts it is meant to represent, inconsistent with its own observable behavior, inherently complex or hard to reason about, inconvenient to actually use, poorly suited to whatever people actually use it for... I've seen a lot of code that is perfectly clean and "well-organized" as code but organized into absolutely awful abstractions. None of that goes against your core point, I just think that seeing the code and its abstractions separately is an important perspective for understanding code design. On the flip side, it's also totally possible to have bad code but a good abstraction. Some of the best abstractions I've worked with have painful implementations, and it didn't impinge on the quality of the abstraction itself! Of course, the bad code made life a lot more painful for the people responsible for implementing and maintaining the abstraction, and I'm sure it required some real skill and experience to keep that from manifesting to users of the abstraction, but they managed it.