1, 3, 4, 12: The CppCoreGuidelines link is very informative. It's answered many of my questions since yesterday. The funny thing is that I had already downloaded this from the repository but forgot about it, and never ended up reading through. Thank you very much.
2: That makes sense. If the standard library is throwing some sort of exception like out-of-memory or an out-of-bound access error, it makes sense to let the program crash instead of rethrowing the exception after handling it myself because there's almost really nothing the end user can do anyway.
5: Yep, makes sense.
6: Yeah, absolutely right. My bad, this is a stupid question now that I think about it.
7: My test program is not correctly, again, my bad. Your example is post #3 demonstrates more than enough to clear my doubt. Although, I have one other question. If I have a few nested namespaces like this:
Code:
// namespace one acts as the "global" namespace for namespace (like std)
namespace one {
namespace two { }
namespace three {
namespace four {
using namespace std;
}
}
namespace five {
// I'd like to use namespace four here, let's say. What's the best way to do this?
using namespace one::three::four; // Like this?
using namespace three::four; // Also works, right?
}
}
// If the end user does this:
using namespace one;
// std does not end up being brought in completely, right?
// If the end user does this:
using namespace one::three;
// std does not end up being brought in completely, right?
// If the end user does this:
using namespace one::three::four;
// std does end up being being brought in completely, right?
// If the end user does this:
using namespace one::five;
// std does end up being being brought in completely, right?
// This is what I tested after your post and before that I was doing terribly wrong at understanding namespaces (I'm ashamed of it lol)
// If I have quite a few namespaces that I'm working with, what can I do to make code more readable? Example code:
namespace library {
namespace type {
typedef int Lint;
}
namespace support {
namespace frontends { }
namespace backends { }
}
namespace implementation {
namespace base {
// I'd like to maybe use namespace std here but I don't want the end user to be impacted
// by it in anyway. If I use std here, I happen to make the code more readable.
class foo {
std::vector <library::type::Lint> a; // not readable - looks bad
std::vector <type::Lint> b; // still slightly bad
};
// better?
using namespace std;
using namespace library::type;
// implementations to make code readable...
// but like I found out, this is bad code if the user ends up using this namespace...
}
namespace interface {
// if the user is supposed to be using classes from this namespace for using the library,
// then they end up including the entire std namespace too because of the next line. But,
// this line helps me keep things readable. What's the best workaround for keeping code
// readable as well as not screw up with the end user?
using namespace library::implementation::base;
class foo_interface {
//...
};
}
}
}
10: And this is what didn't seem to cross my mind. Nice examples. I'm excited to know about how modules would work, sounds interesting and slightly Pythonic.
11: All configuration management like in c++config.h? And all the other configuration headers that might be existing that I do now know of.
13: Right, noted.
14: Cleared! Keep crap as less as you can with implementation/base classes and provide an interface to the end user using this minimal workable implementation class as long as everything is efficient.
Thank you laserlight! Great resource for C++ Programming