OO languages spend most effort addressing a minority use case
250bpm.com
250bpm.com
In that regard, C++ is fine. Java is not.
Also a bothersome issue is people arguing that OOP is reusable, so that they invent all sorts of things that will be extendable, and then you see their code never being used ever again.
My opinion: don't teach OOP, teach software design. PLEASE.
You realize C++ is much more permissive than Java?
I don't think one can really teach reusable abstraction design like one can teach algorithms. There is no science behind it, there is no way to "measure" it. You can't create exam questions about it.
http://wcook.blogspot.co.uk/2012/07/proposal-for-simplified-...
Which identifies two defining attributes of objects as a particular kind of value: they are collections of behaviours, and invocations of their behaviours are dynamically dispatched. Inheritance isn't required; it's polymorphism that's important, and inheritance is just one way to approach polymorphism.
> A closure is an object that supports exactly one method: "apply".
In which understanding, what objects add is the ability to have multiple methods associated with one bit of closed-over state.
Now, you can do that without objects by creating several closures in one context and putting them all in a record to give them names. But at that point, you've just implemented objects. Hence the famous aphorism quoted in Steele's email: objects are a poor man's closures; closures are a poor man's objects.
[0] http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m...
Hardly. There's plenty of valid criticisms of OO out there. However, that does not mean every criticism of OO is valid. Take this one, for instance: the author is complaining that OO is optimized for class inheritance, when it's not the normal case. However, plenty of OO languages don't have classes, or inheritance, and so it falls on its face as a criticism of OO.
> If OOP were that good how come nobody made a killing with an implementation that would make these 'true Scotsman' folks happy.
Because no OO implementation will make them happy. A little unsolicited worldly advice: programmers think themselves paragons of rationality, but they're susceptible to the same flow of fashion, and the same desire to believe ill of something they don't like, as everyone else.
> other paradigms don't seem to need such pervasive apologism.
They do—take a look at the comments when articles come out critical of functional programming, most of which are as good as the one under discussion here. Or when OO supplanted structural programming the first place.
(Of course in 2 years I'll understand the cons of this approach and will think back on these times and wonder how I could have been so naive. :D )
Most code I write in C# is OO in that it leverages encapsulation, but is generally written in a functional style (thanks LINQ) and uses inheritance for maybe two out of a hundred classes.
Most popular languages now are multiparadigm, so there's little point in criticising particular paradigms as if we're somehow stuck working with them and them only.
Like when your coworkers become religious about the ORM ("How DARE you write SQL!") when the database people actually have the superior model (relational) to the programmers (OOP).
Also, many languages have an explicit critique of OOP. Take Rich Hickey's discussion of how OOP complects a bunch of features which can be available a la carte.
So, inheritance is okay, but I don't use it directly. It just isn't a tool I use; it stays in the bottom of my toolbox.
I use classes much like structs in C or structures in PL/I. Yes, classes are a little more general, and I do make use of some of that generality.
But, PL/I structures are quite a bit more general than structs in C and, really, nearly as useful as classes. And, for "addressing" as in the OP, the array addressing in PL/I structures is much more efficient than addressing in classes.
The OP is correct: I don't think of classes and inheritance as representing a is-a relationship. Sorry, I just don't do that. Don't need it. Or, I'm big on collection classes (hopefully based on AVL or red-black trees) and did write my own key-value store for session state storage for my Web site, and that usage can be regarded as using is-a, but, again, I don't get is-a from class inheritance -- just don't need that.
And the OP is correct: A lot that is in my code has its meaning clear only in the comments. The code is like the displayed equations in a calculus or physics book, and the text between the displayed equations is like the comments. Both the text in those books and the comments in the code are crucial.
Yes, the meaning of the code is crucial, but for meaning I want to use a natural language, e.g., English, in the comments.
Higher level languages aspire to take at least some of the "meaning" stuff that would otherwise be in comments and represent it using in-language constructs.
Likely the answer is, again, similar to what is done in a calculus or physics book: E.g., in a calculus book, there's a lot behind the Riemann integral, and in physics, behind the electric field, so in those books we don't express everything as just simple arithmetic with comments.
And, yes, in my code, when I write a function or subroutine, I give it a mnemonic name and have it do some work that has meaning that is described in the comments.
But here is for me a telling point: In grad school, my best math prof just stated that math is written in complete sentences. So, the mathematical symbols do not replace the natural language, e.g., English in the sentences, paragraphs, sections, chapters, etc. Usually good mathematical notation has some mnemonic hints of the meaning, but, still, the meaning is in the text, not the symbols. So, net, there is limited utility and future in trying to have programming language syntax replace the English language for communicating the meaning.
No such luck in Java et al.
But this is easy in prototype-based languages.
Maybe they were fifteen years ago, I don't think that is the case now, the two most popular OO languages (Java and C#) don't even support multiple inheritance.
I seldomly use mutiple inheritance in any language, and instead prefer composition.
That seems really outlandish and obviously flat-out wrong. I assume, then, that you have good reasons to have this contrarian position, and I am really curious to hear what they are :).
When I think of C++ I think of "C with classes." In other words... C with objects. And... a bunch of other stuff tacked on over the years. Which is not to discount that stuff---maybe that is what your argument rests on; if so, that's fine.
My biggest thing in support of OO is that it encourages DRY more affectively than other paradigms, IMO. But I am finding Rust's balancing of functional w/ OO allows for you to pick the best method to DRY (don't repeat yourself).
Anyone who doesn't practice DRY programming doesn't understand the cost of maintaining production code and technical debt.
C++ is not a C with classes. It is a C with namespaces, templates and RAII.
The list example is a bit contrived too. A simple templated class for the list node could give both encapsulation and the exact same speed and allocation characteristics as the C code.
Besides, in OO languages, people are coming around to the idea of favoring composition over inheritance anyway.
So this person is basically arguing against a strawman.
#!/usr/bin/env perl
package Flying;
use Moo::Role;
sub flap {
# do stuff;
}
1;
package Bat;
use Moo;
with 'Flying';
has wings => (
is => 'ro',
default => 2,
);
1;
package FruitBat;
use Moo;
extends 'Bat';
1;
package Bird;
use Moo;
with 'Flying';
# Implementation left to the reader.
1;
use warnings;
use strict;
use mro;
use Bat;
use FruitBat;
use Data::Dumper;
print Dumper mro::get_linear_isa('Bat');
print Dumper mro::get_linear_isa('FruitBat');
print Dumper mro::get_linear_isa('Bird');
__END__
$ perl /tmp/demo.pl
$VAR1 = [
'Bat',
'Moo::Object'
];
$VAR1 = [
'FruitBat',
'Bat',
'Moo::Object'
];
$VAR1 = [
'Bird',
'Moo::Object'
];I went back to my OO roots and c#/c++ and carried on mostly as I did before. Why?
Simply that its easier to rationalise a large system in terms of objects and actions. Even atypical OO languages like Go use this model.
What I did take away was limited mutability (not total immutability) and some functional paradigms such as map/filter and a well founded opinion that one shouldn't listen to programming religious wars and use what works for you.
I'm currently of the opinion that OO is basically a form of module system: useful for carving up large problems into more manageable ones, but not necessarily a good model for writing algorithms.
This is at most a rant against the misguided implementation in certain mainstream languages. Not against OO in general.
The fact that Alan Kay meant something different is irrelevant.
While you can build messaging and composition into most languages, they're usually considered application models in their own right, not core features. (Objective C is an exception, among a handful of others.)
So I think it's a valid question - why do mainstream languages still present this model as a core feature when other models are less rigid, more expressive, easier to work with, and better candidates for language fundamentals?
On the contrary, we see OOP being used in the majority of programming projects.
I have been waiting for a proof that functional programming is easier for a very long time now. It doesn't seem to be the case, and I'm getting sick of fanboyism that insists that it is.