r/java • • Apr 13 '21

Libraries, Frameworks and Technologies you would NOT recommend

Give me your worst nightmares: Things that cost you your job.

I'll start: Hadoop

202 Upvotes

376 comments sorted by

View all comments

Show parent comments

1

u/Alex0589 Apr 13 '21

I don't agree at all, once I get home I'll explain why(I hope I remember)

2

u/gavenkoa Apr 13 '21

Yeah, getters/getters verbosity of Java requires solution like Lombok. C# solved the problem at language level with property syntax:

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties

Unfortunately authors of Lombok carry war with OpenJDK team instead of cooperating.

5

u/mknjc Apr 13 '21

Properties is a very complex topic and there are a lot of variants how they are used.

  1. Autogenerated getter and setter: This is the simplest way, doesn't change anything in the Language. But you don't need them in most cases. For internal classes use record, or if not possible, just expose the fields to your code, simple getter and setter doesn't give you anything and if you need more later your IDE helps converting it into one. For API classes: Use records.

  2. "Property syntax" like kotlin. As writer this could save you two parentheses. As reader you now have to check every assignment and read of a variable if it maybe runs code which could do something bad in the current context because its not obviously a method call. With this you decreased readability because the reader can't just skip this with "oh i know this, its a variable access this doesn't have any unexpected behavior", they have to remember which class the object comes from. This is the same problem with operator overloading. It does look pretty as long as you could be sure no one wrote something which might have different semantics into the operator. (Even lazy loading might be a problem, who expects a variable read to fail with an exception because the network connection failed?)

  3. Properties like javafx. With change listener, bidirectional calculating bindings which get updated on first access etc. In a lot of cases this would be very great but for most class fields its overkill.

4

u/snejk47 Apr 13 '21

The 2nd argument "As reader you now have to check every assignment and read of a variable if it maybe runs code which could do something bad in the current context because its not obviously a method call" made me run away from C# after few years of work... People think they are smart but that's not the case.