Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Java the language is fine, but Java has - or used to have? - so much idiomatic boilerplate - worst of all IMO was the ridiculous imperative to write getters and setters for every field, but there was also a plethora of very broad interfaces - all of which required all kinds of boilerplate and/or delegation to be able to use. Don’t even get me started on the frameworks.

Maybe Java has changed in the last 5 years, but idiomatic Go has much, much, much less boilerplate than the idiomatic Java I used to know.



To your point, I started writing my POJOs without getters/setters. It felt like I was doing something wrong and the ghosts of senior devs I have worked with were looking down at me with shame.... "how could you".

The worst part is that some libraries use getters as convention. e.g. Jackson (by default) uses getter methods to decide what to serialize.


I used to do the same thing, giving total visibility and access inside a package. I do this in my old “Java AI” book (you can get a free copy at https://leanpub.com/javaai by setting the price to free).

I had not touched Java in a long while until yesterday when I wanted to do a quick benchmark of Lucerne to compare it to a search library in another language. I was surprised how easy and quick it was to do this.

I have considered updating my old book for modern Java. It would probably only take a few days to update the examples, but updating the book text would take longer.


Me too - I absolutely recommend using public member fields and not setters/getters! In 20 years of Java development I did not once benefit from all the extra fluff. Classic YAGNI.

I don’t recall having a problem with Jackson, maybe there is an option you can use? But it’s 5 years now since I used Java.

But my point of course was that this is idiomatic boilerplate you don’t find in other languages. Along with a bunch of other ceremony and nonsense like automatic dependency injection and reflection heavy frameworks that reduce mechanical effort by creating complex, invisible and abstract conceptual systems that require far more mental gymnastics than they save on typing. (I’m looking at you, JPA)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: