News for hackers. Stuff that matters.
Re:Why I Don’t Regret Moving Our Android App to Scala by saghm on Wednesday July 12, 2017 @10:33PM (#14758329)
While I don't agree with the general tone of the above comment, I am curious if anyone can enlighten me on why one would need a getter on a member that's already public.
Re:Why I Don’t Regret Moving Our Android App to Scala by curun1r on Thursday July 13, 2017 @01:00AM (#14758848)
I forget who said it, but there's a quote along the lines of, "There's no problem in programming that can't be solved by adding another layer of indirection. Getters are just that, a layer of indirection. So they give you a hook to intercept a call and do something that wouldn't be possible with direct field access. Perhaps you want to lazy-load the field, or dynamically compute its value under certain circumstances. Whatever it is, if you use getters from the outset, you won't have to change code that calls the getters when you decide you need that indirection.
Re:Why I Don’t Regret Moving Our Android App to Scala by saghm on Thursday July 13, 2017 @11:24AM (#14762055)
Fair enough, although those types of things seem like they'd need to be explicitly written, not auto-generated by a compiler (like the ones described as existing for Scala)
Re:Why I Don’t Regret Moving Our Android App to Scala by simon_o on Thursday July 13, 2017 @12:13PM (#14762534)
That's the whole point of what Scala is doing.

Allow flexibility to support such requirements later on, without forcing people to break source and binary compatibility, unlike in Java, C# etc.

That's the reason why you can e. g. implement or override a def with a val.

Re:Why I Don’t Regret Moving Our Android App to Scala by gregghz on Wednesday July 12, 2017 @10:58PM (#14758409)
you don't. Scala produces them automatically for case classes. Kotlin will treat x.count as x.getCount() if getCount exists and count doesn't. They are mostly a side effect of the tools and not strictly required.

Especially in Kotlin and Scala where data tends to be immutable by default there isn't much to gain by using getters.

If your "getter" is doing more than getting the value then maybe you should not call it a getter (imo).

Re:Why I Don’t Regret Moving Our Android App to Scala by lgas on Thursday July 13, 2017 @01:54AM (#14759029)
I think the heart of the question was more, if the members are already public, why does Scala need to produce getters for them, why not access the members directly?
Re:Why I Don’t Regret Moving Our Android App to Scala by gregghz on Thursday July 13, 2017 @03:14PM (#14764267)
I honestly don't know.
Re:Why I Don’t Regret Moving Our Android App to Scala by saghm on Wednesday July 12, 2017 @11:58PM (#14758586)
> If your "getter" is doing more than getting the value then maybe you should not call it a getter (imo)

I'd definitely agree there! In fact, I might go further and say that if your "getter" does more than just return a member, then by definition it isn't a getter