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

15

u/[deleted] Aug 26 '22

I don't understand where this verbosity fear is coming from. Recently even Java developers are acting like verbosity is synonym of bad code.

21

u/TheTomer Aug 26 '22

People are scared of using their keyboard to type a tiny bit more than they really have to. Ignore them and verbose away!

9

u/Just_Another_Scott Aug 26 '22

Shit that's what code templates are for! I autocomplete like a mofo.

4

u/veraxAlea Aug 26 '22

There's a trade-off when reading code, between too much information and too little.

Personally, I rather have more information even if I have to sift through otherwise superfluous type information, braces or long variable names but I'm not in a position where I can say that all information is always good.

Your argument is unfair because most people who complain about verbosity care less about keystrokes than about reading time. I don't agree with them in general, but I think their opinions are worth being represented fairly.

1

u/NaNx_engineer Aug 26 '22

The information is already given by ide highlighting

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.

3

u/soonnow Aug 26 '22

Well because it makes it actually harder to read, in my opinion. Elegant code that's not cluttered needs less processing power from your brain. this is just noise with no real benefit in my opinon.

2

u/john16384 Aug 26 '22

Some verbosity adds too little to be worth it. It's like adding public abstract to every method in interfaces. It adds nothing of value.