Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

126 Neutral

About codingPractices

  • Rank

Personal Information

  • Interests
  1. codingPractices

    How to use namespaces in structuring a project

    OK, so this is what I've decided to do. For personal projects, I shall never use namespaces and when I do have two classes having functions all with the same names, I'll either put that in a namespace or just use Python to glue different modules written in C++ together by using "import module_with_same_name as new _name_for_module" Anything particularly wrong with what I've thought of for now?
  2. codingPractices

    How to use namespaces in structuring a project

    Euhm, I think no.   Putting everything in a single name space, is just like having everything at the global name space, except you write "namespace Foo { ... };" around all code (the syntax may be wrong, but I hope it's clear wrapping a name space around all code isn't doing much). It does avoid name clashes with the now-empty global name space though :)   Instead, don't consider code to be static. You should use a name space for a well-defined part, such as a library that is being used at several places. However, don't do that until it actually is a library. That takes work. Just taking "random" existing code, and declaring "this is a library now" is unlikely to give a nice result. In general, you want to make a clean separation between library code and non-library code, a clean API, generalize some functions, make it complete, unify how you talk to the library in naming of parameters and function names. You want to document the functions, or how one is supposed to use the library. Treat the library as a new entity that has no direct link with how the old code was used before. (A good library should be generally usable, not exactly once in a specific project.)   After having done that, the library code is a proper library, a separate piece of code (with its own name space). Your project now has a lot of duplicated functionality. Fix the project. take out all the duplications, and modify it to talk to the new library, just like you do when you add an external library to your project. (During the cleanup operation, you changed the API slightly, so usually some adaption is required.) Thanks everyone! You all are really helpful! So basically: 1. for my own projects (other than libraries), never use namespaces unless I think I need to (which is when exactly?) 2. Use namespaces only when publicly distributing the code by putting the whole project in a namespace and then for classes?
  3. codingPractices

    How to use namespaces in structuring a project

    So when working with others there will be guidelines so I don't need to worry about it. And in my own projects, let's say I have code that may or may not have code that will be reused elsewhere out even turned into a public library, I should just put the whole project under one namespace but never for anything else such as classes etc?
  4. I know that namespaces are useful to avoid naming conflicts. Like if a user is including three "Biology" projects in their project, then it wouldn't be simple to access specific functions in a certain "Biology" project. However, I don't know how to structure namespaces throughout my project. Should I put the entire project under one namespace and that's it? Hope exactly would I use namespaces throughout classes etc?
  5. codingPractices

    How to structure a codebase

      Thank you! This is the answer I was looking for!
  6. codingPractices

    How to structure a codebase

    OK, so there are three things I'm considering now after learning all this: 1. Whenever I make a function, class etc. I put it in the codebase and then in the project I include that file from the codebase. 2. I make all the functions etc. into libraries and include those in whatever projects I need to use them in. 3. I keep all the namespaces, functions, classes etc. in their original project folders and when I need to use a function, class etc. from another project I just include that.   Or a fourth option...
  7. codingPractices

    How to structure a codebase

    To clarify, I use Gedit and g++ with Terminal (basically I don't use an IDE)     So do I keep all the code the same and then just change the command from Terminal or?       Using g++, how would I do this?
  8. codingPractices

    How to structure a codebase

    main.cpp  #include "/home/neel/MEGA/Code/Test/OtherProject/MyClass.h" #include <iostream> using namespace std; int main(){ cout << "come on\n"; MyClass myClassObject; myClassObject.myFunction(); } It includes the file but when I instantiate it it says "undefined reference to MyClass::myFunction()"   Here's the header and source file included in a different folder:   MyClass.h #ifndef MYCLASS_H #define MYCLASS_H class MyClass{ public: void myFunction(); }; #endif MyClass.cpp #include "MyClass.h" #include <iostream> using namespace std; void MyClass::myFunction(){ cout << "hello bob\n"; }
  9. codingPractices

    How to structure a codebase

    1. So when I call the class from another directory it would still be packaged automatically despite the code being somewhere else? 2. How exactly would I tell in "main.cpp" that it's a lbrary?
  10. I currently have a folder "C++" and within it a bunch of projects. It looks a little like this (obviously I haven't named them Project1 etc.):     C++         Project1         Project2         Project3 Now this used to work fine up until I started having the need to use a class that I made from another project. I thought of copy-pasting the class but this wouldn't work as if I updated the original class, the copied ones wouldn't be updated. Also, I'd have to guess in which project I made the class in. Then I thought of calling it from the other project itself but then if I were to package the project it wouldn't work as it wouldn't include the classes from external folders (at per my knowledge). The only other thing I can think of is within my "C++" folder I have a folder named something like "Codebase", where I store all the classes and the like, and another folder called "Projects" or something and keep "Project1", "Project2" etc. in there and call the classes from the codebase (thus solving the problem where I can't find where a specific class I made is). However, again, I don't know packaging the final product would work. How do you, or professionals, people on GitHub etc. do it?
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!