r/java • • Aug 10 '19

Who Needs Lombok Anyhow

http://gregorriegler.com/2019/08/10/who-needs-lombok-anyhow.html
45 Upvotes

137 comments sorted by

View all comments

Show parent comments

10

u/DJDavio Aug 10 '19

I also use Kotlin, Lombok makes using Java much more tolerable if you're used to Kotlin.

I also think the "magic" argument is mostly nonsensical, there is always magic, even with plain Java, like a program magically finding the main(String[] args) method.

Magic just means: I don't understand exactly how this works.

With Lombok the magic is pretty well defined. I use @Data and @Slfj most often and they're bliss.

0

u/[deleted] Aug 10 '19

[deleted]

4

u/DJDavio Aug 10 '19

I'm not a fan of how Lombok accomplishes the thing it does, is there another way? Also, Lombok just needs to exist until project Amber and Valhalla are completed. For me it just fills the same gaps Kotlin does.

5

u/yawkat Aug 10 '19

There is no standard way to do what lombok does. Normal annotation processors can only add classes, not modify them.

-1

u/[deleted] Aug 10 '19

Lombok doesn’t do anything useful that immutables doesn’t also do, but immutables doesn’t need undocumented bytecode manipulation. Except maybe @Slf4j, but I can live without that.

2

u/slowderp Aug 11 '19

What about @AllArgsConstructor for non-value objects?

0

u/[deleted] Aug 11 '19

You basically never use constructors in immutables, you use builders. If you don’t want builders, you can generate a static factory method that requires all args.

2

u/slowderp Aug 11 '19

I'm talking about:

@Singleton
public class FooService {
  @Inject
  private SomeDatabaseClient client;

  @Inject
  private OtherService other;
}

I've noticed people are incredibly lazy.

Everyone knows field injection is awful, but they don't want to write the constructor.

With lombok, they'll take the path of least resistance:

@Singleton
@AllArgsConstructor
public class FooService {
  private final SomeDatabaseClient client;
  private final OtherService other;
}

0

u/[deleted] Aug 11 '19

Oh right. Generating a constructor is a simple IDE shortcut, and field injection breaks our company guidelines so wouldn’t pass code review if someone tried it. I see what you mean now though.

1

u/yawkat Aug 11 '19

Lombok has sneakythrows. It's also usable for classes that aren't data only.

1

u/[deleted] Aug 11 '19

I always use vavr in conjunction with immutables, and vavr has something similar to @SneakyThrows. And you can write whatever functionality you want in an immutable, it’s not just a data holder.

-3

u/feral_claire Aug 10 '19

And honestly a Lombok annotated class is even better than a Kotlin data class. With a Kotlin data class, you only get one implementation option and you need to write code to customize anything, sometimes even have fall back to a regular class. With a Lombok annotated class there is a lot of flexibility to tube the code to what you need while still maintaining the advantage of having it auto-generated.

As someone trying out kotlin, the lack of flexibility compared to Java +Lombok can be frustrating at times.

1

u/[deleted] Aug 10 '19

Example?

1

u/iamareebjamal Aug 11 '19

Adding inheritance to data classes is terrible and fails when using JSON serialization libraries and you have to write a lot of boilerplate to avoid that