Documentation, more, more

Richard A. O'Keefe ok at cs.otago.ac.nz
Thu Sep 11 22:59:05 UTC 2003


I wrote:
	> If I want something that is like a Java Vector but has a few more
	> operations, and I want it to be usable anywhere a Vector is usable,
	> then it *has* to be a subclass of Vector.  You can do this in Java 1.2,
	> but you had better know everything about Vector.  (One machine here has
	> /usr/java1.2/src.jar, another machine doesn't.  Too bad about anyone
	> trying to extend Vector on the second machine, eh?)

Dustin Sallings <dustin at spy.net> appears to have misunderstood me
rather seriously:

		That's a different model.  Source code is not required
	for extending classes in Java.  Vector is a stable (though old
	and what should be considered deprecated) API that can certainly
	be extended.
	
It isn't *JAVA* that needs the sources if you want to extend it,
it's the *PROGRAMMER* who needs the sources.  There can be important
information about a class, such as a class invariant, stated as plain
comments, not Javadoc comments.

I note that *nothing* in the Java 2se 1.4.1 JavaDoc page for Vector
says that it is deprecated, *nothing* in the 1.4.1 "Deprecated API"
web page says it is deprecated, and on the contrary, in 1.2 it was
fitted into the 1.2 Collections framework.

There are one or two important things that someone extending Vector needs
to know which are NOT in the JavaDoc page; for anything that really needs
"isa Vector" rather than "hasa Vector" you as a programmer do in fact
need to read the source code to be sure you've got it right, even though
the Java *compiler* doesn't need the source code to believe you.

	
		If you want to override Vector to print itself with the
	size, I don't have to know everything about Vector, I just have
	to do this (no, this isn't *exactly* how I'd do it):

	public class MyVector extends Vector {
	    public String toString() {
		return "{MyVector with " + size() + " elements}");
	    }
	}

Yes, but that was a trivial example.  Even if you had used 'elementCount'
instead of size(), you would still have been covered by the documentation.
There are things to know about Vectors (and other Collections) that are not
quite covered in the documentation.  (Although I must say that the 1.4.1
documentation is better than some of the older documentation I was using.)
	
Obviously you could extend _any_ class with a method which only used
public methods to achieve its effect; that tells us nothing.



More information about the Squeak-dev mailing list