More PygeonJava
February 28, 2007 – 9:35 pmContinuation of previous post…
1) No inner classes: no classes as static members, no classes as instance members, no local classes, no anonymous classes. The advantages of these constructs are:
- Documents that the class is used only by its enclosing class.
- Allows access to enclosing members in certain cases.
- More convenient than writing the class elsewhere.
My reasons for omitting inner classes anyway:
- The concept of a class as an instance member of another class is tricky to explain.
- The rules about outer member access are strange because of the peculiar way in which inner classes were added to the language.
- Anonymous inner classes are particularly useful, but fitting a whitespace-sensitive construct within expressions requires strange special allowances.
- Most importantly, inner classes are for the most part syntactical conveniences.
2) ‘break’ and ‘continue’ labels are in. The labels are declared with ‘label’ on the line preceding the ‘while’ or ‘if’ to which they apply (heh, a bit of experimenting just now told me labels can actually be used not just with loops but with ’switch’es and ‘if’s; seems labels can’t precede an ‘else’, but they can precede an ‘if’ immediately after an ‘else’).
3) Explicit casting everywhere: no automatic widening casts, no autoboxing, no nothin’. Enforcing this will require inspection of the imported types, for otherwise, automatic casts would be accepted by the compiler. (With all this casting going on, I’m considering abbreviating the casting operator from ‘cast’ to just ‘c’).
4) No Java 5.0 features: no autoboxing, no enums, no generics, no annotations, no covariant returns, no varargs methods. Aside from autoboxing, I find the syntax and subtleties of these features strange enough myself that I can’t see learners faring well with them. Besides, they are for the most part just conveniences. Covariant returns are not allowed because this would break the explicit casting requirement. (On the other hand, learners will shortly encounter some 5.0 features in the library if they look around the docs; of course, PygeonJava has always been designed to allow learners to pick it up ASAP and then drop it ASAP, so learners should be on to real Java before they give the docs a serious look.)
5) Abstract classes are in. Even though an interface is arguably just a limited kind of abstract class, interfaces are in too because of their important role as a kind of pseudo multiple-inheritance. In interfaces, the public and static modifiers on each method must be present as a reminder to learners.
6) No assertions. On one hand, assertions are really useful because they can be toggled on and off by a runtime option, which is very useful, but on the other hand, assertions are essentially just a shortcut for if (!bla) {throw exception;}.
7) As with PygeonC, no for, enhanced for, do-while, switch.