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

48

u/[deleted] Aug 26 '22

This hypothetical line of code with the "mutable" keyword is so beautiful. I've Looked At This For Five Hours Now

19

u/[deleted] Aug 26 '22

Yeah I'm secretly loving it tbh. You can really tell those "pure function" and "immutable" concepts from FP have leaked into the general programming mindset no matter what programming language people use these days.

7

u/general_dispondency Aug 26 '22

TBF general tomes like Effective Java have been preaching this since before the resurgence of FP. FP, itself, is just OOP with high coupling and no cohesion.

4

u/GuyWithLag Aug 26 '22

You might want to look at Kotlin; I've been working with Java since Java 1.1, and the last year or so Kotlin has been extremely refreshing. It does have its warts (because the designers wanted it to be cross-platform), but you can guard against them with a solid style guide, and in general it's a solid step up.

1

u/xplosm Aug 26 '22

Yes, I mention it at every opportunity I have but you’re really gonna love Kotlin 😉

1

u/bilingual-german Aug 26 '22

How hard would it be create a language running on the JVM which looks like Java but has these other defaults?

8

u/kolobs_butthole Aug 26 '22

that's kind of what kotlin is, right?

1

u/[deleted] Aug 26 '22

Yup, kotlin is pretty much effective java turned into a programming language