|
|
|
|
|
by linhat
4582 days ago
|
|
I wish I could upvote this more than just once. Using 'struct' instead of 'class' and combining that with templated "pure functions" [1], when applicable, make for some really readable/maintainable/extensible C++ code, which, although often overlooked, is a multi paradigm programming language (the OOP proponents want you to believe otherwise ;-). Especially, as mentioned in the article, the fact that if you're honest you almost never really need private class members (that might later force you to create set/get-ters) really resonates. These days, I prefer to create an interface using the PIMPL idiom [2] completely hiding the underlying implementation, whilst the implementation itself preferably consists of data structures and collections of these (hence 'struct') and some templated functions to modify these. This also resonates with an old C mantra: design data structures first, model functions after their behaviour or something similar [where I just cannot find a quote for]. My main gripe with using 'struct' in favor of 'class' is probably the compatibility problem with other programmers that might become confused as to why you are doing such weird things... [1] https://en.wikipedia.org/wiki/Pure_function [2] https://en.wikipedia.org/wiki/Opaque_pointer |
|