The programmer … has to be able to think in terms of conceptual hierarchies that are much deeper than a single mind ever needed to face before.
Quote: On the cruelty of really teaching computing science
Java syntax sugar with Project Lombok
In one of my last projects I used Project Lombok to reduce boilerplate code. Lombok provides some annotations to remove the noise from the java language.
How does it work
Lombok runs as as an annotation processor which handler modifies the AST (Abstract Syntax Tree) by injecting new nodes such as methods and fields. After the annotation processing stage, the compiler will generate byte code from the modified AST.
How do I use it
Getters and setters like:
1 2 3 4 5 6 7 8 9 |
private String name = "Jens"; public String getName(){ return name; } public String setName(String name){ this.name = name; } |
Can be replaced by the Lombok annotations:
1 |
@Getter @Setter private String name = "Jens"; |
Or replace the noisy initialization of a logger:
1 2 3 4 5 6 7 |
public class MyClass { private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MyClass.class); public static void main(String... args) { log.error("Log me tender, log me sweet, ..."); } } |
With a fancy annotation:
1 2 3 4 5 6 |
@Log public class LogExample { public static void main(String... args) { log.error("Log me tender, log me sweet, ..."); } } |
There are a lot more lombok features. There is also a great tutorial. What lombok does is not very impressive when you look at just a single example. But it helps a lot to remove java syntax noise from your classes and focus on the important parts of your business logic. When you look at the @data example, you can imagine how much code you don’t have to write(generate), read and maintain with Lombok.
Installation
Lombok can be installed with maven or ivy or include the lombok.jar in you build path. You have to teach your IDE about Lombok. Double click on the lombok.jar to install it into eclipse. For IntelliJ there is plugin available. It can also be installed from the IntelliJ plugin repository.
Summary
No more java projekts without Lombok.
Heating monitoring with twine
Finally I found time to configure my twine. I use it to monitor the heating of a vacation home when nobody is there. The heating there is really old, and the chance of an failure is really high.
With the twine software it’s a no brainer to configure a setup like send an email when the temperature is less then 9°C. A great way to connect things to the internet!
GoEuro is public beta
Patrick my partner at our software engineering company recently got involved in GoEuro.
GoEurois a startup which aims to become the best travel search engine for Europe comparing (and combining) air, train and bus options.
The goeuro team did a great work on building their software in the last months. Now the site is open for public. Happy traveling!
New syntax highlighter for jensjaeger.com
I just replaced the relative simple Highlight Source Pro with the much more advanced Crayon Syntax Highlighter.
Crayon has an awesome theme editor with a lot of predefined code styles:
And helper for the editor to insert code snippets:
And some fancy ui controls in the code block:
1 2 |
#!/usr/bin/ruby puts "Hello World!" |
Happy coding!