Thought on Lombok

I really like to use Lombok. It really shortens Java codes. I prefer simple codes. Lombok’s @Getter and @Setter feel like C#’s Automatic properties.

Java + Lombok:
@Getter
@Setter
private int id;

C#
public int Id {get; set;}

But there are some concerns that Lombok may degrade code quality. There are many useful features but there are also many constraints you shoud care about. For example, @EqualsAndHashCode provides equals() method but it is only for immutable objects. @Builder is also useful when you build an object but it internally contains @AllArgsConstructor. This constructor is default (package private) so it might be called in the same package. When you change members of the class, that code calling the contructor will be affected.

Like these, there are many leaky points when you use Lombok. This is why some people think Lombok is bad or not good for their project at least. However, I don’t agree. Lombok is for most cases, so it is okay to use. So what about these edge cases?

My answer is simple. Embrace it. Tolerate it. Someone might use badly. Blame them, educate them, but keep using Lombok. I believe that they will use it well soon. This is just a tool. It depends how to use.

I also think Lombok may have some bugs or vulnerabilities. Then I also hope Lombok is updated quickly and regularly to fix or mitigate them. Or I may contribute to it.

I like simple codes and Lombok helps doing it. I know Lombok is not perfect so we should be careful when we use it. But this danger cannot be the reason to avoid Lombok. Using it well is difficult but worthy to try.

Loading

Published
Categorized as xacdo

By xacdo

Kyungwoo Hyun

Leave a comment

Your email address will not be published. Required fields are marked *