rss feed
Today I found this post from Paul Buchheit that explains this type of programming mentality better than I could (http://paulbuchheit.blogspot.com/2007/05/amazingly-bad-apis.html):
There is a very tempting trap that many programmers fall into. In my post quoted above I called it the Bob Trap, but perhaps a better name would be the Abstraction Trap. Abstraction in general is an immensely powerful tool, and as its magic has been bestowed upon the land, programmers have realized that they can write complex programs in C++ or Java or Python rather than assembly language and therefore be much more productive. But the tendency with anything good, as Paul explains, is to try to apply it to absolutely everything. And this is where programmers like Bob start to go astray. When abstraction becomes an end unto itself, it begins to interfere with the original goal of producing maintainable software.Anyway, I don't have a whole lot to add to this. The idea just really resonated with me. One of the reasons I dig Python is that it tends to use abstraction as a force for good.Further reading on Python versus Java, especially as related to abstraction and code bloat: http://dirtsimple.org/2004/12/python-is-not-java.html
blog - Python, Java, and abuses of abstraction
posted by witten on May 22, 2007
A few months ago I wrote about a former coworker with a particular propensity for churning out mountains of code (http://coderific.com/blog/post/351):
Let's call him Bob. Don't worry, if you're one of my former coworkers, and you're reading this, then it isn't you. Bob liked to write code. He liked to write lots of code. He would invent problems where there weren't any, not because he genuinely liked solving problems, but because he liked to write copious amounts of code. He relished big, sweeping architectural changes, and simply based on the frequency with which he caused them, you'd think that he knew no other way to write software.... Bob was simply too fascinated with the minutiae of his language of choice, and so as long as he was lost in reams of code he had written containing overly complicated component interactions to sort out, he was happy.
Today I found this post from Paul Buchheit that explains this type of programming mentality better than I could (http://paulbuchheit.blogspot.com/2007/05/amazingly-bad-apis.html):
I also have a second theory about what happened to Java: it attracted people who like to write piles of code filled with endless abstractions. When I worked at Google, one of the engineers on our Java mailing list suggested that we ban the keyword 'new'! I was puzzled by this suggestion, but after a little research I learned that one of the hot fashions in Java is to use factories instead of 'new' (not that factories are bad, but "sometimes good" does not imply "always best"). Better yet, you don't reference the factories directly (not enough abstraction), instead you have some framework that injects the factories into your classes according to what is written in an XML configuration file. In this way, you can make your code perfectly unreadable, but more importantly, it is very abstract.
There is a very tempting trap that many programmers fall into. In my post quoted above I called it the Bob Trap, but perhaps a better name would be the Abstraction Trap. Abstraction in general is an immensely powerful tool, and as its magic has been bestowed upon the land, programmers have realized that they can write complex programs in C++ or Java or Python rather than assembly language and therefore be much more productive. But the tendency with anything good, as Paul explains, is to try to apply it to absolutely everything. And this is where programmers like Bob start to go astray. When abstraction becomes an end unto itself, it begins to interfere with the original goal of producing maintainable software.Anyway, I don't have a whole lot to add to this. The idea just really resonated with me. One of the reasons I dig Python is that it tends to use abstraction as a force for good.Further reading on Python versus Java, especially as related to abstraction and code bloat: http://dirtsimple.org/2004/12/python-is-not-java.html
3 comments
Write a comment!-
Re: Python, Java, and abuses of abstraction posted by ckhoo on May 22, 2007 05:11 PM
Are you talking about inheritance or delegation?http://www.objectmentor.com/resources/articles/inheritanceVsDelegation.pdfUsing inheritance IMHO is scary. I was looking at code a few months ago which has over 6 levels of inheritance for some classes.. Not only that, this programming language (Centura) supported multiple inheritance. Needless to say, I did not like it.Delegation (or interfaces, contracts) is much better in most cases, and harder to abuse.I think more importantly, code needs to be separated into layers (you know the drill - UI, business logic & data access) with well defined programming rules for each layer. That way, you understand the rules of engagement when you're dealing with different sections of code.Chris -
Re: Python, Java, and abuses of abstraction posted by witten on May 22, 2007 06:01 PM
ckhoo wrote:Are you talking about inheritance or delegation?
I don't think I was talking specifically about either. :)Using inheritance IMHO is scary. I was looking at code a few months ago which has over 6 levels of inheritance for some classes.. Not only that, this programming language (Centura) supported multiple inheritance. Needless to say, I did not like it.Delegation (or interfaces, contracts) is much better in most cases, and harder to abuse.
Abuse of abstraction can strike in a variety of ways. In the quoted article, Paul was talking about overuse of the factory pattern and dependency injection in Java. I've seen that problem before as well, but I've also seen overuse of both inheritance and delegation. It sounds like you've already run across this sort of problem with inheritance. But delegation isn't immune from abstraction abuse either. Think about really deeply nested delegation hierarchies such that a single call to an object's function kicks off a series of delegated calls through dozens of nested objects. This can be problematic both in terms of debuggability and performance.I do agree however that inheritance tends to be abused more often than delegation. Inheritance is often the blunt instrument of choice for neophyte OOP programmers that just completed CS 101 and are now dangerous enough to inflict some real damage on the world.I think more importantly, code needs to be separated into layers (you know the drill - UI, business logic & data access) with well defined programming rules for each layer. That way, you understand the rules of engagement when you're dealing with different sections of code.
Yup, separation into distinct, well-defined layers is one of the best uses of abstraction, but you can go too far with the number of layers if you're not careful. -
Re: Python, Java, and abuses of abstraction posted by polterguy on May 25, 2007 02:35 PM
Astronaut Architects it's called...