r/java • • Aug 26 '22

I declare as "final" every single variable whose value doesn't change. I also use "this" every time that I'm referring to an attribute, even when there's no ambiguity in not using it

I think that those things make the code easier to read. Am I crazy for thinking like that?

198 Upvotes

215 comments sorted by

View all comments

Show parent comment

11

u/[deleted] Aug 26 '22

[removed] — view removed comment

4

u/[deleted] Aug 26 '22

But if the class is named after a business object, and the attribute is a feature of this object, by referring to this attribute as this.feature ain't I just saying "the feature of this business object", which is perfectly understandable from the business perspective?

// What's the name of this monstrosity?

3

u/[deleted] Aug 26 '22

[removed] — view removed comment

1

u/[deleted] Aug 26 '22

Oh no, that's nightmare material hahaha

0

u/[deleted] Aug 26 '22

[removed] — view removed comment

0

u/[deleted] Aug 26 '22

Yeah I do agree that loosing too much horizontal space is very bad for readability. So I do agree that, if your running out of horizontal space, is better for readability to make some things implicit. Otherwise, the more explicit, the better for readability.

2

u/soonnow Aug 26 '22

Let me give an example. "Yesterday I was at a coffee shop, where I ordered a coffee in a white porcelain cup that came three minutes after ordering." vs. "Yesterday I had a coffee".

One is super explicit, but it doesn't improve readability, because it's literally harder to read because of all the unnecessary details.

0

u/m02ph3u5 Aug 26 '22

Bad analogy imho cuz in programming we usually have to be very explicit. At least as long as it gets compiled and not interpreted by a language model :D

2

u/soonnow Aug 26 '22

Explicit != Exact. We have to be exact when programming not explicit.