• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Generics and WO
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Generics and WO


  • Subject: Re: Generics and WO
  • From: Ian Joyner <email@hidden>
  • Date: Tue, 15 Aug 2006 14:06:16 +1000

Reading up on this a bit more, I note that generics are implemented, not by changing the JVM, but by 'type erasure'. The upside of this is that programs using genericity are able to run on older JVMs and you still get compiler checks and are able to cast your casts to the wind.

Downside though is that cast checks will still be done at runtime, even though a class cast error can't occur, so there is no speed up due to stronger typing.

Now I have to admit to being a bit lazy and have just been using NSArray, NSDictionary, etc in preference to Java Collections and Arrays, but now with genericity, the Java collection hierarchy has a lot more going for it. I gather Apple have put WO development on hold, or opened it up a lot more. So does that mean that NS (a dumb naming convention) structures will be deprecated (a word that itself should be deprecated, I'm in a very opinionated mood today in my opinion!) or maybe enthusiasts out there will make them generic?

Another nice liberation in Java 1.5 is to allow covariant return types, so you can:

class A {
	public A another () { return clone (); }
}

class B extends A {
	public B another () { return clone (); }
}

OK, it's still not as convenient or nice as Eiffel's type system, notably with anchored types that let you:

class A
	another: like Current is
		result := Current.clone
	end
end

class B inherit A
end

... no need to redefine 'another' in B, because 'like Current' implicitly redefines the return type to the subclass. Oh, and I just realised Eiffel has deep_copy and deep_clone as well (and actually still a better data structures library).

Oh, well, at least Java is getting there, and WO will be greatly improved if it can take advantage of the new facilities.

On 10/08/2006, at 5:21 PM, Ian Joyner wrote:

I know Chuck noticed in my code postings that I annotate all my collections and enumerations with a generic label. For example:

	NSArray /*[String]*/ string_array = new NSArray ();
	Enumeration /*[String]*/ e = string_array.objectEnumerator ();

but this is just dumb documentation and now Java 1.5 has generics for real (and they seem to have done a good job with type conformance rules and constrained genericity (wonder where they got that from, although they have had enough languages do generics before, even C++ with its awful templates). Real generics get rid of all those horrible type casts and better still any runtime ClassCastExceptions (making runtime code more efficient too).

Is there any indication that WO will adopt genericity in the near future. I have looked at making subclasses of NSArray and NSMutableArray (XNSArray <T> and XNSMutableArray <T> respectively), but you can't assign an XNSMutableArray to XNSArray, since XNSMutableArray <T> is not a subclass of XNSArray <T>.

So you are really stuck with adding the generic parameter to the original classes, NSArray <T> and NSMutableArray <T>, and this change does not break any existing code which uses them unparameterized (I think, I have not read it all yet).

EO- and WODisplayGroup would also be good to have a generic parameter so you could have

EODisplayGroup <My_entity> dg;
My_entity m = dg.selectedObject (); // No cast or possibility of run-time ClassCastException.


	for (My_entity me: dg.selectedObjects ()) {
		... do something to me
	}

Any rumblings that genericity might happen soon?

Ian

_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Generics and WO
      • From: Lachlan Deck <email@hidden>
References: 
 >Generics and WO (From: Ian Joyner <email@hidden>)

  • Prev by Date: Re: Tutorial project
  • Next by Date: One Thought about what Web 2.0 Means
  • Previous by thread: Generics and WO
  • Next by thread: Re: Generics and WO
  • Index(es):
    • Date
    • Thread