News for hackers. Stuff that matters.
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.