3 ms·
Thank you for posting, OP! I have a tangential question about your programming style. I've noticed you define quite simple structs, that nevertheless have const
by vladharbuz 6y ago
Thank you for posting, OP! I have a tangential question about your programming style. I've noticed you define quite simple structs, that nevertheless have constructors and are not POD (e.g. they include a deque<>), and define the methods that work on them inside a namespace. [0]
The two main styles I've seen are (1) the classic full-fledged OOP-y C++ classes with methods, and (2) POD structs with functions that work on them defined in namespaces, in a more C-like style.
Your style seems to be a mix. You don't seem to get the big downsides of OOP, as you're grouping functions per namespace instead of having to make everything a class and ending up with a contrived architecture. At the same time, you're still going to be using many C++-isms due to your use of non-POD structs, which some people may appreciate (for uniform initialisation and memory management), and some people may enjoy less (due to the limitations and complexities of constructors, being forced to use exceptions etc.).
I apologise for my extremely superficial description, but I think it's enough background for my question, namely: could you speak a bit about this programming style, what led you to choose it, and what you enjoy/don't enjoy about it? Thank you! :)
[0]: https://github.com/codr7/liblgpp/blob/main/src/lgpp/parser.hpp https://github.com/codr7/liblgpp/blob/main/src/lgpp/parser.h...
- codr7 6y agoYou're welcome, the isolation is not without upsides :) That's correct, I tend to drift towards the same style when the language allows it. This is the result of 35 years of trial and error, not so much careful planning. I've found that structuring my code like this makes it more enjoyable to deal with. C++ being C++, simplifying and cutting it down to its core is essential from my experience. But I like constructors and destructors, and the standard library is pretty nice these days.
- jimsmart 6y agoI like this programming style, personally. The pattern of having helper funcs as well as class/struct methods, which is most appropriate, is a pattern I seem to see quite frequently with Go code.