Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 30th, 2005, 3:16 PM   #11
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
Quote:
Originally Posted by darkone916
Does it have any side effects using "using namespace std; ?
Not "side effects" ... but if you were going to write a program that used mostly items from a different namespace, then it would not be worth it. So, basically, it is usual to use that line for any ANSI-C++ compliant code.
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2
skuinders is offline   Reply With Quote
Old Jul 30th, 2005, 3:19 PM   #12
darkone916
Hobbyist Programmer
 
darkone916's Avatar
 
Join Date: Jul 2005
Location: Oman
Posts: 125
Rep Power: 4 darkone916 is on a distinguished road
Send a message via MSN to darkone916
not worth it in wat ways??
__________________
From the bottom of the stone steps...
...i'm calling still.
darkone916 is offline   Reply With Quote
Old Jul 30th, 2005, 3:31 PM   #13
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Quote:
Originally Posted by darkone916
not worth it in wat ways??
consider this:
#include <iostream>
int main()
{
    sdt::cout<<"Hello World!\n";
    return 0;
}

now you can get rid of std by using namespace std but is it worth it in this case to add a full line of code to get rid of three letters?
OpenLoop is offline   Reply With Quote
Old Jul 30th, 2005, 3:34 PM   #14
darkone916
Hobbyist Programmer
 
darkone916's Avatar
 
Join Date: Jul 2005
Location: Oman
Posts: 125
Rep Power: 4 darkone916 is on a distinguished road
Send a message via MSN to darkone916
Ok i get it now... :p

thanx guys
__________________
From the bottom of the stone steps...
...i'm calling still.
darkone916 is offline   Reply With Quote
Old Jul 31st, 2005, 1:03 PM   #15
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Quote:
Not "side effects" ...
*sighs*
It's silly that every single tutorial feeds you the use of "using namespace std;" as the norm thing to do. It clogs up the global namespace. You definitely don't know the name of every single function/class/typedef the standard library provides you with. You'll no doubt get name conflicts with variable names, function names, etc. At least with the "using std::cout" syntax you know precisely what you're including into the global namespace.
Cerulean is offline   Reply With Quote
Old Jul 31st, 2005, 1:29 PM   #16
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Quote:
Originally Posted by Cerulean
You'll no doubt get name conflicts with variable names, function names, etc.
Functions and variables defined in a local scope has priority over variables defined in namespace/global scope. I've been using "using namespace std;" for 2+ years and never ran into the problem you're describing (it sure saved me some keystrokes though).
It is really a matter of personal choice IMO.
OpenLoop is offline   Reply With Quote
Old Jul 31st, 2005, 2:10 PM   #17
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 600
Rep Power: 4 Ancient Dragon is on a distinguished road
I'v never had a problem with "usng namespace std" either. Who cares that it causes the compiler to do extra stuff? use precompiled headers and you will never even notice the compile-time difference.
Ancient Dragon is offline   Reply With Quote
Old Jul 31st, 2005, 2:27 PM   #18
darkone916
Hobbyist Programmer
 
darkone916's Avatar
 
Join Date: Jul 2005
Location: Oman
Posts: 125
Rep Power: 4 darkone916 is on a distinguished road
Send a message via MSN to darkone916
I think i will start using "using namspace std;" from today.
__________________
From the bottom of the stone steps...
...i'm calling still.
darkone916 is offline   Reply With Quote
Old Jul 31st, 2005, 5:10 PM   #19
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Quote:
I've been using "using namespace std;" for 2+ years and never ran into the problem you're describing (it sure saved me some keystrokes though).
That's good to know. I sure hope it doesn't turn around and bite you like it had a fair few times when I first started working on large projects.
Sure, it's personal choice, just like shooting yourself in the foot is a personal choice. The bad things is that to the uninformed this "personal choice" of yours is being passed of as the Right Thing To Do (tm). Hence me now recommending you Google and see what other programmers recommend. You'll see that in the vast majority of cases, their personal choice concurs with mine.

My £0.02.
Cerulean is offline   Reply With Quote
Old Jul 31st, 2005, 6:28 PM   #20
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Cerulean, you actually scanned all the 245,000 google results for using namespace std and determined that
Quote:
Originally Posted by Cerulean
... the vast majority of cases, their personal choice concurs with mine.
I doubt it. But if you want, post a poll about it in programmingforums.org and let's see what other programmers have to say.

I'll continue "using namespace std;", not because you don't like it, but because you don't have any hard evidence as about how "DANGEROUS" it can be. Clearly the naming is not a problem, also functions can be identified by their arguments if the names are the same.

Now I know you will not be using namespace std, but just to save you the trouble of typing std:: before every cout and cin call, try "using std::cin" and "using std::cout".
OpenLoop is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:11 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC