Well the main reason I was struggling a bit with it's use was the fact that I was always taught to reduce the scope of variables/data when possible, for the same reasons you don't want global variables.
For larger projects minimizing complexity is crucial and breaking your program into discrete black boxes (ideally) that communicate (through well defined interfaces) with as few of each other as necessary, should almost always be a priority.
forkingpaths
I think that this kind of discussion (using globals, private vs. public, etc) tend to generate a lot of "general aesthetic" opinions, because the langages at hand (here C/C++) are not really good at providing what we want in term of invariants.
All the arguments ultimately revolve around how we enforce invariants or "state consistency" in a program, so that we can reason about it. Eg. "you should use accessors and not touch global shared state to ensure your data are always in a consistent state", vs "you don't want the langage to get in your way, and you can be disciplined enough to not touch what you're not supposed to touch".
forkingpaths
C style doesn't help you much to enforce anything beside minimal type correctness, so it's easy to have wrong assmuptions about what the state of the program can be when a particular piece of code is executed, which is the cause of most subtle bugs.
forkingpaths
More often I would like features to enforce invariants at the function/block level ie. declaring which state can be touched in a particular block of code (eg captures/lambda/something to be invented) rather than declaring which state can be touched inside a particular block of data (private/public).
If we had semantics that allowed us to choose which invariants we want to be true inside a particular piece of code, there would be no point in all these "best practices" opinions, because you would declare the invariants you need to reason about your code, and the discussion could not be detached from that particular piece of code.
And calling something an opinion on "general aesthetics" is simply an out of hand dismissal.
Everyone has different skillsets/strengths/ways of reasoning/etc. so the idea that what's the most common cause of bugs for me is going to be the most common cause of bugs for you and most other programmers seems totally unfounded.
That may be fine for you but there are also plenty of people out there for whom reasoning about global state is not a major cause of bugs nor a major productivity drag, so discussions like this one would be a good candidate to fall under the heading of "general aesthetic" opinions.
forkingpaths
Exactly, I was just saying that the language should let you decide on which invariant you want to be enforced, and not decide on you behalf which kind of safety you need. No need to turn my own words around, which weren't meant to be rude anyway. Of course, everyone here is talking from their own point of view and no one is trying to impose their ideas ! If you do not experience this kind of needs at all, or are not subject to bugs related to wrong assumptions about the state of your programs, that's great : Tell us what's your approach to this type of complexity, tell us what kind of bugs bite you more often, what features you would need to prevent it, etc...
A lot of subtleties get lost communicating across a forum.
forkingpaths
Yeah, and English is not my native language, which doesn't help. I most certainly lack some sense of nuance compared to a native speaker, so don't be offended !
I played devil's advocate with Jon on the the value of encapsulation. The resulting conversation may interest folks: http://handmadedev.show/ep-10-2016/ (section: 'On the utility of abstraction')
I played devil's advocate with Jon on the the value of encapsulation. The resulting conversation may interest folks: http://handmadedev.show/ep-10-2016/ (section: 'On the utility of abstraction')
TL;DR: Abstractions help programmers temporarily forget details, and that can be useful. Some best practices on how to encapsulate, however, are questionable.
boagz57
At a certain point, more levels of abstraction really only obscure the purpose of that particular code and make things harder, not easier, to understand. This definitely goes against the grain of most C++ books and discussions which value abstraction/encapsulation as on of the main end goals of any particular piece of code and never really emphasize the trade-offs of doing so. I know in my experience, when trying to understand certain C++/OO code bases I tend to get completely lost in the abstractions and find things very difficult to follow.
NelsonMandellaboagz57
At a certain point, more levels of abstraction really only obscure the purpose of that particular code and make things harder, not easier, to understand. This definitely goes against the grain of most C++ books and discussions which value abstraction/encapsulation as on of the main end goals of any particular piece of code and never really emphasize the trade-offs of doing so. I know in my experience, when trying to understand certain C++/OO code bases I tend to get completely lost in the abstractions and find things very difficult to follow.
Keep in mind that most mainstream C++ books are targeted at the lowest common denominator, the average case (i.e. not very good) being programmers who are essentially cogs in some large company machinery. In this context the additional abstractions, guards rails, etc. may make perfect sense. Game engine programmers/expert programmers/lone wolfs/etc. fall well on the margins (or entirely outside of) the target audience of most of these kinds of mainstream books.
forkingpaths
I almost forgot about this, I'm going to listen to it again ! Do you plan to make any new interview ?
forkingpaths
By the way, how's the compiler going ? :-)
boagz57
What I also like is he seems to validate what I and I know a lot of other people tend to think when learning about programming, despite being taught the opposite.
TelashNelsonMandellaboagz57
At a certain point, more levels of abstraction really only obscure the purpose of that particular code and make things harder, not easier, to understand. This definitely goes against the grain of most C++ books and discussions which value abstraction/encapsulation as on of the main end goals of any particular piece of code and never really emphasize the trade-offs of doing so. I know in my experience, when trying to understand certain C++/OO code bases I tend to get completely lost in the abstractions and find things very difficult to follow.
Keep in mind that most mainstream C++ books are targeted at the lowest common denominator, the average case (i.e. not very good) being programmers who are essentially cogs in some large company machinery. In this context the additional abstractions, guards rails, etc. may make perfect sense. Game engine programmers/expert programmers/lone wolfs/etc. fall well on the margins (or entirely outside of) the target audience of most of these kinds of mainstream books.
True, but that does in no way mean that C++/OO is better, or even as good in huge codebases on huge companies. I have worked in several now, and ALL of them have in common that parts made in C (sometimes all of their code) are stable, fast, and reliable. The C++ parts are always slow buggy messes. This have been the rule in ALL of them so far.