Learning from SWT
Although blogs often suggest the freshest of web content, I often find myself reading things months or years old, by following a blog’s links.
An example is some OTI stuff on SWT, from way back in 2001. The first article shows rather clearly the impact of two different approaches to using JNI for accessing platform-specific GUI widgets. By strictly using JNI as no more than a forwarding proxy, they get a single API to support, all the power of java for all of their programming logic, and much simpler debugging and profiling.
This led me to a second SWT article which is a good example of coding standards in action. The standards are defensive, and influence the api design, e.g.
This rule occasionally leads to API that seems artificial. For example, GC.getClipping (Region) forces the programmer to create a Region in order to get the clipping region from a GC. Although it might have been a bit “prettier” to provide GC.getClipping () that returned a Region, this would break the rule because it would have to allocate an operating system resource outside of a constructor. While it could be documented that the programmer needs to free the Region returned by GC.getClipping (), programmers don’t always read the documentation. Making the programmer call the constructor for the Region makes it clear that it is the programmer’s responsibility to free the resource.
In the “how did I get here” department: wanting to see the contents of Steve McConnell’s second edition of Code Complete, I bugmenotted my way past cc2e’s registration. Out of curiosity, I clicked the “profile” button for the bugmenot user, and saw a mailinator email address. “That’s cool,” I thought, and seeing that its creator had a blog, I stopped by there and read his java rant. Which had a kind reference to SWT.