Tag Archives: functional programming

Concision

Warning: This post contains rant and is short on actual reasoned arguments.

There are a number of things that are often considered bad practice in Java. These include static imports, star imports, shadowing, omitting braces, notUsingReallyLongVariableNames, etc. Also, many Java developers object to features like first class functions, operator overloading and type inference, because they might ‘overcomplicate’ the language and cause people to produce unreadable code.

Given that this is a post about concision, I will now shorten the above rules into a single rule:

It is bad practice to do anything which might cause you to write less code.

“Oh.” says the (hypothetical – I don’t think anyone actually reads this blog) reader, “Another whiner who doesn’t like typing. Just use an IDE!”

This is not about typing. I know perfectly well that the IDE can do ‘typing inference’ (so to speak). This is about reading. Making your code more verbose does not make it more readable. In many cases it makes it less readable because you’re hiding the actually important stuff inside layers of crap. Further, even when all of it is relevant, expressing it in an overly verbose way makes it much harder to take in.

Even ignoring the functional programming argument, I think the Java community and conventions would gain a lot by losing their fear of terse code.

This entry was posted in programming and tagged , , on by .

What’s in a syntax?

I was looking at JGA earlier. Basically yet another instance of the JGreenspun pattern. I have my own implementation of the same sort of thing – JGA looks significantly better than mine frankly.

But, even with a nice terse syntax, the kind of shenanigans one has to go through to make it work are pretty horrible. Take a look at some of my code snippets if you don’t believe me (granted the snippets I had are not very terse, but due to heavy use of anonymous inner classes one is pretty stuck with using constructors, which with abundant generics quickly leads to some really horrible lines). Although you can get most (well, about 75%) of the functionality of a functional language like ML or Haskell into Java if you hammer enough, the result is fairly mindly blastingly horrible.

Shorter syntax for declaration of anonymous inner classes would certainly help a bit, but I don’t think it’s really going to be enough. I think that until closures come along to Java (and I mean proper BGGA style closures. Anonymous inner classes just aren’t going to cut it) I’m going to have to revert to the way of doing things that doesn’t involve too much greenspun. And/or defect to Scala completely.

This entry was posted in programming and tagged , on by .