The Java programming language is one of the most taught, learned, written about, and programmed in programming languages today. Beginning its life in 1995, it rode in on the Object-Oriented Programming hype-wave of the nineties. Although some might argue that Java's primary means of abstraction is the class---and therefore Java is primarily object-oriented, the huge number of available Java libraries indicates otherwise. In this essay, I will argue that Java's most powerful means of abstraction is the library. I will also explore whether a new term---namely "Library-Oriented Programming"---is warranted to describe programming using libraries as the main abstraction.
A library (in OO languages) is a collection of classes designed and made to be used together in an organized way. There are certain conventions that must be followed to use the library. And within those conventions, you can solve a problem. It may be a foreign concept to some to see libraries described as a form of abstraction, so I might need to borrow the credibility of an outside source. According to FOLDOC, the definition of abstraction is:
A library is meant to hide the details of a particular problem (say reading the contents of c:\directory\file.txt) by generalizing it to some more abstract problem (like creating a File object, then creating a FileInputStream, then wrapping it in an InputStreamReader). In general, though, classes of a library must be used together for them to work. This means that the library is an atomic unit. One could define a programming paradigm as a way to define atomic units (and their interactions) that model a problem in an abstract way. Java, therefore, relies on libraries as one of its means of abstraction.
But are libraries the principal means of abstraction? When you need to read in a weird file format or speak some well-defined protocol, do you ask yourself "I wonder if someone has written a library to do this?" or do you ask yourself "I wonder if someone has written a class to do this?" My intuition is to ask for the library. And I suspect most others do the same.
On the other side, you don't create an object to solve the problem, you create a framework--another word for a library. On the whole, solitary classes are not powerful enough to abstract away the complexity of real-world problems. Classes make great calculators, cash registers, and rectangle simulators---examples that teachers and books use to teach OOP principles---but they won't abstract very much more than that before they start to get brittle.
Since many classes are needed, and those classes, in general, are intertwined with the specifics of the library, the classes themselves do not abstract away problems atomically. The meat of the abstraction's ability to solve a problem is in the whole of the library.
One could argue that, although libraries are very commonly used to model problems, the main source of the power of the libraries is from the object-oriented nature of Java. It is therefore unfair to say that libraries are "principal", even though they are used as abstractions. Do not the bread and butter of OOP---object encapsulation, message passing, and polymorphism---come into play?
Object-oriented programming was touted as the solution to the code reuse problem. However, experience has shown the programming community that classes, by themselves, are not reused. When was the last time you downloaded a single .class file? It is, in fact, not the objects that are important, but the interactions and relationships between objects that are important. Their interactions are where they get their power. Hence libraries, which define a set of classes and their interactions, are the principal means of code reuse. And it is this reuse, because libraries can solve many specific problems in a general way, that defines their place as principal.
As to whether a new name should be used, well, that's really not up to me. The community will decide if it needs "library-oriented programming". I will probably use it---it seems a useful concept. I would say it's at least as useful as "language-oriented programming" as applied to Lisp. And don't forget that you heard it here first if others start adopting it.
From day to day, Java programmers write classes and methods. And they write code that instantiates, initializes, and operates on objects. But in the long view, those classes and methods and their patterns of use principally constitute libraries. Libraries have their own means of encapsulation (through interface classes) and their own means of combination (also through the interface classes). Library-oriented programming parallels Lisp's Language-oriented programming---where programmers write functions and macros then take a step back and realize they have written a whole new language. Could this be one of the reasons Java libraries flourish while Common Lisp's libraries don't? On another note: should language designers try to see the long view of their language as they design it? Can a language be built that makes the library the basic form of abstraction? What kind of abstraction would be superimposed on top?
Comments
Scala's approach to modularization
Have you looked at the way scala does modularization? Objects and classes are recommended instead of packages, and scala provides a way to import all of the symbols (objects, classes, traits, etc.) from within a statically defined Object into the current namespace. This enables modules (libraries) to be subclassed or combined just like other classes.
In essence scala's approach is a confirmation of your characterization, but the designers take it further by providing a set of refinements that allow the module system to actually be object oriented - by making singleton objects capable of serving the purpose of a library while retaining the power of an object.
Functional languages are
Functional languages are called "functional" even though a single function isn't powerful enough to abstract away a non-trivial problem. A couple of huge functions would be a bad way to write most programs just like a couple of huge classes would be. Instead you probably use collections of functions working together, none of which atomically solves your problem. The term "functional" still fits though. Every language is library-oriented when the problem becomes big enough.
That's not what object-oriented means.
If you can make and use an object in the language, it is an object-oriented language. That is all there is to it. Java is object-oriented.
The way Java's library works is irrelevant to Java's programming paradigm. The creators could have written it without using any objects and make you access everything through memory locations of machine code, and Java would still be object-oriented. Why? Because you can make objects. Yes it's just that simple. This is engineering--no community consensus or design philosophy is necessary to figure it out. Ask: Can I make an object? Don't ask: Are there pre-made objects for me to use?
Now, what you are getting at could be mighty interesting, but there's plenty of fundamentals you need to get right before you get into it, to me it just sounds like a lot of gobbledygook.
By this definition, which
By this definition, which popular languages aren't library-oriented?
Most (all?) languages are like that!
By your definition, I guess most if not all (useful) languages would classify as "library oriented". In C, C++ or Python (to name the ones I'm familiar with) one downloads and uses libraries. As you said, function or single object reutilization is extremely rare. Anyway, the concept might be useful, as in being more aware of what you're doing.
Is the prototypical inheritance of JavaScript really more OO?
Is the prototypical inheritance of JavaScript really more object oriented.
I love javascript and have for 9 years. jQuery rules!
This is idiotic drivel.
Someday, young man, when you actually know something, you'll think back on this post and cringe with embarrassment.
Component-oriented?
I think what you're describing is commonly referred to as component-oriented or module reuse.
Your observations are correct - code reuse is not typically done at the object level, but I think this is not because Java is not a OOL, but because the complexity of our systems has advanced far beyond the granularity of our the languages and libraries that are currently popular.
Hey Anonymous - don't you have anything better to do than piss on those whom you think know less than you? You're the one who should be embarassed. Get a life.
Framework is simply another word for library ?
BOLD STATEMENT SIR
Nice read but still
Nothing new here, OSGi and The Java Module JSR are formalizing the module paradigm which doesn't contradict OOP in any way.
Module based development is taking OOP to the next level where bulk of classes can be entities on their own.
As for Java OOP lacking, this it true but due to other reasons (primitives , static constructs)
Great!
This is exactly what I'm talking about.
Some responses to comments . . .
@Brian and Ben: Well, my intention is not to say that Java is not Object-Oriented (even though I provoked people with the title). Obviously I would have a lot of people disagree with that statement (though not everybody). I tend to think Java is very Object-Oriented---just not principally so.
What I was referring to, though, as some commentators (Robin, Ismael, JD) understood, is that it could be useful to look at the language in that way.
@Brian, Dan & Ismael: C, Python, and many others tend to be library-oriented. Lisp, as I said at the end, tends to be more Language-oriented.
@JD: It already has a name? I thought I had cornered it.
@Anonymous: Sorry, I was not clear: libraries and frameworks are not equivalent. But they share enough commonality that their differences are insignificant to the argument.
My main point (and I'm sorry for not being clear enough) is that though the language defines classes, methods, packages, etc., when people share code, they tend to share libraries. It's another layer of abstraction on top of the basics of the language. Libraries are not directly supported in the language. And understanding this can be useful. It is not irrelevant, Brian. Because you can ask yourself "what is the best way to design a library" instead of "what is the best way to design an object."
Although some people write languages in Java (e.g. Martin Fowler), typically you develop a library for reuse. Each has its advantages and disadvantages. But there's a deeper issue here: if objects are abstracted away into libraries, how can you abstract the library away? What language features can you incorporate into the language to create better libraries? And when these libraries become so easy to make, what new abstractions will develop on top? Clusters of libraries? Meta-libraries?
My main point (and I'm sorry
My main point (and I'm sorry for not being clear enough) is that though the language defines classes, methods, packages, etc., when people share code, they tend to share libraries.
And libraries are a collection of what? Classes.
WTF
Dude, you're far out. Really. It's like you've been evolving in some parallel universe of software development. Like Bizarro alternative to Superman.
I'll take that as a compliment.
Thank you.
"Although some might argue
"Although some might argue that Java's primary means of abstraction is the class---and therefore Java is primarily object-oriented, the huge number of available Java libraries indicates otherwise. In this essay, I will argue that Java's most powerful means of abstraction is the library."
But if the libraries contain classes, then isn't Java's "most powerful means of abstraction" still classes? Why do you talk about libraries as if they are different from classes? They sound like the same thing to me.
Good question
Libraries are not equivalent to classes.
C has libraries but no classes.
C has objects
But it doesn't have explicit support for classes. Object oriented design works fine in C, but you need some boiler-plate/macros to get virtual calls and inheritance.
Thanks everyone, for your feedback.
A more concise way to pose the argument:
Java abstracts through classes (OOP).
Java abstracts through libraries (module reuse).
Libraries solve more complex problems than classes.
More complex problems solved means more powerful abstraction.
Therefore, Java's most powerful form of abstraction is the library.
I shall say that these are
I shall say that these are are views which are totally object oriented so we can extend this discussion to any level. I have learned the language but I haven't worked a lot. It is difficult to find that potential customers and buyers who could afford it. Believe me, after reading the article, I am thinking that what is OO and what is not.
Post new comment