Object Oriented Programming is out of the CMU Computer Science Introductory Curriculum

70 views
Skip to first unread message

Chris Koerner

unread,
Mar 21, 2011, 9:14:20 AM3/21/11
to java...@googlegroups.com

Cédric Beust ♔

unread,
Mar 21, 2011, 12:54:48 PM3/21/11
to java...@googlegroups.com, Chris Koerner


On Mon, Mar 21, 2011 at 6:14 AM, Chris Koerner <ches...@gmail.com> wrote:

Well, that's CMU, so this should't come as a surprise :-)

Having said that, I find this disappointing. I think it's important to make functional programming an integral part of a CS undegrad/grad course, but replacing OO with it? This makes no sense.

Both methodologies are extremely important and they are going to be around for decades, especially OO. OO should not be an optional class.

--
Cédric


Carl Jokl

unread,
Mar 21, 2011, 1:48:03 PM3/21/11
to The Java Posse
It does look like a high degree of pet subject enthusiasm on the part
of the person running the course. As much as Java is mentioned in the
article, Java did not invent object orientation and there are many
other Object Oriented languages or languages which have embraced
object orientation after their initial invention. I don't see
functional programming being the silver bullet which makes all Object
Oriented systems redundant.

Is what is being suggested here that data and functionality should be
kept separate for the greater good? I can see some of what is being
suggested but I don't believe that having data in special data
structures and functions to work on the data automatically makes a
system more modular and reusable. The code in the function may expect
data in a very problem specific way or the function may perform
functionality which is so specific to a given problem that it may not
be any more reusable than code on an object where the data and code
are combined together.

Having data and functionality separate is somewhat the case with C
isn't it. C however does have some state by virtue of static variables
which can point to some other kinds of state holding structures.

I don't know. Some of these food fights and almost dogmatic talk of
the one enlightened way of doing things can make me feel fed up with
the whole programming community. I always end up doing the wrong thing
according to someone.

Alexey Zinger

unread,
Mar 21, 2011, 2:58:41 PM3/21/11
to java...@googlegroups.com
Indeed, I've never done anything right either :)  What I don't understand is why functional and OO are seen as mutually exclusive.  One of the main things being touted about Scala was that it would make it easy for a traditional OO Java person to dip their toe in Scala's pool and proceed into more functional aspects of it in a gradual, organic way.  Similarly, we're adding functional libraries and features into Java's own ecosystem and the sky isn't falling.  I see them as orthogonal techniques -- both good to know and can play well with one another under the right circumstances.
 
Alexey



From: Carl Jokl <carl...@gmail.com>
To: The Java Posse <java...@googlegroups.com>
Sent: Mon, March 21, 2011 1:48:03 PM
Subject: [The Java Posse] Re: Object Oriented Programming is out of the CMU Computer Science Introductory Curriculum
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+unsub...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.


Cédric Beust ♔

unread,
Mar 21, 2011, 2:59:48 PM3/21/11
to java...@googlegroups.com, Carl Jokl
What's really mystifying to me is that I really don't see OO and functional operate at the same level, let alone being mutually exclusive with each other.

Functional is more about the implementation of your methods while OO gives you a way to organize them in a way that maximizes reuse and encapsulation.

-- 
Cédric



--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.




--
Cédric


Kevin Wright

unread,
Mar 21, 2011, 5:47:46 PM3/21/11
to java...@googlegroups.com, Carl Jokl
I fail to understand why Object-Oriented and Functional programming are so often portrayed as opposites.  Nothing could be further from the truth... if anything, the two paradigms are completely orthogonal.

The real opposites here are imperative vs declarative programming, with FP being a subset of declarative programming.  Many languages (including Java) are able to support both imperative and declarative styles with varying degrees of ease.

Object-Orientation works just fine in a purely functional context, and Alan Kay - who coined the term - did his first experiments in the area of OO building on top of LISP...

CLOS gives a clear example that FP doesn't mean not-OO.  Or if you prefer something closer to home, JodaTime is a very good example of functional design.

So does avoiding OO in the first semester/year/whatever mean that it's being abandoned in favour of pushing FP?   Absolutely not!
It just means that the lecturers recognise it to be a paradigm more suited to larger composition and to system level design, problems that aren't really appropriate for teaching someone's first steps in programming.  For smaller-scale work, functional composition is far easier to teach and understand,


--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.




--
Kevin Wright

gtalk / msn : kev.lee...@gmail.com
mail: kevin....@scalatechnology.com
vibe / skype: kev.lee.wright
quora: http://www.quora.com/Kevin-Wright
twitter: @thecoda

"My point today is that, if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger" ~ Dijkstra

Kevin Wright

unread,
Mar 21, 2011, 5:54:54 PM3/21/11
to java...@googlegroups.com, Cédric Beust ♔, Carl Jokl


2011/3/21 Cédric Beust ♔ <ced...@beust.com>

What's really mystifying to me is that I really don't see OO and functional operate at the same level, let alone being mutually exclusive with each other.

Functional is more about the implementation of your methods while OO gives you a way to organize them in a way that maximizes reuse and encapsulation.

-- 
Cédric


... What he said ...

 

Ricky Clarkson

unread,
Mar 21, 2011, 7:23:33 PM3/21/11
to java...@googlegroups.com, Kevin Wright, Carl Jokl
Lisp (and hence CLOS) is procedural rather than functional, like C or Python.  It just has better support for untyped FP than most.

mP

unread,
Mar 21, 2011, 10:02:06 PM3/21/11
to java...@googlegroups.com, Carl Jokl, Kevin Wright
The simple explaination being that most professors in universities, cant get a real job so most dont really know what they are talking about.

Alan Kent

unread,
Mar 21, 2011, 10:29:50 PM3/21/11
to java...@googlegroups.com
On 22/03/2011 1:02 PM, mP wrote:
> The simple explaination being that most professors in universities,
> cant get a real job so most dont really know what they are talking about.

I am sure its nothing to do with job satification of teaching, helping
the next generation to get skills that will enable them to get a good
life, more flexible work hours, to be paid to look into new technologies
to determine their relevance to course materials, to have the
possibility of doing funded research, then having a pool of bright
students you can use to progress your research interests where the only
requirement is to make sure they learn something along the way, .... ;-)

I used to work at a university - most of the fellow professors did not
*want* to get a "real" job as you put it. They got paid less, but had a
lot more fun and a lot less stress! Its not clear to me yet who is
"smarter" here.

Just my 2c worth.
Alan

mP

unread,
Mar 21, 2011, 10:33:28 PM3/21/11
to java...@googlegroups.com, Alan Kent
Your commentary precisely backs up my point, they remain in academia which has a different focus which is quite different to the targets and goals of the business world. Therefore after all that their attention and priorities are more selfish towards their opinions and bias rather than what exactly is required in a real world environment.

Cédric Beust ♔

unread,
Mar 21, 2011, 11:22:25 PM3/21/11
to java...@googlegroups.com, Alan Kent
Regardless of how everybody feels about this topic, the explanation itself bothers me:

"Object-oriented programming is eliminated entirely from the introductory curriculum, because it is both anti-modular and anti-parallel by its very nature, and hence unsuitable for a modern CS curriculum."

It looks like whoever made that decision has a pretty big chip on their shoulder and it's pretty clear from that sentence alone that students going to his/her class will get a pretty incomplete and biased picture.

Exactly the opposite of what a renowned university such as CMU is expected to provide.

-- 
Cédric


--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.




--
Cédric


Alan Kent

unread,
Mar 22, 2011, 1:17:52 AM3/22/11
to java...@googlegroups.com


There is a aspect to this which is correct - but it can be taken too
far. Just because their personal objective is not business oriented
does not mean they cannot teach things useful to programmers who will
work in the business world.

However, Professors also teach multiple subjects, and the ones I know
teach some subjects that are not so interesting to them, but they accept
that as part of the job. We all have things in our jobs that are less
enjoyable I suspect.

How do you get feedback from real industry? Well, the University I was
at teaches post graduate students whom the lecturers talk to. They do
read up on various sources. They talk to people in industry. But they
also see the importance of teaching skills like problem solving and
giving breadth of experience. Teaching a student one technology is not
always that useful - technology dates. Its teaching the skill to pick
up new technologies that is more useful. You just have to pick some
technology to use in practice as a vehicle.

Anyway, I don't think this line of discussion is being that productive
so I am going to drop out of it. I just reacted to what appeared to be
pretty blanket statements. I know a number of academics that have moved
into industry, and industry people that teach at Universities. I would
not necessarily agree that business people are better teachers than
Professors. But I do agree that I have come across Professors that are
very much focussed on their own pet interests - but I find similar
people in industry too! I think its a part of being human! ;-)

Alan

Reinier Zwitserloot

unread,
Mar 22, 2011, 7:05:32 AM3/22/11
to java...@googlegroups.com
I fell over this too. There's a nasty implicit logic error there: "most popular language based on paradigm X is seemingly bad at Y and Z, so let's conclude that paradigm X is 'clearly' anti-Y and anti-Z". That, and it sounds a little too arrogant. I'm aware this might sound a little hypocritical coming from me, but I'm not responsible for designing the CS curriculum at a university of some renown, so there's that.

Russel Winder

unread,
Mar 23, 2011, 12:55:52 PM3/23/11
to java...@googlegroups.com, Carl Jokl, Kevin Wright

If this is the attitude people are going to have and express it's no
wonder the world is a totally f$$$ed up place.

There are a very large number of people out in industry and commerce who
are so appallingly awful at programming they shouldn't be allowed
anywhere near an IDE let alone an editor.

It is true there are people trying to teach programming who do not have
a clue what they are talking about. It is also true that there are
people teaching programming who are far, far, far better programmers
than anyone in industry and commerce -- bar none.

--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel...@ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: rus...@russel.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder

signature.asc

Russel Winder

unread,
Mar 23, 2011, 1:05:24 PM3/23/11
to java...@googlegroups.com, Alan Kent
On Mon, 2011-03-21 at 20:22 -0700, Cédric Beust ♔ wrote:
[ . . . ]

>
> It looks like whoever made that decision has a pretty big chip on
> their shoulder and it's pretty clear from that sentence alone that
> students going to his/her class will get a pretty incomplete and
> biased picture.
[ . . . ]
>

I think we can see fallout from the 1980s. Then it was Imperative vs.
Declarative but rather than coming to any sane resolution, the battle
evolved into Functional vs Object-oriented. Of course C was what people
who weren't using Pascal, Fortran, Ada, Modula-2, Smalltalk, etc. were
using and thus C++ became the poster child of object-orientation. Which
in itself is a bit strange as the object-oriented of C++ wasn't the
object-oriented that the object-oriented folk were fighting for!

In the UK, successive governments have over the last 20 years tried to
destroy the university system. Most of the quality
imperative-supporting programmers/teachers left for sensible work--life
balance and salaries, leaving a much higher percentage of
declarative/functional-supporting folk in academia. These people
remember the 1980s and are now going in for the final victory of the
Paradigm Wars. Looks like something analogous is happening in the USA.

Did you fight in the Paradigm Wars?

signature.asc

Carl Jokl

unread,
Mar 23, 2011, 1:18:31 PM3/23/11
to The Java Posse
Maybe the UK University system will be bought out by Tesco.

All hail Tesco.

I remember the 80's and by golly they were awesome and we are not
talking the regular kind of awesome rather the double fireball attack,
laser dynamite rocket underpants ninja nuclear plasma war rabbit kind
of awesome. Except for the recession but I was a child so that wasn't
my problem.

Russel Winder

unread,
Mar 23, 2011, 1:39:04 PM3/23/11
to java...@googlegroups.com
On Wed, 2011-03-23 at 10:18 -0700, Carl Jokl wrote:
> Maybe the UK University system will be bought out by Tesco.
>
> All hail Tesco.

Like Macdonald's bought the USA school system?

> I remember the 80's and by golly they were awesome and we are not
> talking the regular kind of awesome rather the double fireball attack,
> laser dynamite rocket underpants ninja nuclear plasma war rabbit kind
> of awesome. Except for the recession but I was a child so that wasn't
> my problem.

What I liked about the 1980s was that at UCL we were able to teach the
first course in programming for computer scientists using Miranda for 10
weeks then C++ for 10 weeks. I like to think we created a more rounded
sort of programmer than the current system does. Of course we taught
economists, physicists and chemists Fortran just as they asked. And C
to the electronics engineers, because they thought C++ was too airy
fairy -- classes, that not real code.

signature.asc

Alexey Zinger

unread,
Mar 23, 2011, 2:09:00 PM3/23/11
to java...@googlegroups.com
This seems like such a strange thing.  We're talking about computer science and engineering, not exactly liberal arts stuff.  I understand that many of us feel passionate about technology, mathematical elegance and all of that, but the moment I start to take sides in a "paradigm war" on the basis of personal allegiance to some thought camp rather than pragmatism is the moment I should lose all credibility and "exit the battlefield".
 
Alexey



From: Russel Winder <rus...@russel.org.uk>
To: java...@googlegroups.com
Cc: Alan Kent <ALAN....@saic.com>
Sent: Wed, March 23, 2011 1:05:24 PM
Subject: Re: [The Java Posse] Re: Object Oriented Programming is out of the CMU Computer Science Introductory Curriculum

Chris Phelps

unread,
Mar 23, 2011, 2:23:04 PM3/23/11
to java...@googlegroups.com
What makes you think science is not full of personal allegiance, politics, and paradigm wars?  A friend of mine is a professor in a scientific field, and he's constantly dealing with these kinds of issues derailing new findings and new interpretations.

Chris


Russel Winder

unread,
Mar 23, 2011, 2:28:47 PM3/23/11
to java...@googlegroups.com
On Wed, 2011-03-23 at 11:09 -0700, Alexey Zinger wrote:
> This seems like such a strange thing. We're talking about computer
> science and engineering, not exactly liberal arts stuff. I understand
> that many of us feel passionate about technology, mathematical
> elegance and all of that, but the moment I start to take sides in a
> "paradigm war" on the basis of personal allegiance to some thought
> camp rather than pragmatism is the moment I should lose all
> credibility and "exit the battlefield".

If it hadn't been for all the people taking sides based on politics and
"belonging to a particular group" then object-oriented would not be
where it is today.

Read Thomas Kuhn, "The Structure of Scientific Revolutions". The
Functional vs. Object-oriented Paradigm War is a wonderful paradigm of
exactly what he was putting forward as science.

signature.asc

Alexey Zinger

unread,
Mar 23, 2011, 2:31:16 PM3/23/11
to java...@googlegroups.com
No doubt, it goes on.  I just don't understand it.
 
Alexey



From: Chris Phelps <cjp...@gmail.com>
To: java...@googlegroups.com
Sent: Wed, March 23, 2011 2:23:04 PM

Kevin Wright

unread,
Mar 23, 2011, 3:12:42 PM3/23/11
to java...@googlegroups.com, Russel Winder, Alan Kent
On 23 March 2011 17:05, Russel Winder <rus...@russel.org.uk> wrote:
On Mon, 2011-03-21 at 20:22 -0700, Cédric Beust ♔ wrote:
[ . . . ]
>
> It looks like whoever made that decision has a pretty big chip on
> their shoulder and it's pretty clear from that sentence alone that
> students going to his/her class will get a pretty incomplete and
> biased picture.
[ . . . ]
>

I think we can see fallout from  the 1980s.  Then it was Imperative vs.
Declarative but rather than coming to any sane resolution, the battle
evolved into Functional vs Object-oriented.  Of course C was what people
who weren't using Pascal, Fortran, Ada, Modula-2, Smalltalk, etc. were
using and thus C++ became the poster child of object-orientation.  Which
in itself is a bit strange as the object-oriented of C++ wasn't the
object-oriented that the object-oriented folk were fighting for!


My experience is that most folk familiar with FP are still thinking of it in terms of imperative vs declarative, and only those firmly entrenched in C++ and its offspring seem to think that OO is somehow the opposite to FP.

In many ways, declarative programming *has* become wildly successful, and was almost guaranteed to be used in any system with a data storage requirement prior to the NoSQL movement - making it more widely adopted than Java, C++, C#, etc.  Even now, all the NoSQL alternatives that I've seen have a declarative query syntax, with SQL already having proved the power of this paradigm when it came to clustering, sharding, and other such requirements for an application to scale outwards.
 
As for the OO that folk were originally asking for; independent units that communicate by message passing, we now have it.  That particular style is now known as actors, and the current showcase for the technique is Erlang, typically considered to be an FP sort of a language.  It does amuse me how these things so often come full circle...

In the UK, successive governments have over the last 20 years tried to
destroy the university system.  Most of the quality
imperative-supporting programmers/teachers left for sensible work--life
balance and salaries, leaving a much higher percentage of
declarative/functional-supporting folk in academia.  These people
remember the 1980s and are now going in for the final victory of the
Paradigm Wars.  Looks like something analogous is happening in the USA.

Did you fight in the Paradigm Wars?

--
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel...@ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: rus...@russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

Russel Winder

unread,
Mar 23, 2011, 4:23:28 PM3/23/11
to Kevin Wright, java...@googlegroups.com, Alan Kent
On Wed, 2011-03-23 at 19:12 +0000, Kevin Wright wrote:
[ . . . ]

> My experience is that most folk familiar with FP are still thinking of
> it in terms of imperative vs declarative, and only those firmly
> entrenched in C++ and its offspring seem to think that OO is somehow
> the opposite to FP.

And then there is "applicative" which for a while appeared to be
distinct from "declarative" and "functional". That's the problem with
jargon, there is an awful lot of it, and each clique defines it
differently ;-)

> In many ways, declarative programming *has* become wildly successful,
> and was almost guaranteed to be used in any system with a data storage
> requirement prior to the NoSQL movement - making it more widely
> adopted than Java, C++, C#, etc. Even now, all the NoSQL alternatives
> that I've seen have a declarative query syntax, with SQL already
> having proved the power of this paradigm when it came to clustering,
> sharding, and other such requirements for an application to scale
> outwards.

As we know C++ template programming is functional programming, so much
of C++ is functional :-) Also of course the whole STL generic
programming and especially generic functions has made a huge difference
to C++ such that declarative is a massive factor. Unlike Java which
chose to ignore iterators à la C++ -- another paradigm war but this one
was fought in the late 1990s. Joshua Bloch has at least acknowledged
that the Java Collections framework took the wrong architectural
decision; that the JGL architecture would have been far superior. I
even wrote the beginnings of a algorithms and data structures library
myself mixing the best of all bits. Of course it went nowhere because
Sun was a bit of a steam roller enforcing "right thinking" about Java.
And then there is Functional Java.

> As for the OO that folk were originally asking for; independent units
> that communicate by message passing, we now have it. That particular
> style is now known as actors, and the current showcase for the
> technique is Erlang, typically considered to be an FP sort of a
> language. It does amuse me how these things so often come full
> circle...

But actors pre-date object-oriented by about 10 years. It still
irritates me that C++ rejected message passing in favour of some
doublethink about function call being equivalent to message passing.
Long live active objects! Pool-T, UC++, KC++ rule . . .

signature.asc

Cédric Beust ♔

unread,
Mar 23, 2011, 4:49:06 PM3/23/11
to java...@googlegroups.com, Russel Winder, Kevin Wright, Alan Kent
On Wed, Mar 23, 2011 at 1:23 PM, Russel Winder <rus...@russel.org.uk> wrote:
Unlike Java which
chose to ignore iterators à la C++ -- another paradigm war but this one
was fought in the late 1990s.

First of all, before the enhanced for loop came out, Java was using iterators pretty much everywhere in collection loops:

for (Iterator it = collection.iterator(); it.hasNext(); ) {
  Object o = it.next();
}

This followed the techniques made popular by the STL, but it was seen as not just a lot of boiler plate but also exposing users to needless implementation details: if all you want is enumerating the objects in a collection, why should you even care about the concept of iterators?

Thus, the enhanced for loop was born:

for (Object o : collection) {
  ...
}

No more iterators, much easier to read, and the only objects involved in this construct are the ones you care about: the collection and the objects it contains.

 
 Joshua Bloch has at least acknowledged
that the Java Collections framework took the wrong architectural
decision;

Uh, citation? We came up with the enhanced for loop precisely to hide iterators, so I still claim that the enhanced for loop is a big improvement over what we had before.

Or are you referring to something else?

--
Cédric


Josh Berry

unread,
Mar 23, 2011, 4:56:30 PM3/23/11
to java...@googlegroups.com
2011/3/23 Cédric Beust ♔ <ced...@beust.com>:

> Or are you referring to something else?

I think he is referring to the fact that iterators were not an
original part of the collections framework.

Alexey Zinger

unread,
Mar 23, 2011, 5:00:08 PM3/23/11
to java...@googlegroups.com
That doesn't seem right.  java.util.Iterator and the rest of the collections stuff (java.util.Collection) both date back to Java 1.2.  Before that, there was java.util.Enumeration.  Is that what you mean?
 
Alexey



From: Josh Berry <tae...@gmail.com>
To: java...@googlegroups.com
Sent: Wed, March 23, 2011 4:56:30 PM

Subject: Re: [The Java Posse] Re: Object Oriented Programming is out of the CMU Computer Science Introductory Curriculum
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+unsub...@googlegroups.com.

Josh Berry

unread,
Mar 23, 2011, 5:15:52 PM3/23/11
to java...@googlegroups.com
Yeah, and I was just guessing at what the other poster meant. :)

Kevin Wright

unread,
Mar 23, 2011, 5:35:00 PM3/23/11
to Cédric Beust ♔, Russel Winder, Alan Kent, java...@googlegroups.com


On 23 Mar 2011 20:53, "Cédric Beust ♔" <ced...@beust.com> wrote:
>
>
>
> On Wed, Mar 23, 2011 at 1:23 PM, Russel Winder <rus...@russel.org.uk> wrote:
>>
>> Unlike Java which
>> chose to ignore iterators à la C++ -- another paradigm war but this one
>> was fought in the late 1990s.
>
>
> First of all, before the enhanced for loop came out, Java was using iterators pretty much everywhere in collection loops:
>
> for (Iterator it = collection.iterator(); it.hasNext(); ) {
>   Object o = it.next();
> }
>
> This followed the techniques made popular by the STL, but it was seen as not just a lot of boiler plate but also exposing users to needless implementation details: if all you want is enumerating the objects in a collection, why should you even care about the concept of iterators?
>
> Thus, the enhanced for loop was born:
>
> for (Object o : collection) {
>   ...
> }
>
> No more iterators, much easier to read, and the only objects involved in this construct are the ones you care about: the collection and the objects it contains.
>

Of course there are iterators, they're just made implicit through a bit of syntactic sugar.  Ultimately, the name of this construct is a dead giveaway, it's a for "loop".

The thing is fundamentally imperative, and only has value through iterating over every element in a collection and optionally performing some side effect. If it were to return a value of some sort, then it's possible to imagine a future version of Java in which iterators weren't involved, but that simply ain't the case right now.

Russel Winder

unread,
Mar 24, 2011, 3:48:41 AM3/24/11
to Cédric Beust ♔, java...@googlegroups.com, Kevin Wright, Alan Kent
On Wed, 2011-03-23 at 13:49 -0700, Cédric Beust ♔ wrote:
[ . . . ]
>
> First of all, before the enhanced for loop came out, Java was using
> iterators pretty much everywhere in collection loops:
>
> for (Iterator it = collection.iterator(); it.hasNext(); ) {
> Object o = it.next();
> }

My point was that the interface of Iterator, and Enumerator before it,
was the wrong choice. This implements forward iterator which is very
restrictive -- especially if what you really want is bidirectional
iterator or random access iterator.

> This followed the techniques made popular by the STL, but it was seen
> as not just a lot of boiler plate but also exposing users to needless
> implementation details: if all you want is enumerating the objects in
> a collection, why should you even care about the concept of iterators?

No, Collections did not follow STL. Iterator (and indeed Enumerator
before it) didn't learn the lessons of STL at all. The STL has a far
richer view of iterator than Collections offers. It was JGL that tried
to realize this richness, as did my own ADS -- a library created to
teach all this stuff to students -- Collections ignored all the
knowledge of how to use iterators in C++ that STL had built up.

You cannot build up the rich generic programming style that the C++
iterator infrastructure allows based only on forward iterator. This is
why JGL (and ADS) were created. However, Collections was the standard,
so JGL died. The story of ADS is for another place.

>
> Thus, the enhanced for loop was born:
>
>
> for (Object o : collection) {
> ...
> }

Well this (or at least something like it) should have been in Java in
the first place. This idiom was already in many languages in the early
1990s, but the Oak/Java folk chose to stick to the very low-level view
of iteration. They should perhaps have talked more to the Self folk
who apparently were in the next door offices.

>
> No more iterators, much easier to read, and the only objects involved
> in this construct are the ones you care about: the collection and the
> objects it contains.

If all you want is a forward iterator. In the cases where you want
that, foreach is ideal -- witness that most languages have this
construct these days.

>
>
> Joshua Bloch has at least acknowledged
> that the Java Collections framework took the wrong
> architectural
> decision;
>
>
> Uh, citation? We came up with the enhanced for loop precisely to hide
> iterators, so I still claim that the enhanced for loop is a big
> improvement over what we had before.

I am not disagreeing with this for the one use case of forward iteration
over the whole container -- which happens to be a majority use case and
so crucially important. However, it is not 100% of the use cases, so
other iteration structures are needed. C++, D, etc. provide that richer
iteration framework, Java does not. java.util.Iterator is and always
will be a forward iterator that does not provide a rich enough iteration
structure to provide the generic programming as seen in C++, D, etc.

>
> Or are you referring to something else?

Personal communication, JavaOne 2004.

I finally met up with Neal Gafter, with whom I had been having various
email exchanges over the previous 8 years, on the Sun stand and Joshua
Block was there as well. The conversation naturally turned to
Collections and thence to the iterator structures. Paraphrased
Joshua's comment was "I am happy with the way things are going forward,
but if I were to do it again, I would probably do it differently, more
like STL."

signature.asc
Reply all
Reply to author
Forward
0 new messages