Books, General, Programming, Refactoring

Code Simplicity

Code Simplicity by Max Kanat-Alexander is a thought provoking book on improving software code quality. As with many “philosophical” books (i.e. books not aimed at a specific technology) on software development the advice given here is not “hard and fast” and should not be considered as “rules” but rather as “guidelines” that developers should think about when writing code within their own context.

The book’s main theme is on the three flaws of software design.

  1. Writing code that isn’t needed (YAGNI)
  2. Not making the code easy to change
  3. Being too generic

These three flaws have some conflicting aspects and I think the developer needs to find the right balance. The author himself talks about these flaws in this great 4 part series on YouTube.  I suggest watching these short videos if you don’t want to buy the book (or perhaps buy the book after watching them :))

There are many other useful advice in the book such as;


It is more important to reduce the effort of maintenance than it is to reduce the effort of implementation


Never “fix” anything unless it’s a problem, and you have evidence showing that the problem exists


The ease of maintenance of any piece of software is proportional to the simplicity of it’s individual pieces


Strangely to me (call me nuts ;)) the most simple but most important line in the book was not about code quality itself, but rather the author’s answer to the question “What is the purpose of Software?”


The purpose of software is to help people….”not to make money” or “show people how intelligent I am”


Software developers (including yours truly) often ignore or forget this basic fact when designing and implementing software products. This most often results in a complex, over-engineered product that makes simple things hard for the end-user.

Java, Programming

Groovy Console: Python like REPL for Java

UPDATE2: JShell to be introduced in Java9, so hopefully we will have a “native” Java REPL!

UPDATE1: Checkout a discussion about this post on Reddit!

One of the strong features of Python (and many other interpreted languages) is the availability of a REPL(Read, Evaluate, Print & Loop) interactive shell to execute code without having write a complete program and compile it to see the result. This substantially increases developer productivity especially when working with a large code base. Using a REPL shell (a.k.a. console) you can easily run and test small code snippets in isolation from your main program.

Now if Python can have a REPL why can’t Java? Well the answer is simple, Java is a “compiled” language. Undeterred, I still Googled for a “Java REPL”. Stackoverflow pointed me to Groovy Console. But before going onto Groovy Console, What is Groovy?

From Wikipedia:

Groovy is an object-oriented programming language for the Java platform. It is a dynamic language with features similar to those of Python, Ruby, Perl, and Smalltalk. It can be used as a scripting language for the Java Platform, is dynamically compiled to Java Virtual Machine (JVM) bytecode, and interoperates with other Java code and libraries. Groovy uses a Java-like curly-bracket syntax. Most Java code is also syntactically valid Groovy.

The Groovy installation includes a REPL which is (obviously :)) called “Groovy Console”. Since “Most Java code is also syntactically valid Groovy” I can now use the Groovy Console to execute Java code snippets (see screenshot below).


This is great because now I don’t have to write a complete class and the dreaded “public static void main()” to test a small snippet of code before I merge it into my “big” program.

So there you go…if you want a “Java REPL” install Groovy!