News for hackers. Stuff that matters.
Re:Java 1.0 Turns 25 by imtringued on Saturday January 23, 2021 @10:24AM (#25882843)
In principle I like Java but there are a few minor details that just make it not worth dealing with it. Getters and setters are incredibly annoying. There are lots of crazy things going on in the JEE ecosystem. The latter is a big deal when you accept an average "Java job".

If you were to give it a small facelift I wouldn't have to worry about all the tiny flaws that add up. I don't really need Kotlin, Scala or dead JVM language x. Just a slightly better Java.

Re:Java 1.0 Turns 25 by freedomben on Saturday January 23, 2021 @11:09AM (#25883261)
Java was (and still is) IMHO a great language, but the culture around it is why I refuse to do it professionally. Things I can't stand:

1. Multiple (often unnecessary) layers of abstraction that end up being much more complicated than the thing they were intended to simplify through abstraction. There is no concept too simple to abstract it seems

2. Verbose and hard to follow "builder" patterns

3. The extreme proliferation of design patterns. I have literally seen hundreds in various Java codebases.

4. Gradle is great but requires memorizing a non-trivial API and learning a whole new (awesome, but still) language (Groovy).

5. There's always a "Java" way of doing stuff that is different (often because of abstractions, see #1) so you have to re-learn everything that way. Example: Managing TLS certificates

5. Legacy code is everywhere, and can be really painful.

So much of it was hacked together and became critical and can never be re-written and never retired

There are more, but I weary of this discussion :-)

Re:Java 1.0 Turns 25 by happyweasel on Saturday January 23, 2021 @01:27PM (#25884814)
6. excessive configurabilty leads to fragility at runtime - the overuse of annotations, xml/yaml/whatever configurations and late-binding (effectively assembling the app at runtime) eliminates quite a lot of advantages of a statically typed language and brings us back to string coding: runtime-errors due to typos, jpa strings in annotations, typo in an xml file leads to non-functioning software at runtime. Classloader horrors due to deeply nested library dependencies that use different versions of libraries, fueled by the insanity called maven.
Re:Java 1.0 Turns 25 by twistedpair on Saturday January 23, 2021 @01:48PM (#25884999)
> overuse of annotations, xml/yaml/whatever configurations and late-binding (effectively assembling the app at runtime) eliminates quite a lot of advantages of a statically typed language

Just avoid Spring. That's been my motto and I've been Spring free for 7 years now. Doctors say I should live out a happy life.

Re:Java 1.0 Turns 25 by kharak on Sunday January 24, 2021 @05:12AM (#25890818)
I work mostly with Java and am a bit blind to other languages, at least in a professional setting. Which languages / ecosystems do it differently? I'm looking for something new.
Re:Java 1.0 Turns 25 by bostonvaulter2 on Sunday January 24, 2021 @06:16AM (#25891113)
I'd recommend Elixir as a nice introduction to functional programming while not being too arcane.
Re:Java 1.0 Turns 25 by dkarl on Saturday January 23, 2021 @11:58AM (#25883867)
Somehow Java attracted more than its fair share -- way more -- of programmers who wanted to believe that software development had all been figured out, the right answers were known, and the only thing that remained for the profession was to be faithful to the true answers and priggish towards anyone who had doubts. That was a really weird time, especially in retrospect when we think about what the "right" answers were back then.
Re:Java 1.0 Turns 25 by parasubvert on Saturday January 23, 2021 @12:02PM (#25883925)
That’s a side effect of enterprise software development, because politically it’s all about posturing to make non-technical management more comfortable. “Wow they’re really confident they must know what they’re doing”

The same attitude existed in C++ programmers in that space that sneered at Java’s intrusion.

I see the same attitude in new teams using Golang in the enterprise.

Re:Java 1.0 Turns 25 by freedomben on Saturday January 23, 2021 @12:29PM (#25884241)
Yes, excellent observation. I've seen that attitude a ton in the "design patterns" discussion. e.g.:

"Why are we doing a Factory for Singleton Factory design pattern here?"

"Because this design pattern is made for this scenario"

Re:Java 1.0 Turns 25 by lr4444lr on Saturday January 23, 2021 @12:59PM (#25884558)
This. Exactly this. It wasn't that Java was a "different" way of doing things in business software that had pros and cons, it was that its adherents thought it was THE way of doing things in business software.
Re:Java 1.0 Turns 25 by saiya-jin on Saturday January 23, 2021 @12:46PM (#25884431)
1) those layers of abstractions are often the result of some smart guy in the team, reading some design patterns book and then desperately applying them whenever feeling the chance. Typical building his little cathedral story.

Its pretty horrible, but by no mean java-specific. It can be achieved in any object-oriented language, and to some extent also in others.

Re:Java 1.0 Turns 25 by vips7L on Saturday January 23, 2021 @06:18PM (#25887040)
Patterns aren't always bad When used correctly they can greatly simplify code.
Re:Java 1.0 Turns 25 by Corrado on Saturday January 23, 2021 @12:44PM (#25884413)
OMG! Thank you for this. I've disliked Java for years but really couldn't put into words exactly why. Reading you comment I started thinking about all the time I wasted chasing down error messages that were spread across 7 different classes. And working with TLS in Java? Nightmares abound!
Re:Java 1.0 Turns 25 by pjmlp on Saturday January 23, 2021 @11:52AM (#25883795)
Gradle is only a thing in Android circles, thankfully.

Legacy code is everywhere on the world, only a selected few get to work on shiny things from scratch. Even cool startups eventually turn into legacy.

I wonder what technology used at enterprise level, doesn't suffer from those bullet points.

Re:Java 1.0 Turns 25 by augustk on Saturday January 23, 2021 @03:39PM (#25885841)
If I have to work with legacy code I actually prefer code written in a non-object oriented language. Badly written OOP code is often worse.
Re:Java 1.0 Turns 25 by bcrosby95 on Saturday January 23, 2021 @07:27PM (#25887527)
Yeah, navigating overly-architected OOP is like playing super mario brothers. The princess is always in another castle.
Re:Java 1.0 Turns 25 by rafram on Saturday January 23, 2021 @03:53PM (#25885951)
> Gradle is only a thing in Android circles, thankfully.

It's the standard Java build tool at this point. I don't know of anything better.

Re:Java 1.0 Turns 25 by BossingAround on Saturday January 23, 2021 @04:05PM (#25886082)
I don't know about "better" but Maven has been the standard in my company. Personally, I like it better, call me crazy.
Re:Java 1.0 Turns 25 by pjmlp on Saturday January 23, 2021 @04:35PM (#25886346)
For Android developers and ex-Ant users only.

I really don't see it anywhere else to make it standard, besides it depends on Maven Central.

Re:Java 1.0 Turns 25 by vips7L on Saturday January 23, 2021 @06:14PM (#25887016)
Maven is the standard build tool and has been on every project I've worked on outside of play/sbt hell.
Re:Java 1.0 Turns 25 by tannhaeuser on Saturday January 23, 2021 @12:49PM (#25884470)
> Gradle is only a thing in Android circles, thankfully.

Wish that were the case, but unfortunately Gradle builds showed up in server-side, SpringBoot-heavy FinTech startup code I worked with not too recently. I guess it's due to the copy/paste nature of Spring development, like other choices in those code bases.

Re:Java 1.0 Turns 25 by pjmlp on Saturday January 23, 2021 @01:14PM (#25884688)
I don't do Spring, so I am spared from that.

That is to be expected, given how Spring is now hyping Kotlin as they did previously with Groovy, Scala and Clojure support, and Kotlin folks tend to push for Gradle due to its use on Android.

Re:Java 1.0 Turns 25 by fulafel on Monday January 25, 2021 @11:32PM (#25912565)
"Enterprise" is a hard term for me to use productively in software context, because it feels so synonymous with bad software.

Lots of fine pieces of software are used in small and big companies that do only one thing and do it well.

As for in house line-of-business apps, it's an elusive species because if it does what it needs to cost effectively and is not a marketing case for a fat software company like Oracle nobody often gets told about it. But I've seen and heard of LOB apps built thereupon that don't suffer from those bullet points, except for 5.

Re:Java 1.0 Turns 25 by happyweasel on Saturday January 23, 2021 @01:28PM (#25884829)
Gradle at least gave incremental builds... Even though javac is fast, practical java builds are sloooooww (maven)..
Re:Java 1.0 Turns 25 by pjmlp on Saturday January 23, 2021 @01:31PM (#25884861)
Indeed, thanks to a background daemon that needs at least 2 GB ram and an SSD to be competitive with Maven.
Re:Java 1.0 Turns 25 by projectileboy on Saturday January 23, 2021 @04:22PM (#25886219)
Agree, strongly. I always think it’s funny when people complain about the verbosity of Java, because most of it is self-imposed. Even more funny is that the same Java programmers will migrate to something like Groovy and then reproduce all of the same verbosity there (e.g., “Don’t use implicit ‘it’ variables! Name it theImportantThingFromTheImportantThingArray!”)
Re:Java 1.0 Turns 25 by sickcodebruh on Saturday January 23, 2021 @07:09PM (#25887424)
I’m really with you. The culture around it feels borderline developer-hostile. It’s exhausting and feels like I’m participating in some strange, elaborate religious ceremony.
Re:Java 1.0 Turns 25 by u678u on Saturday January 23, 2021 @10:34AM (#25882922)
The weird thing is you dont even need getters and setters, you can make member variables public (and final if you have to). Just its the Java culture that is so wedded to it. I like Java but its the culture that makes everything soo complicated.
Re:Java 1.0 Turns 25 by derefr on Saturday January 23, 2021 @10:47AM (#25883025)
I don’t fault Java programmers for their “love” of getters/setters; they’re taking something that really is a best-practice in certain situations, and which mostly doesn’t hurt otherwise (that best-practice being “making the contractual interface for an object its methods, so that the implementation can change while the interface remains stable”) and just deciding to do it all the time rather than only when it will likely have future benefits.

Which makes a lot of sense, if you look at it through the lens of cultural anthropology. Enterprises dictate approaches like this, because the alternative is leaving the choice to the individual programmer — and these same enterprises don’t hire experienced-enough programmers to trust their judgement. And so all the programmers who work for these enterprises end up absorbing this approach as a social norm, just “something you do”, rather than “independently rediscovering the need for it” in a way that would lead to them actually knowing when it’s useful. So, even when not locked into an enterprise that forces it on them, they just keep doing it, because that’s the culture that’s been inculcated on them (and how all the examples look, how all the libraries do it, etc.)

Personally, I’m not in theory against “unilateral” use of getters/setters, either. I just kind of which they worked in Java the way they work in Ruby: where referencing a field on any object other than `this` would actually just be sugar for a call to the getter/setter. Where the Java optimizer would then take special care to optimize-away the call frame for known-‘trivial’ getters/setters.

Re:Java 1.0 Turns 25 by jrochkind1 on Saturday January 23, 2021 @12:47PM (#25884441)
I was thinking of ruby as you write this... it's not quite true that in ruby "referencing a field on any object... is just sugar for a call to the getter/setter."

It's actually true that ruby makes it impossible to directly access fields in objects other than `self` (ie `this`). Seriously, it's not possible ruby takes away the ability to do so, thereby making it not even a choice anymore, you have to create a getter/setter, it's the only option. There is no sugar, there is simply a prohibition on direct access to iVars in other objects, period.

What might make it look like "sugar" is that parentheses method calls are optional in ruby -- `obj.foo` is just another syntax for `obj.foo()` Whether or not it's a getter, any method at all, nothing special for getter/setter here. That's literally the only thing going on here that makes you think there is "sugar", ruby syntax having parentheses be optional in method calls.

And additionally ruby gives you a shortcut "macro" to defining the getter/setter, `attr_accessor :foo` inside a class body just automatically defines the conventional getter and setter for you. You still do need to define them though, again no "sugar".

So ruby actually comes down solidly on the side of "yes, always use getters/setters"... in some ways this is what you are complaining about, people always doing it, right?

But it turns out differently and not annoying anyone, I think, because it was planned for by the language designers in the first place, both by making it mandatory (eliminating it as a point of debate or as something a programmer will spend any time ever considering when implmeenting), and by providing devices to make it convenient.

I think the choice to make parentheses optional in method calls actually goes along with the choice to forbid direct access to fields in other objects; both because there is now no need to syntactically distinguish between the two, and because it makes it less annoying to forbid. It also causes all sorts of other complexity in writing parsers for ruby though...

Re:Java 1.0 Turns 25 by derefr on Sunday January 24, 2021 @11:20AM (#25893187)
I happen to know a bit about Ruby. (A lot more than I know about Java, as it happens.) Let me pick a few nits :)

#instance_variable_get / #instance_variable_set is a thing. The (default) implementations of these methods on Object are just C code that do direct IVar reads/writes. You can thus think of #instance_variable_get and #instance_variable_set as real “field access” in Ruby. It’s just that, unlike most languages, there is sugar† for the getter/setter, and there isn’t any sugar for the “direct” field access.

† (The setter’s sugar is obvious — `a.b=x` is re-written by the lexer into a call `a.send(:"b=", x)`. The getter’s sugar is less obvious — it’s seemingly just a regular method call. But think about why Ruby makes parens optional on arity-0 method calls in the first place. To sweeten getters into something field-access-looking!)

But, well, you might say, #instance_variable_get is just a method, too! I can override it as I want! Really, it’s just another kind of getter/setter — sort of a categorical one.

Well, let’s go one level deeper — you can literally “reach into” the object to take a look at its IVars as it sees them:

    obj.instance_eval{ @foo }
“Objection! #instance_eval can be overridden! DRb proxy-objects do it!”

Well, okay, let’s get creative, and start breaking through the seemingly pure-OOP semantics of Ruby, revealing the more functional-language underpinnings:

    inst_eval_fn = Object.instance_method(:instance_eval)
    inst_eval_fn.bind(obj).call{ @foo }
Re:Java 1.0 Turns 25 by nsxwolf on Saturday January 23, 2021 @11:31AM (#25883521)
Is anyone not using Lombok these days? I haven’t written a getter or a setter in years.
Re:Java 1.0 Turns 25 by JackFr on Saturday January 23, 2021 @07:29PM (#25887538)
Working with java for 20 years. Have never used Lombok, and honestly don’t personally know anyone who has. (Same with Kotlin.)

It’s a big world.

(Another weird thing for the first 25 years of my career never used anything but Sybase as a relational database — across 5 different firms. Never used Oracle or SQL Server.)

Re:Java 1.0 Turns 25 by pjmlp on Saturday January 23, 2021 @11:54AM (#25883816)
I never used and never plan to. Don't need bytecode magic that my IDE can do for me.
Re:Java 1.0 Turns 25 by marvy on Saturday January 23, 2021 @01:16PM (#25884713)
Consider the following two cases:

1. MyClass has 10 private fields, each with a trivial getter and setter.

2. YourClass has 10 private fields, of which 9 have a trivial getter and setter. The last one has a trivial getter but the setter is non-trivial.

If you use your IDE to write your getters and setters, than the two classes above will look the same at glance.

If you use Lombok, the "special" field will stick out at once.

Personally, I prefer to avoid Lombok and just use public fields. That way, the field with a nontrivial setter will also stick out, and no need for bytecode magic.

Re:Java 1.0 Turns 25 by pjmlp on Saturday January 23, 2021 @03:27PM (#25885732)
When I use my IDE, I use its code navigation features to my profit.
Re:Java 1.0 Turns 25 by marvy on Saturday January 23, 2021 @06:23PM (#25887071)
Okay now I'm curious: what IDE do you use that makes this a non-issue?
Re:Java 1.0 Turns 25 by pjmlp on Sunday January 24, 2021 @02:14AM (#25890024)
Eclipse, here are some tips.

- Ctrl + shift + T => search for types

- Ctrl + O => search for methods

- Ctrl + T => switch between classes

- Filters, https://help.eclipse.org/2020-12/index.jsp?topic=%2Forg.ecli...

Re:Java 1.0 Turns 25 by nsxwolf on Saturday January 23, 2021 @12:47PM (#25884440)
A bean with nothing but fields and a couple annotations is much cleaner and smaller than one full of generated getter/setter code. And I can rename a field without having to fumble around with the IDE to regenerate them.
Re:Java 1.0 Turns 25 by pjmlp on Saturday January 23, 2021 @01:11PM (#25884667)
Never learned to use code navigation tools and respective IDE filters?
Re:Java 1.0 Turns 25 by nsxwolf on Saturday January 23, 2021 @01:18PM (#25884736)
Those aren’t as good as just using Lombok.
Re:Java 1.0 Turns 25 by pjmlp on Saturday January 23, 2021 @01:30PM (#25884846)
Indeed, they don't provide the pleasure to dig out bugs caused by mishandling bytecodes or the verifier.
Re:Java 1.0 Turns 25 by petersellers on Sunday January 24, 2021 @12:47AM (#25889650)
Are you referring to code folding? Stuff like that helps but it's still not as good as Lombok just generating the getters and setters for you. I'm not sure if IntelliJ can filter out some of the other stuff Lombok can generate (builders, value objects, constructors, etc.)
Re:Java 1.0 Turns 25 by pjmlp on Sunday January 24, 2021 @02:06AM (#25889987)
Lombok generates too much for its own good.
Re:Java 1.0 Turns 25 by diroussel on Saturday January 23, 2021 @04:32PM (#25886320)
There is no magic. You have source code and when you compile you get byte code.

In the early versions of Lombok it was a bit dodgy as it used private APIs, but now the compiler has the public hooks and its all good honest compiler plugins.

Re:Java 1.0 Turns 25 by rufus_foreman on Saturday January 23, 2021 @12:12PM (#25884061)
I'm not a fan but the place where I work now uses it and it doesn't bother me as much as I thought it would. IDEs are smart enough to work with it. Although I still wouldn't use it on a project of my own.
Re:Java 1.0 Turns 25 by u678u on Saturday January 23, 2021 @05:19PM (#25886681)
Agreed Lombok is nice, but why can't they just put that in the runtime? You have to be suspicious of every extra package.
Re:Java 1.0 Turns 25 by dkarl on Saturday January 23, 2021 @12:31PM (#25884266)
Yeah, I think it's no accident that the best thing about working on the JVM is the massive ecosystem of popular libraries. Java and the Java community did a pretty good job of solving the problem of extremely large numbers of developers sharing code with little coordination over long timelines. Unfortunately, they did it because that was their vision of how enterprise software would be created: dozens if not hundreds of programmers working together on enormous monolithic applications with months-long release cycles. Your code had to be extremely defensive, so you could change the internals without fear, and also extensible and customizable, so you would be less likely to be interrupted by requests to make changes to support someone else's work. All the extra work and complexity to accomplish that became the "right" way to write Java code regardless of context.
Re:Java 1.0 Turns 25 by The_rationalist on Saturday January 23, 2021 @10:55AM (#25883104)
This is why Kotlin has the best of both worlds. You can access a variable through A.b and it will automatically call the getter if there's one
Re:Java 1.0 Turns 25 by kabes on Saturday January 23, 2021 @11:09AM (#25883252)
Javascript can do the same, but I think it's an anti pattern, since now the caller doesn't know what side effects, or performance characteristics you get by accessing the property with an implicit getter/setter.
Re:Java 1.0 Turns 25 by dragonwriter on Saturday January 23, 2021 @03:34PM (#25885806)
> now the caller doesn't know what side effects, or performance characteristics you get by accessing the property with an implicit getter/setter.

Beyond method call overhead (which may or may not be a given depending on how things are optimized in some languages), the caller doesn't know that automatically with explicit getters/setters, either; you'd have to read the source to know that just as much if they are explicit as implicit (or rely on documentation, which hopefully is complete and current).

Re:Java 1.0 Turns 25 by augustk on Saturday January 23, 2021 @03:47PM (#25885902)
In the programming language Eiffel this is called the uniform access principle.
Re:Java 1.0 Turns 25 by edflsafoiewq on Saturday January 23, 2021 @04:32PM (#25886315)
The uniform access principle is that features are "available through a uniform notation, which does not betray whether they are implemented through storage or through computation"; it doesn't imply anything about what the uniform notation is. Java-style getters/setters also achieve the uniform access principle; everything is accessed only via get_X()/set_X() and never a raw field .X that would betray it was implemented through storage.
Re:Java 1.0 Turns 25 by augustk on Sunday January 24, 2021 @03:19AM (#25890329)
"Although it's a fundamental feature of object-oriented programming, remarkably few OO languages really follow it. (Eiffel is naturally an exception.) Most languages simulate it by convention, hence the habit of using accessors such as getAge in Java and C++ programs."

https://martinfowler.com/bliki/UniformAccessPrinciple.html

Re:Java 1.0 Turns 25 by mgkimsal on Saturday January 23, 2021 @11:06AM (#25883220)
groovy did/does this too. any property automatically has a getter/setter in the compiled code if an explicit getter or setter doesn't exist.
Re:Java 1.0 Turns 25 by dragonwriter on Saturday January 23, 2021 @03:30PM (#25885757)
You can make member variables public, but that means that changes to how you handle access become compatibility-breaking.

If you use getters and setters, you have more future options without breaking backward compatibility. When you are making libraries that lots of other projects might depend on, this is probably more important than when making apps, especially relatively small apps.

“Getter/setter from the start” optimizes for induced maintenance cost on dependent code.

Now, in some other languages, access via getters/setters is at least source-compatible with field access, which makes this less of (or not at all, for dynamic languages, or if it is object and not just source compatibility) an issue. But that's not the case with Java.

Re:Java 1.0 Turns 25 by acdha on Saturday January 23, 2021 @04:14PM (#25886162)
> When you are making _libraries_ that lots of other projects might depend on

I think that's the key part here: most developers are writing code which will rarely or never be reused but they _learn_ by looking at shared code, and shared code which is on a different development cycle by a team nobody knows, and the field doesn't hasn't had a great history of discussing how different tradeoffs are appropriate for different projects.

Re:Java 1.0 Turns 25 by acdha on Saturday January 23, 2021 @11:16AM (#25883338)
I blame the culture, too. It’s unreal how many programmers have internalized this idea that simple code is somehow a personal failing.

One factor I’ve thought about is how many Java programmers seem to have learned design by looking at things like the Java core libraries or a few open source frameworks, without recognizing that most people are not writing code intended to be generally reusable by millions of projects and that popularity means those projects cannot modernize their style easily, either. People write new code on new projects today as if it still needs to be compatible with the early 2000s because much of the code they learned from ossified around that time, and will claim it’s “best practice” because otherwise why would this Oracle/Apache API still use it?

Re:Java 1.0 Turns 25 by JulianMorrison on Saturday January 23, 2021 @11:03AM (#25883185)
I have a tendency to do "public final" variables and set them in the constructor for data objects. There's this weird hangover from Smalltalk and the idea that everything should be overridable that wants getter and setters to be functions, when basically a read-only variable in an immutable data object is much simpler and just as safe.

But for some dumbass reason it's not "the Java way".

Re:Java 1.0 Turns 25 by pfarrell on Saturday January 23, 2021 @04:43PM (#25886439)
Encouraging immutable data objects is “the Kotlin way”, though.

You have explicitly mark properties as mutable (“var” instead of “val”). I didn’t get the value of this at first, but when we started catching bugs at coding tiime that would have been runtime errors in Java, I started to understand. This was among my takeaways from working with it in production for about two years.

Re:Java 1.0 Turns 25 by JulianMorrison on Sunday January 24, 2021 @06:59PM (#25897496)
In general Java it's still messy because although you can make the value of a variable immutable, the innards of the object it's holding are still mutable. Such as appending to a list.

You have to go as far as Clojure does and create a whole new suite of truly immutable data containers, for full safety. I dunno if Kotlin goes this far. But yeah, it's the right way.

Re:Java 1.0 Turns 25 by vbezhenar on Saturday January 23, 2021 @11:34AM (#25883560)
You will need getters/setters for some fields. So your code will look weird:

    p.x = p.getY() + p.z;
    p.setY(p.x + p.z);
It's better to use more universal approach, so your code will look unified.

Another thing why getters/setters are preferable is because when you need to replace field with computed value, you would need to replace all your code.

Proper approach would be to use properties which are available for every language but Java. They invented records, which somewhat fill that niche.

Re:Java 1.0 Turns 25 by eweise on Saturday January 23, 2021 @07:09PM (#25887422)
I've used Java for over 20 years. Not once have I ever replaced an attribute with a computed value.

Also p.x = p.y + p.z is much easier read.

Another drawback of getters and setters is that you end up not looking at that code because you assume you know what it does, so you can miss when someone puts logic into a setter or getter

Re:Java 1.0 Turns 25 by augustk on Saturday January 23, 2021 @03:51PM (#25885936)
I don't like the idea of having a verb in the name of a pure function. I think it reads better to simply name the function after the result it returns.
Re:Java 1.0 Turns 25 by c00lc4t95 on Saturday January 23, 2021 @10:53AM (#25883088)
Java developer 6yrs here. I've worked in code bases and extended internal libraries that forgo the getters/setters model, for exposing member variables directly, and it's not better.

If you ever need to change something about that value, do additional logic before returning (I e. emit metrics), or model a data class with an interface having getter methods makes these so much easier.

Re:Java 1.0 Turns 25 by hakfoo on Saturday January 23, 2021 @02:40PM (#25885366)
I think it's a YAGNI problem, perhaps not consciously stated. The premise is if we never touch the public members, we can one day update the setters to add validation, or analytics, or include some automated formatting shim inside the getter...

But nobody actually does it.

Re:Java 1.0 Turns 25 by xxs on Saturday January 23, 2021 @10:45AM (#25883014)
getters/setters became popular with RMI. Public fields have all kind of security/code smell issues. Most classes should be immutable.
Re:Java 1.0 Turns 25 by JulianMorrison on Saturday January 23, 2021 @11:08AM (#25883243)
Public writeable fields are threading and encapsulation smells but public read-only fields just say, this data is part of my interface.
Re:Java 1.0 Turns 25 by xxs on Saturday January 23, 2021 @12:17PM (#25884120)
well, yes however fields cannot be part of an 'interface' in java. (they can but they'd be static)

I do use package private fields liberally, though. Just not non-static public fields.

Re:Java 1.0 Turns 25 by JulianMorrison on Sunday January 24, 2021 @06:55PM (#25897475)
Interface as used here means the broader concept of a "a class's interface is its public advertised operations" and not the specific Java thing called an interface.
Re:Java 1.0 Turns 25 by bcrosby95 on Saturday January 23, 2021 @07:14PM (#25887461)
Problem is lots of tooling and libraries you might integrate with assume getters and setters and literally won't work without them.
Re:Java 1.0 Turns 25 by pjmlp on Saturday January 23, 2021 @11:53AM (#25883807)
It was brought by Smalltalk and C++ developers, but I guess 25 years later many don't get that part of history.
Re:Java 1.0 Turns 25 by vips7L on Saturday January 23, 2021 @06:20PM (#25887052)
Or just use Java records.

    public record SomeViewModel(String name, int age) { }
Re:Java 1.0 Turns 25 by chapium on Saturday January 23, 2021 @11:26AM (#25883448)
Getters are necessary because Java does not have read only attributes (except final).
Re:Java 1.0 Turns 25 by frevib on Saturday January 23, 2021 @10:33AM (#25882908)
Kotlin is slighty better Java. No more getters, setters, hashcode and toString. Kotlin is also much better Java for asynchronous programming, null-safety, and functional programming. It’s modern Java.
Re:Java 1.0 Turns 25 by twistedpair on Saturday January 23, 2021 @01:53PM (#25885031)
Same goes for Scala and Case Classes. Alas the type astronauts went crazy with Scala, scaring some folks off.
Re:Java 1.0 Turns 25 by eweise on Saturday January 23, 2021 @07:10PM (#25887435)
I agree. I wish the Scala community would inherit some of the simplifying culture of the Go community.
Re:Java 1.0 Turns 25 by ebruchez on Saturday January 23, 2021 @09:24PM (#25888408)
Scala 3 introduces a number of simplifications. For example, typeclasses and other constructs are much easier with Scala 3. This said, Scala always included the idea of having a powerful type system. From this perspective, it can never be as simple as a language that doesn't have a comparatively powerful type system (or no static type system at all).
Re:Java 1.0 Turns 25 by bcrosby95 on Saturday January 23, 2021 @07:37PM (#25887600)
The philosophy behind Kotlin and Java really couldn't be more different. Go is much closer to a modern Java than Kotlin.

Kotlin does have some nice additions. But it is very much a kitchen sink language. I wish I could take some of those nicer additions and leave the sink.

Re:Java 1.0 Turns 25 by pjmlp on Saturday January 23, 2021 @11:56AM (#25883839)
Without a VM to call its own, unless we start talking about ART or the failure of Kotlin/Native memory model.
Re:Java 1.0 Turns 25 by xxs on Saturday January 23, 2021 @10:41AM (#25882989)
Well, getters and setters are a choice that's not predominant for the core java packages: java.lang, java.util, java.io, java.nio, etc.

Of course there were added with awt 1.1 and swing in an attempt to catch up with the visual programming jazz and for many it never disappeared. Later on there was (still is) a trend to use builders... and a general shift for immutability.

Re:Java 1.0 Turns 25 by Deinumite on Saturday January 23, 2021 @07:39PM (#25887612)
I see this cited a lot, but honestly I would say the majority of jobs use Spring, and it has been that way for quite a while.
Re:Java 1.0 Turns 25 by zmmmmm on Saturday January 23, 2021 @08:03PM (#25887745)
Can I suggest trying Groovy (properly, not in the form of hacking together gradle or jenkins scripts, but as an application language)?

It's basically what you want but unlike the other "dead" languages it is designed to complement Java rather than compete with it and is unlikely to ever become obsolete for that reason.

Re:Java 1.0 Turns 25 by noisem4ker on Saturday January 23, 2021 @10:27AM (#25882866)
>Getters and setters

Meet Project Lombok. Problem solved and forgotten.

Re:Java 1.0 Turns 25 by Vax45 on Saturday January 23, 2021 @10:58AM (#25883149)
I prefer Immutables for code generation. Lombok tends to interfere with Eclipse' code evaluations (last time I used it, it kept interfering with searching for a generated method's usage in your code base) and tends to confuse me when trying to figure out if something's an actual method or a method that was injected into the AST during compilation.

Immutables has its own set of problems, but at least it uses the standard Annotation processor and has a clear separation of generated code and the interface you write.

Haven't used Java's new record's yet, so don't really know anything about that.

Re:Java 1.0 Turns 25 by dehrmann on Saturday January 23, 2021 @01:04PM (#25884601)
I can't remember the exact issues, but there's enough magic going on in Lombok that it doesn't play well with Kotlin, so you're better off with Autovalue or Immutables to future-proof things. I also generally don't like how much magic Lombok uses, regardless of if you needs support for any other JVM languages.
Re:Java 1.0 Turns 25 by zmmmmm on Saturday January 23, 2021 @08:00PM (#25887722)
After spending nearly a whole day trying to get a lombok build configured and working in my IDE ... I just gave up on it. It's a nice idea but I prefer to use something like Groovy where the AST transformations happen directly in the language space rather than in a meta-build step that requires so much IDE involvement. (not to mention most of them not even needed because Groovy just does those conveniences by default).
Re:Java 1.0 Turns 25 by ivan_gammel on Saturday January 23, 2021 @10:54AM (#25883100)
Well, no, it is not. Lombok does not mask invocations, so it is still foo.getA().getB().getC()
Re:Java 1.0 Turns 25 by neeleshs on Saturday January 23, 2021 @11:04AM (#25883191)
Not in the language, but Lombok makes it a non-issue
Re:Java 1.0 Turns 25 by parasubvert on Saturday January 23, 2021 @11:59AM (#25883875)
Much of the JEE ecosystem (not all) has been replaced by Spring Boot or Quarkus. Generally they have been a delight.
Re:Java 1.0 Turns 25 by AtlasBarfed on Saturday January 23, 2021 @08:21PM (#25887909)
Use groovy with @CompileStatic. At least for your beans. Autogenerates the getter/setters.