   Where to put project constants? Header file?
  ^ where to put variables that every class needs?   
  Mu. There aren't any variables that *every* class needs.But for certain types of constants, yes - a "const <type>" declaration in a header is a natural solution.   ;  Directly to the point: Extern them in a header file, have the actual variables in a .cpp file. or Define them as const in a a header file. or #define them in a header file.That said, it's poor design to have lots of shared variables at a global scope.  It becomes very hard to track who is using it and why.  Assuming they are const, someone might edit the code to fix something they are doing, and end up breaking everything else.  Assuming they are non-const, someone might edit the variable at runtime, breaking some other thing.It's also poor design to have "magic numbers" all over the place. It makes sense for a small subset of numbers. Math constants are a good use, like pi, std::numeric_limits, root_2, etc.  Maybe you have, for optimization, constants like MAX_PATH_LENGTH instead of dynamic buffers. But numbers like PLAYER_HIT_POINTS should be abstracted out to a data file that is loaded in the player code, and the player code should have an accessor function "GetMaxHP".   ;  Also consider storing them in data files, if appropriate for the context of the value in question.   ;  the variables are for graphics settings, such as screen mode.why is c++ such mess for online documentation? compared to java? and visual studio 2010 can't refactor anything? what the hell. and i've noticed that some people defend c++'s short comings as more "hands on". sure, some of it is, and the object management is less sloppy than in java, but the header guards, macros... GRR/complaining   ;Quote:Original post by KulSeranDirectly to the point: Extern them in a header file, have the actual variables in a .cpp file. or Define them as const in a a header file. or #define them in a header file.That said, it's poor design to have lots of shared variables at a global scope.  It becomes very hard to track who is using it and why.  Assuming they are const, someone might edit the code to fix something they are doing, and end up breaking everything else.  Assuming they are non-const, someone might edit the variable at runtime, breaking some other thing.It's also poor design to have "magic numbers" all over the place. It makes sense for a small subset of numbers. Math constants are a good use, like pi, std::numeric_limits, root_2, etc.  Maybe you have, for optimization, constants like MAX_PATH_LENGTH instead of dynamic buffers. But numbers like PLAYER_HIT_POINTS should be abstracted out to a data file that is loaded in the player code, and the player code should have an accessor function "GetMaxHP".so i should store the player variables on disk, not in memory? this makes sense for reloading old game states, but that isn't the issue   ;Quote:Original post by overeasythe variables are for graphics settings, such as screen mode.And when a user wants to change his graphics settings you are going to recompile your whole game with different compile-time constants?Quote:Original post by overeasywhy is c++ such mess for online documentation? compared to java? and visual studio 2010 can't refactor anything? what the hell. and i've noticed that some people defend c++'s short comings as more "hands on". sure, some of it is, and the object management is less sloppy than in java, but the header guards, macros... GRR/complainingJava is a language backed by a company, of course they are going to set up some sort of documentation on their website to market their language.C++ is a free language.As to why C++ code is harder to refactor: Buy VAX if you really need it, otherwise it's because C++ is a much more complicated language to parse than Java.   ;Quote:Original post by overeasythe variables are for graphics settings, such as screen mode.Then only the classes that actually interact with the screen should need them. Please keep in mind the Single Responsibility Principle.But please do be more detailed - what kind of settings? Do the values need to change over time? If so, why?Quote:why is c++ such mess for online documentation? compared to java?Because C++ is not the intellectual property of a single company, the way Java is owned by Sun (excuse me, Oracle).Also, because it is a much older language. (By the way, Java is actually even newer than Python, technically ;) )Quote:and visual studio 2010 can't refactor anything?Again, it's a much older language and has developed over time keeping many peoples' interests in mind. In particular, many things have been done to make it as backwards-compatible as possible with C. The result is that the language grammar is quite complicated. A given expression can mean wildly different things in different contexts, and there are annoying complications (like the fact that things will be interpreted as function definitions if at all possible). This makes it very hard to write any kind of rules for refactoring C++ code that are actually safe.Quote:what the hell. and i've noticed that some people defend c++'s short comings as more "hands on". sure, some of it is, and the object management is less sloppy than in java, but the header guards, macros...Horses for courses. If you don't need to be "hands on", then don't be. Yes, C++ could be much prettier and still offer the low-level access that it does. But it's what we're stuck with.But do keep in mind that you can find much higher-level languages than Java, too. And you might also consider looking at C#, for example (which is about the same "level" and is in the same family of syntax, but makes a lot of different design decisions).Quote:Original post by pablo24C++ is a free language."Free" in some senses, but not really either gratis (even if everyone thinks they know the language... you will have to pay for a non-draft copy of the Standard) or libre (you can use the language if you're nobody, but good luck contributing to its evolution if you're not already on the Standards Committee).   