14 ms·
Honestly, subclassing strikes me as mostly unnecessary. Most of those use cases can be addressed with protocols or traits.
by EPWN3D 1y ago
Honestly, subclassing strikes me as mostly unnecessary. Most of those use cases can be addressed with protocols or traits.
- Spivak 1y agoWelcome to the Python community's "subclassing is only for sharing code, user-beware if you try to use it for anything else."
- default-kramer 1y agoI strongly prefer FP over OOP, but... Is there any desktop GUI library that isn't built on subclassing? Winforms, WPF, Swing, Qt, Godot all do. This doesn't prove that subclassing is necessary, but it sure seems like the best approach we've found so far.
- dragonwriter 1y ago> Is there any desktop GUI library that isn't built on subclassing? There are desktop GUI libraries implemented in C, Go, and other languages that do not have subclassing, so, the answer kind of has to be yes.
- throwaway2037 1y agoGtk+ is pure C, but the library essentially implements subclassing manually. It is so painful to use, and so much worse that the C++ equivalent in gtkmm. Again, Win32 API does similar to allow subclassing of widgets. Again, painful.
- SideQuark 1y agoEvery GUI toolkit I've used, which is many, implement subclassing for UI elements whether or not the language supports it. Remember, C++ was originally written in C, so it's clear lack of a native language feature doesn't mean things written in that language also lack that feature.
- throwaway2037 1y agoI think your reply is more elegant than mine. Years ago, I worked on a Wall Street trading app that was written in pure C but had inheritance. It was a miracle to read the code as a 25 year old! I wonder if there are any modern UI toolkits that do not use subclassing at all -- actual (C++/Java/C#) or synthetic (C). It would be such a PIA not to inherit from a base widget that handles most basic operations. Maaaaaybe it could be done purely with encapsulation... But, oh brother, that would a lot of boilerplate code!
- tpmoney 1y agoI think the closest I’ve encountered is the Objective C frameworks Apple used to use. Customizing the behaviors of default library components was almost exclusively done with delegates and protocol implementation rather than subclassing.
- billmcneale 1y agoThe question is not whether it can be done (of course it can) but rather, what is the more elegant approach. There is plenty of evidence that OOP provides some flexible, extensible, and intuitive ways to design GUI libraries. I have personal experience that OOP can be the better approach in other fields too (such as overriding a specific method of a larger structure).