As I start to code more and more, for example in C++, I tend to also want to learn more about the accepted standards for code.I'm trying to code a chess engine right now, but I'm unsure how to treat each 'module' of the program (which is separated into different files).For example, it makes sense to make a class for bitboards as bitboard.h and bitboard.cpp, as this might be required later on. But, it doesn't make sense to have a class for the move generator, because I won't ever need more than one move generator.But I still want to abide by the principle of least privilege, and not give users access to more functions than necessary. But, I'm not sure if you can do this without a class? I've looked at namespace but I'm not sure how it'd apply in this case.How do professional programmers handle this sort of thing? I've looked at the source for the Stockfish open source chess engine, and it has both header files and cpp files, but the header files simply seem to have a whole bunch of variables.
Modular programming practices
c++;programming practices
The Principle of Least Privilege is about security, not software engineering and should not be confused with Encapsulation.  They are two very different things.The point of the Principle of Least Privilege is to give a user (or application) the bare minimum of permissions it needs.  So user A may get a different set of permissions than user B.  This is to make it hard for potentially malicious users to gain access to potentially dangerous features as it requires that they have explicit permission.Encapsulation is about making it clear about what parts of your class are meant for external user and what parts are meant to be ignored by the caller.  The purpose here is not about malicious users, but rather, about making sure users don't accidentally write code that depends on things that may change in the future.  It also pushes class authors to create clear interfaces.Inherent in the Principle of Least Privilege is that different users have different permissions.  There is no notion of that in all in Object Orient software.  All users of your classes have the same access.  Also implicit in the Principle of Least Privilege is that you are forcing users into a restricted subset.  By contrast, Encapsulation can be easily broken in many Object Oriented languages.  (In some, like Python, encapsulation is entirely handled with coding standards.)If you try to design classes with an eye to restricting users to a minimum (as with the Principle of Least Privilege) you are likely going to end up with classes that are limited and hard to use.  Instead, you should look at it from the perspective of what are the users going to want to do with this class.  The public interface is everything you can think of that users will want to do.  Then make everything else private.  That's Encapsulation.In essence, when designing classes, you want to operate with an eye to giving users the most privilege you can safely give them.