Friday, February 11, 2005

Gosling on SWT

In a presentation to an Australian user group, James Gosling said some things about SWT that I thought were a little far out, so I asked Chris Grindstaff (who helped me with the SWT section in TIJ4) about it, and he allowed me to publish his comments:

"From memory, there were some OTI Smalltalkers 7-8 ago who did try to convince Sun they were going down the wrong path with AWT/Swing. Swing is very analogous to VisualWorks Smalltalk's approach of emulating the widget toolkit. OTI had been native UI toolkits in Smalltalk for many years and thought it was a better approach. A lot of those folks are responsible for SWT today. They thought emulated was the wrong way to go and they still do.

"Gosling says AWT == SWT. That's sort of true but less true than more. The big difference between the two is AWT is very much least-common-denominator across all platforms. SWT isn't. The other significant difference is AWT chose to hide the emulation layer in C. In other words, java.awt.Button is the same on all platforms, while the native peer differs on each platform. One of the consequences of this is porting is harder, some things are in Java, some aren't. It also makes for a larger footprint because a java.awt.Button has fields for it's size, bounds, etc that the OS also has.

"In SWT the org.eclipse.swt.Button Java/class is different on each platform. The SWT lib does nothing but stuff methods straight to the OS. One toolset and less duplication.

"Gosling also claims SWT is way simple. That's not true either. It's not as full-featured as Swing but that's also by design.

"The API matching Windows is somewhat fair, but much preferable to least common denominator with AWT. Where something doesn't exist on a platform an emulated version is created. But again that's better than not implementing a tree, table, or notebook, example, just because they don't exist on one of the targeted platforms.

"Porting and consistency aren't nightmares on other platforms. One of the beauties of moving the widget toolkit code from C to Java is your platform gurus can program the widget toolkit in Java using Eclipse. So when you look at the SWT source for a org.eclipse.swt.Button on Windows it makes a lot of sense to a Windows guru, likewise for the widgets on the Mac, they make lots of sense to a Carbon guru.

"The proof is in the pudding. You rarely see an AWT application, even most Swing apps are ugly and OS strangers. You can get close but never close enough. For example when MS added theme support in Windows XP, SWT got those for free. There are more and more SWT built applications appearing. In general, why struggle to emulate pixel by pixel what Microsoft, Apple, and all the Linux developers are doing for you? Don't reinvent, use.

"You can also check out the article I wrote for Linux magazine, although I probably don't say anything I haven't said here: SWT: Eclipse's Secret Weapon"

MindView Home Page