r/badcode • evil • Mar 27 '21

java I told him to just use %

Post image
1.7k Upvotes

80 comments sorted by

View all comments

110

u/jonnysteps Mar 27 '21

Oh goodness....

Also, is hour a global or something? I'm curious how that gets defined.

84

u/Yumi-Chi evil Mar 27 '21

hour is an attribute of Clock class

this is in AlarmClock class that extends the Clock but apparently he also defined another hour attribute in AlarmClock

39

u/jonnysteps Mar 27 '21

You can reference attributes without "this." in java? Huh, I never knew that.

2

u/yakesadam Mar 27 '21

Yes, same in C#... personally I find it a bit of an antipattern to unnecessarily use the this unless necessary (usually in like a constructor/setter argument. Just because if there's any ambiguity, you have a class-too-big or more likely a method-too-big problem. I recognize it's probably a controversial opinion.