5 ms·
The hill I’ll die on is to avoid classes, everywhere. You don’t need classes. Just use functions and structs (or plain objects, etc.). OOP was a terrible mistak
by monero-xmr 3y ago
The hill I’ll die on is to avoid classes, everywhere. You don’t need classes. Just use functions and structs (or plain objects, etc.). OOP was a terrible mistake and mixing state with logic was a major catastrophe that poisoned a few generations of engineers. Burn the Gang of Four design patterns and scatter the ashes into the ocean.
- foobarkey 3y agoI will join you on that hill, just make a pureish function/method that does the thing its supposed to do and job done. Although in 10% of cases OOP and inheritance is useful
- fuzztester 3y agoOOP can be used without inheritance, using composition. Actually all four ways are possible: with either, neither, or both. The GoF book says to prefer composition over inheritance much of the time, in an early page of the book.
- mvdtnz 3y agoFrom 15 years industry experience my biggest takeaway is to ignore advice from anyone who claims their point of view applies "everywhere".
- monero-xmr 3y agoWell I have over 20 years experience so maybe you need 5 more years or so
- piva00 3y agoReaching 20 years mark here, and I kinda agree and disagree with your initial take. Hear me out, I don't think classes should be used to mutate state, or perform actions on their own. But they are a nice way to namespace and think about components properly. It can be achieved with just structs and functions (strongly typed, for the love of all deities) but giving a container like a class has its advantages to namespace some categories of functions belonging to their own structs. I agree that many other uses of classes (and fucking design patterns piled on top) were, and still are, a major source of pain in software development, I'm very glad to see that a lot of folks around the 15-25 years of experience realised the footguns are not worth it and adapted to write more readable "dumb" code.
- sgarland 3y ago> namespace Precisely. I’m a DBRE, not SWE, but I use Python a lot, and have written some internal tooling. Classes as namespacing is wonderful.
- monero-xmr 3y agoJust namespace with folder and file structure. Done
- eyelidlessness 3y agoI share your take, and I’ll even say that classes are an underused tool when applying functional principles in mixed paradigm languages. If you use a class as a struct (with value semantics), you get: - A type - A name for it - A canonical way to build a value of that type - A consistent way to reference its semantic meaning at runtime and in any static/build time/documentation format - A singular, easily discoverable place to change it
- tensor 3y agoMost "non-oop" languages like Go and Rust have all of this. They also generally have interfaces. What they don't have is inheritance, which I think is what really differentiates OOP from structs with interfaces.
- eyelidlessness 3y agoEven inheritance of classes-as-structs is probably under-appreciated. It’s not quite as flexible as more general composition. But it’s not nearly as problematic as OOP inheritance, because it’s ultimately only a hierarchical composition of taxonomy and value construction semantics. It can become problematic if you apply the wrong taxonomy, but that would be true without inheritance as well.
- 000ooo000 3y agoAmen. Everything in software is about tradeoffs. The only sensible answers to software questions start with "it depends". Dogmatic shittalking of OOP, a paradigm that quite a few developers are happily using to produce successful software, only highlights a lack of perspective and an unjustified arrogance.
- fuzztester 3y agoSOLID point. Pun intended.
- klysm 3y agoI generally agree with you. The only time I find classes make sense is when you need a stateful imperative handle. Those cases are rare.
- breadwinner 3y ago> OOP was a terrible mistake and mixing state with logic was a major catastrophe You're gonna have to justify that. Can't just take your word for it. Where do you store your state, if not in objects?
- margorczynski 3y agoThe struct. OOP tries to combine the struct (data) and functionality (methods) into one and it is a bad idea.
- monero-xmr 3y agoAnd that’s the essence of OOP. Once you grasp why that is such a colossal blunder, it’s obvious what a mistake the entire endeavor truly is.
- deleted 3y ago[deleted]
- breadwinner 3y agoThat's how the real world is. The state and the functionality are in one thing. OOP models the real world. Are you suggesting that data should be stored in global variables instead?
- monero-xmr 3y agoYou don’t lose scoping by avoiding classes. I’m not really sure what you are asking. You store all data in primitives or structs, and pass it along to functions, which mutate the data. Much simpler to reason about, comprehend, debug, test, and so on.
- breadwinner 3y ago> You store all data in primitives or structs, and pass it along to functions OK, so in global variables, like in C language. And you think this is better than OOP. Glad that's working for you!
- wayeq 3y agoYikes. That kind of all-or-nothing thinking is a red flag. Structs and functions are great if you see yourself adding more new functions than data types in the future (the existing functions don't need to change!). OOP is great if you see yourself adding more data types (the existing classes don't need to change!).
- tensor 3y agoStructs with functions and interfaces retains most of the good parts of OOP. I agree that inheritance seems to be more trouble than it's worth.
- the_real_cher 3y agoPeople create a bajillion non-deterministic little state machines in their code and act like it's no big deal.