Wednesday, May 30, 2007

BOF-6012 Javascript Programming Language:

Best Practices for Developers on the Java Platform

2007 8 May, 20:00
Tuesday

Eugene Lazutkin, Sun (Dojo)
Gregory Murry, Sun
Sang Shin, Sun (javapassion.com)

http://www.javapassion.com/ajax/BOF-6012.pdf

General JavaScript ideas and idioms
Peter-Paul Koch's Quirksmode web site:
http://www.quirksmode.org/js/
Douglas Crockford's web site:
http://www.crockford.com/javascript/
Please read his articles on “Classical inheritance...” and
"Prototypal inheritance...”

http://dojotoolkit.org/
http://www.jslint.com/lint.html

Javascript code is essentially an execution tree where functions are first class. A form of inheritance is implemented as prototypes. Prototypes allow the addition of members to existing classes. At a theoretical level, Javascript is more powerful that Java because of the prototype feature.

Javascript, or, really, ECMAScript, was never intended to be a full-featured programming language. The goal was simplicity. Perhaps the most useful thing that could be added to Javascript, while keeping to the KISS principle, is modules and namespaces. Namespaces provide reference integrity, while modules allow the bundling of various js files.

jMaki is a widget gallery. jMaki allows selective use of features across js libraries.

Dojo provides packaging: namespaces, packages, modules; OOP: constructors, inheritance.

So for a namespace,
var dojo = { }
dojo.gfx = { }
creates the dojo.gfx namespace. Syntactic sugar with
dojo.provide("dojo.gfx")

dojo.require(“dojo.gfx.path”);
Loads the path.js file from the gfx directory of the source tree. path.js is a module and gfx is a package.

Dojo provides internationalization and accessibility. Dojo provides infrastructure.

JavaOne source material URL

JavaOne source material can be found at
http://developers.sun.com/learning/javaoneonline/

TS-2294 Closures for the Java Programming Language

2007 May 8, 16:40
Tuesday

Neal Gafter, Google

http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-2294&yr=2007&track=5
http://www.javac.info/
http://gafter.blogspot.com/

A clousure is a "a function that refers to free variables in its lexical context." A free variable is a variable outside of the scope of the function that the function can reference by value (usually???). The variables are bound at the time the closure is made. Closures are for abstraction and program readability.

Gafter stresses that any implementation of closures must not interfere with the language as it stands and, less obviously, with the standard APIs as they are.

Gafter gives interesting looping examples. The loop is bound with a list and a function that is applied to each element of the list. This can be done currently with anonymous classes, but Gafter gives several instances where inner classes fail. Eg, "return" would mean a return from the closure, however, with the anonymous class approximation, "return" returns from the implemented or overriden method.

forEach(strings, new OneArg()
public void invoke(String s) {
if (…) return computeResult(s); // error!
}
});

Areas might serve programmers well:
  1. Fork-join concurrency
  2. Functional and higher-order utilities
  3. Aspect Oriented Programming
  4. Continuations
  5. Multiple dispatch

Tuesday, May 29, 2007

TS-2707 Java Puzzlers, Episode VI:

The Phantom-Reference Menace / Attack of the Clone / Revenge of the Shift
2007 May 8, 15:20
Tuesday

Joshua Bloch
William Pugh

http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-2707&yr=2007&track=5

FindBugs - Finds bugs in Java programs

Never miss the Java Puzzlers sessions when you have a chance to see it. Joshua Bloch and William Pugh are entertaining and informative.

My objection to last year's puzzlers is that most of the problems would be avoided by good programming practice. It seemed that many of the puzzlers were based on code that no programmer of any experience would write. If there's one lesson from Java Puzzlers, it's "always employ good programming practices." If you're not sure, consult "Effective Java", by Joshua Bloch. The concepts apply to any programming language.

I'm happy to say that 2007 was different. The puzzlers were similar to code you might write or find in the wild. Many of the problems were based around auto-boxing, so always keep your code simple and perhaps verbose when using auto-boxing.

I'm not going to recount the puzzlers here. I will, however, list the maxim associated with each puzzler.

  1. The joy of sets: don't mix types
  2. Don't use URL as a set element or May key - Use URI instead. Unfortunately, URL.equals() can behave differently if you have a network connection or not. URL is based on IP, so different URLs that resolve to the same IP are considered equal!! Other lesson, don't let environment influence equals() and hashcode().
  3. Special code must be written for JUnit to test threads. Because the exception is thrown on another thread, JUnit will report a pass. Need another strategy to report error.
  4. Watch initialization order. Wrapped primitives are not primitives. Never use Boolean in a ternary operator.
  5. BufferedInputStream.skip() is broken. Must wrap skip() and check the return.
  6. Be carefule where apply absolute value. % is remainder operator, not mod operator! So, negative numbers have different remainders from moduli.
  7. Avoid mixing types
  8. Silent widening is dangerous, Use double over float.

Tuesday Afternoon General Session

This session discussed the state of the internet, it's future, and how Sun and Java are/will support the web.

Application genres:

Terminal Apps
Client/Server Apps
Web Apps
Rich Net Apps
Integrated Rich Clients

The goal is to make it easier to assemble apps and content; increase "rich interactivity".

JavaFX makes building GUIs easier. JavaFX is a declarative language that wraps Swing and takes the tediousness out of building GUIs. This looks promising.

Java SE 6

Web Servicess Stack
Scripting Language support
Desktop API enhancements
Tools API
Custom annotations
Compiler access
Diagnostic tools attach on demand.
Co-bundled JDBC database
Improved swing fidelity

Open source JDK, openjdk.java.net

Java SE 7

Super packages
Super jars
First class support for other languages, scripting.dev.java.net
New byte code

A focus will be on the consumer experience: quick start, modular JRE, better install experience.

Nasa and Sun Collaborate on World Wind

World Wind is a geo spatial browser. Create your own mash up. Very cool. http://worldwind.arc.nasa.gov/

Tuesday, May 15, 2007

TS-1589 Language Oriented Programming and Language Workbenches

Building Domain Languages Atop Java Technology
Neal Ford, www.thoughtworks.com

2007 May 8, 10:50
Tuesday

Slides at http://developers.sun.com/learning/javaoneonline/2007/pdf/TS-1589.pdf

I had thought this session was about constructing domain specific programming languages and using supporting tools to generate Java code or even byte code (see bison).

Unfortunately, this is "Language Oriented Programming". All that is involved is building API so that programming reads like a sentence.

Ford's main point is that with traditional APIs, context is always provided, ie the client needs to know too much. With Domain Specific Language (DSL), context is implied. DSL allow higher abstraction and declarative programming. This is great. Declarative programming is the way to go, whenever possible.

Ford achieves language oriented programming by having all methods return this and allowing chaining, as in JQuery.

Eg,

Car API
Car car = new CarImpl();
MarketingDescription desc = new
MarketingDescriptionImpl();
desc.setType("Box");
desc.setSubType("Insulated");
desc.setAttribute("length", "50.5");
desc.setAttribute("ladder", "yes");
desc.setAttribute("lining type", "cork");
car.setDescription(desc);

Car Fluent Interface
Car car = new CarImpl().withMarketingDescriptionOf(
new MarketingDescriptionImpl("Box", "Insulated” ).
andAttributeOf("length", "50.5").
andIncludesA("ladder").
andAttributeOf("lining type", "cork"));

This is probably for small code, but one thing I've learned over the years, is don't try to code in a style that isn't explicitly supported by the language. I've seen C code that uses macros to simulate OO, and I've seen C++ code written in a Lisp style. In both of these instances, despite the coders being talented, the results were disastrous.

There is an example that using factories and immutable instances where this applies really well, but I can't see this style working for large programs.

Friday, May 4, 2007

Blogging for real

I've resisted blogging for the reason that it's the kind of activity where you start out with a lot of steam but quickly lose interest. Lacking relevant material is probably cause for lagging interest, both for authors and readers.

That said, JavaOne provides relevancy and perhaps a little interest. Hence, JavaNine. Don't read too much into the title. It's more than you want to know that JavaTwo was already taken.

In this blog, I summarize the sessions I attended. I do not provide detail because there are many resources that discuss the material much better than I ever could. If there are any outstanding ideas or quotes, I try to reference the source. I try to include URLs and projects for potential avenues of investigation.