Result of thinking in Java

I was recently involved in some discussion about Java and DSL and had an interesting observation how the language can impact the thinking. It was so explicit that I decided to discuss it in more details.

Please take a look at the code:

int labelsWidth=150;
  layoutless
    .item(new ComponentBox()
      .component(jLabel1)
      .width(labelsWidth)
      .height(22)
      .x(0)
      .y(8+25*0)
      )
    .item(new ComponentBox()
      .component(jTextField1)
      .width(layoutless.width().minus(labelsWidth).minus(16).minus(50))
      .height(22)
      .x(labelsWidth+8)
      .y(8+25*0)
      )
    .item(new ComponentBox()
      .component(jButton2)
      .width(49)
      .height(21)
      .x(layoutless.width().minus(58))
      .y(8+25*0)
      )
    ...
    ;
  this.add(layoutless, BorderLayout.CENTER);

This code builds simple dialog showed on the picture:

Participants of those thread insisted that this is a good sample of Java DSL and proposed to rewrite it in Ruby and thus prove that it is better for building DSL.

Can you rewrite this DSL in Ruby and make it better? The answer is NO. Why? Because good DSL made from 2 ingredients:

  1. Good design (ideally it should be language agnostic).
  2. Good implementation in the target language.

The problem with this DSL is that its design is bad and no matter what implementation do you choose the result will be bad also.

So, how the language impacts the thinking? The impact is:

  • After a while you starting to believe that this nonsense is actually a DSL and you became used to it and satisfied with it and believing that this is the right way to go.
  • The limitations of language at some point places limitations to your imagination. And you thinking about the design staying within limitations of language and became blind to possibilities lying outside of it.

For example - with such limitations you can be blind to alternative designs, like this one:

dialog
  row 30%, 70%
    image '/image-with-keys.jpg'
    form
      row
        text 'Label1'
        button '...'
      text 'Label2'
      password
  button 'Ok'

It's better to get used to many languages. And even if you works with Java only - it will free your imagination.

So, don't think only in Java.