My first C++ project!!!!!!!!

Pages: 12
J4ke wrote:
And when I say well on your way, I mean you've just started. I've been programming for around 3 years and I'm still learning something new every day.

The day a C++ programmer says they have learned everything is the day arrogance has set in. I've been programming in C++ for 17 years and I still learn new things every day and even find that I have some poor habits I thought were normal methods (which they were back in the late 90s when I started, but have been changed in recent years).
closed account (Dy7SLyTq)

[EDIT]
Though, learncpp.com does something that I think is a little annoying and overkill.

#include <iostream>

class NAME{
using namespace std;
//....
};

void funct(...)
{
using namespace std;
//......
}

int main()
{
using namespace std;
// .......
return 0;
}

that should never be done. ever. there is nothing wrong with limiting the scope you want to bring in namespaces to, but that is very bad in fact down right pointless(except for learning about scope) it is always much better to just specify what you want to bring in
Last edited on
Your code is alright. I would say you have a basic understanding of C++. For all that you need it for, I think you're fine. If you havn't practiced the <math> functions though, I think you should, as you will find them helpful if you use programming as a means to create proofs (I did read an article in which mathmaticians were programming algorithms to prove theorums).
DTSCode wrote:
that should never be done. ever. there is nothing wrong with limiting the scope you want to bring in namespaces to, but that is very bad in fact down right pointless(except for learning about scope) it is always much better to just specify what you want to bring in

I completely agree. The only time I do using namespace std; is when I am trying to just do something real quick and don't really know what I'm going to use just yet. See, for me it is easier to doing using namespace std; and then going back and changing that one line to using std::cin; using std::cout; using std::vector; using std::string; instead of doing std:: in front of everything and then deciding to go back through to add the using and remove the std:: in the code. Don't get me wrong, if I'm doing my own library tests I do std:: and don't even think about doing using. Mainly do using for when I'm doing silly game tests to test an idea.
closed account (Dy7SLyTq)
yeah i mean ill use it every once in a while (using namespace std), like when i had to write a program that was going to escape new lines in a string. i threw it away right after like i knew i would. however, like with my compiler, i would never think of using that with the standard namespace, the boost one, or the sfml one if i need to use it
@DTSCode and BHXSpecter
using namespace declarations aren't bad practice, it's when they are placed in global scope that they become bad. I use them at function scope all the time, especially with boost which has a lot of nested namespaces.
closed account (Dy7SLyTq)
it brings in every thing and you might not neccesarily need it
Using it in function scope means you have to continually call it. For example, lets say (and this is a terrible example) you have three functions that use cout/cin. Then in main you have more cout/cin calls. So that means in all three functions you load everything from the std namespace at the start of each function and then again in main(). I would rather just load it all in the global namespace until I decide which ones I need and then go back and just use the ones I need.

When I code I don't sit there and say, "Okay I need vectors, strings, map, lists, etc." I simple do global using namespace std; and start coding. I make notes of what std objects I use and then after I get it done I go back and change using namespace std; to using std::<object>; for every object i have in my code. The only time I don't mess with using and stick to std::<object> is if I'm writing functions and such for library tests (which I don't do often lately as I suck at writing libraries).
BHXSpecter wrote:
Using it in function scope means you have to continually call it.
AFAIK there is no overhead so "calling" it in each function call shouldn't be an issue.

My point was that blindly saying using namespace is always bad and should never be used isn't completely correct.
naraku9333 wrote:
My point was that blindly saying using namespace is always bad and should never be used isn't completely correct.

Well I don't blindly say anything. I genuinely believe it is bad to use it. I feel it is bad due to the possible function/object clashes you could have between the standard and other libraries that may be made by programmers who decide to make functions that are similar named to the standard.
closed account (Dy7SLyTq)
well i guess there is one case: when you know youll be using everything in that namespace then it would probably be better, but even when i use boost, which you said you use it for, i never do using namespace.
I always think of Michael Dawson's comment about using. Makes me laugh, and though it was relevant (even though I don't agree with it).

Michael Dawson wrote:

A language purist would say you shouldn't employ either version of using and that you should always prefix each and every element from a namespace with its identifier. In my opinion, that's like calling your best friend by his first and last name all the time. It just seems a little too informal.
Topic archived. No new replies allowed.
Pages: 12