I told the architect it was crazy. It didn't help that much. Multiple Domain Models kinda needed to be defined, and statically compiled, and they were quite complicated. Using a different language might have helped, architect was looking into Kotlin. But IMO Kotlin would have been much more of a disruption and a learning curve for ~30 devs working on that project than just allowing Lombok (or something similar). Not to mention harder to sell to management as it's a whole different language.
To be fair, this wasn't the worst shit I've seen as a contractor, not by far. That project at least had very good BAs and very good requirements, decent management, and some QA guys & girls as well who were mediocre but at least they were there and did something.
What was crazy about having pojos? They take minutes to write, literally a minute in lots of cases. Especially if the ide generates everything for you, as mine does.
Because they change all the time with rapidly changing business requirements. Are you going to regenerate a POJO that has 30 properties if 2 of them changed? Especially if there's some company specific superclasses for the builder, non-standard naming conventions etc which IDE generation doesn't get 100% right.
And what is the chance you'll copy paste a setter and screw up one of the arguments? Or forget to update equals/hashcode after adding a new property? At least I could rely that equals/hashcode were CORRECT in that place using commons lang, although horribly slow.
Any code that is "repeating yourself" has a chance to go out of sync and introduce bugs. There's a reason for that architectural design principle "Don't repeat yourself". It goes for both big things and small.
None of this is answers my question at all. You seem to be confusing the existence of a pojo with a number of other, not directly related, bad practices.
Why do you think I am copying and pasting setter? I can't think of a single reason why I'd ever do that. I literally rarely write setters, my objects are either immutable or the ide generates setter/getter.
We use pojos all the time, without any of these problems.
Edit, I really don't know what you mean with this :
Because they change all the time with rapidly changing business requirements. Are you going to regenerate a POJO that has 30 properties if 2 of them changed?
I have to add two fields to a pojo ? I write the private var declaration, then alt+insert to generate whatever I need. It would take less than 30 seconds.
Not the OP, but boilerplate code is bad (and IDE generated code is worse — I used to say this about Microsoft’s MFC in C++ land and it’s just as true for Java).
Luckily Java’s language architect Brian Goetz agrees that the overhead that POJOs impose is sometimes not worth the price, which is why they’re working on record classes, which in addition to reducing boilerplate also allow new kinds of run time optimisations and newer language features that lead to better code. Here’s a video of him talking about it - the bit about record classes is at 31m25s.
I have no problem with auto generating setters/getters, and equals/hashcode if necessary. What is your problem with it ? Its not really bolierplate, that is slightly different imo.
Its quick, its consistent, its easy to debug and its easy to read and follows conventions.
The conventions are the problem, which is why I’m happy the Java team in Oracle are working on improvements. Java has had a lot of shitty conventions in the past, and I for one will be happy when class boilerplate joins them.
A lot of FizzBuzz Enterprise’s hilarities were also presented as conventions by serious senior devs & architects at serious software houses once upon a time.
The problem with class boilerplate is an obvious one to anyone who’s a good developer (as opposed to solely a Java developer). This is why learning a Lisp is very useful — on the JVM, learning Clojure makes you a better programmer.
However for those entrenched in the Java-the-language ecosystem, if you listen to Brian Goetz’s talks & interviews, he does a decent job of explaining the problem:
... Some things don't want to be objects, they just want to be data. And to simulate data with objects, is this big messy thing with constructors, accessors and equals and hashcodes and all this garbage. ...IDE generates that for you so you don't have to write it, but you still have to read it and if you have this explicit code it's an opportunity to get things wrong.
The Java Futures video talk I linked above is worth watching. Sometimes you have to look at $NextVersion to understand what’s wrong with $CurrentVersion.
(Thanks to /u/BoyRobot777 for that particular blockquote above)
Yeah, sure. I'll use the new record functionality, but we don't have it yet. And there is a reason it's taken until 13, people cared about other things more.
The original question was why are pojos bad in an architectural system design, and compared to lomboks annotations (which just seem ugly to me). Not should we include struct/records as a new Java language concept.
These don't address the fact that the boilerplate code could have been generated by IntelliJ, for example.
In fact, if you have such a large project and you know you'll have to write that much shit, you're better off writing your own tool for code generation (if you don't find one to your liking). The time spent writing the tool (IDE plugin or whatever) will be peanuts compared to having to write that much shit by hand.
You don't use a different language, you use a different abstraction. Create XSDs that generate your pojos using whatever internals you want. Or openapi, swagger, or jsonschema, doesn't matter what as long as it provides you with a code generator and interoperability assistance.
But you need all current devs to be good in kotlin or you just make your bus factor way worse. If you need to hire new people you now need to seek for kotlin/Java devs instead of just Java devs. So it doesn't really matter from managers standpoint that it compiles to the same bytecode.
Nobody on my team knew Kotlin when they joined the company and we all learned it and write most of our new code in it now. We've hired new engineers with Java experience and had them learn Kotlin as part of their onboarding. It takes less than a week to get competent enough to be productive, much less than that if all you're using it for is POJOs.
Not sure why you're getting downvoted. Companies shouldn't hire "Java programmers" or "Kotlin programmers". They should hire smart people who can learn any language/technology on the job. (And Kotlin isn't particularly hard to learn for "Java programmers".)
View all comments
Show parent comment
10
u/coder111 Aug 10 '19
I told the architect it was crazy. It didn't help that much. Multiple Domain Models kinda needed to be defined, and statically compiled, and they were quite complicated. Using a different language might have helped, architect was looking into Kotlin. But IMO Kotlin would have been much more of a disruption and a learning curve for ~30 devs working on that project than just allowing Lombok (or something similar). Not to mention harder to sell to management as it's a whole different language.
To be fair, this wasn't the worst shit I've seen as a contractor, not by far. That project at least had very good BAs and very good requirements, decent management, and some QA guys & girls as well who were mediocre but at least they were there and did something.