2 ms·
Well, it said controversial, and it didn't disappoint! I was surprised to see the one about getters and setters: "they make them private and provide getters an
by commandlinefan 6y ago
Well, it said controversial, and it didn't disappoint! I was surprised to see the one about getters and setters: "they make them private and provide getters and setters for all of them." I had begun to think I was the only person who felt this way (now I think he and I are the only ones). Getters and setters (and "datatypes" in general) miss the point of object oriented programming.
- selfhoster11 6y agoNot only do getters and setters miss the point of OO programming, but (controversial opinion) they utterly kill it dead in Java. Every. single. Java. object. now has to have them. The average Java data class is a tiny stub at the top of the file that contains the class name and the data structure definition, followed by a parasitical mound of getters, setters and builders. This unsightly growth of boilerplate ends up being regenerated by the IDE tooling every time it changes anyway. I feel like I'm working with C, except that the code I'm editing has already been through the macroprocessor. Any needles of "smart" logic are drowned out in the haystack of dumb accessors. That same haystack, coupled with auto-regeneration, makes it very easy to clobber any "smart" accessors, so nobody dares to be clever. It's always logic on the outside of the class. There is a thing do'er that does something to the class, but the class has no idea how to do the thing with its own data by itself. This is the antithesis of the very ideas that OOP promotes. Whether they are a good idea is debatable, but the fundamental conflict cannot be ignored.
- kondu 6y agoThankfully, plugins like Lombok partially solve this issue - while we still have unnecessary accessors, atleast they don't pollute the source code and make it hard to read and navigate.