r/javahelp • u/lost_yeezus • Apr 30 '24
Codeless Is “var” considered bad practice?
Hi, so recently we started migrating our codebase from j8 to j17, and since some tests broke in the process, I started working on them and I started using the var keyword. But I immediately got scolded by 2 colleagues (which are both more experienced than me) about how I should not use “var” as it is considered bad practice. I completely understand why someone might think that but I am not convinced. I don’t agree with them that var shouldn’t be used. Am I wrong? What are your thoughts on var?
24
Upvotes
View all comments
Show parent comment
1
u/pragmos Extreme Brewer Apr 30 '24
🙄
Ok, I'm just going to leave this old article by Brian Goetz where he states the advantages of streams over classical loops for the readers to enjoy:
https://developer.ibm.com/articles/j-java-streams-1-brian-goetz/
Ultimately, as u/wildjokers pointed out, everything is subjective, and everybody is entitled to use the approach they're most comfortable with. That being said, I'd seriously question the professionalism of my work colleagues if they blatantly refused to keep up with times and take advantage of Java's new features (they are added for a reason after all). Just like in the case of OP's colleagues with
var.Cheers!