Channels ▼

Jocelyn Paine

Dr. Dobb's Bloggers

Plain Language

December 13, 2010

This morning, I was berating my brain. If I were supple enough, I'd have given it a good kick. Because it couldn't remember how to open and print to a Unicode file in Java. (You create a new FileOutputStream pointing at the file, then create an OutputStreamWriter from the FileOutputStream and the name of your encoding, and then create a PrintWriter from the OutputStreamWriter. While doing this, you have to keep in mind the difference between the "write" methods, which most output streams can execute, and the "print" methods, which fewer can. I don't know why.)

But then I decided that it isn't my brain that's at fault; it's Java. Because look how Java makes you define an associative table:

static {
  defaultPorts.put( "http" , new Integer(80) );
  defaultPorts.put( "shttp", new Integer(80) );
  defaultPorts.put( "https", new Integer(443) );   // ...
  UsesGenericSyntax.put( "http" , Boolean.TRUE );
  UsesGenericSyntax.put( "shttp" , Boolean.TRUE );
  UsesGenericSyntax.put( "https" , Boolean.TRUE ); // ...

Which is ludicrous, insane, crazy, preposterous, risible, ridiculous, farcical and absurd, as well as every other synonym you can think of. An associative table is a mapping, and a mapping is a function, and function is the most fundamental notion in mathematics. Also the simplest. Functions are sets of ordered pairs, so any decent language would let you write them using a notation whose primitives represent the primitive parts of a set of ordered pairs, clearly arrangeable to describe the whole.

It's analogous, or should be, to the control knobs on my cooker. The layout of the knobs is a scaled-down picture of the layout of the hotplates, and the set of possible rotations of each knob is a curved picture of the set of its hotplate's possible temperatures. The parts of the controls match the parts of what they control, and the arrangement of these controls matches the arrangement of the things they control. Except if I program in Java, when my cooker controls would look like this:

static {
  CookerControlPanel cp = 
    my_cooker.addCookerControlPanel( new CookerControlPanel("CookMaster CP141","UK version") );
  cp.setLanguage( "English" );
  cp.getLabelTextGenerator().setTextReadingDirection( TextReadingDirections.LEFT_TO_RIGHT );
  CookerHotplateControlKnobPosition front_left_pos, front_right_pos, back_left_pos, back_right_pos;
  front_left_pos = new CookerHotplateControlKnobPosition( new Integer(0), new Integer(0) );
  front_right_pos = new CookerHotplateControlKnobPosition( new Integer(6), new Integer(0) );
  back_left_pos = new CookerHotplateControlKnobPosition( new Integer(0), new Integer(6) );
  back_right_pos = new CookerHotplateControlKnobPosition( new Integer(6), new Integer(6) );
  CookerHotplateControlKnob front_left_knob = new CookerHotplateControlKnob( front_left_pos );
  front_left_knob.addLabel( "Front left" );
  CookerHotplateControlKnobTemperatureScale front_left_knob_temperature_scale = 
    new CookerHotplateControlKnobTemperatureScale( CookerHotplateControlKnobTemperatureScaleBaseScales.FAHRENHEIT, new Integer(50), new Integer(350) );
  front_left_knob.addTemperatureScale( front_left_knob_temperature_scale );
And on and on and on, until your brain turns to toast.

Moreover — returning to the associative table — why must I tell Java that 80 is an integer? Does it know an 80 that isn't? Why must I tell it that TRUE is a Boolean? Does it know TRUEs that aren't? Perhaps they're TRUES used by visitors from another universe whose logic is different from ours, so that when they come here, they have to switch. Like an internationalisation-resource-bundle, except that you carry with you not your time-zone and alphabet, but your universe's truth values.

I copied the associative-table code from a video called "Public Static Void". This was one of the keynote speeches at OSCON 2010, the O'Reilly Open Source Convention, and is by Rob Pike, co-designer of Google's Go programming language. Pike doesn't like the verbosity of Java and C++, and gives examples that demonstrate it, as well as ridiculing the spurious packaging around 80 and TRUE. At the beginning of the video, he quotes Lisp expert Dick Gabriel:

I'm always delighted by the light touch and stillness of early programming languages. Not much text; a lot gets done. Old programs read like quiet conversations between a well-spoken research worker and a well-studied mechanical colleague, not as a debate with a compiler. Who'd have guessed sophistication bought such noise?

I'm sure Gabriel was thinking of Lisp. And maybe also of APL, Algol 60, BCPL, Comit, Simula 67, Snobol, and even Fortran. But then, perhaps somewhere in the years that began with Pascal and Modula and Clu, and ended with C++ and Java, something went awry. What? And why?

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags


<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags


<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

