Welcome Guest ( Log In | Register )

Bump Topic Topic Closed RSS Feed

Outline · [ Standard ] · Linear+

C++ C++ using namespace std, a bad practice?

views
     
TSAzusa_San
post Jul 22 2015, 07:47 PM, updated 9y ago

Getting Started
**
Junior Member
267 posts

Joined: Mar 2015
for c++, is "using namespace std" in global consider bad practice? then why university lecturer still teach in this way? sweat.gif

http://stackoverflow.com/questions/1452721...ed-bad-practice

CODE

#include <iostream>
using namespace std;

int main()
{

return 0;
}


This post has been edited by Azusa_San: Jul 22 2015, 07:47 PM
kurokami98
post Jul 22 2015, 08:38 PM

New Member
*
Junior Member
30 posts

Joined: Oct 2014


Depend on how you use it
wKkaY
post Jul 23 2015, 01:59 AM

misutā supākoru
Group Icon
VIP
6,008 posts

Joined: Jan 2003
I don't know why your lecturer taught it that way, but if you feel that it's wrong why don't you bring it up to him? Go build up your assertive communication skills smile.gif
CyrusWong
post Jul 23 2015, 02:03 AM

Regular
******
Senior Member
1,626 posts

Joined: Apr 2013
i currently studying degree in software engineering, 2nd year student, mmu.

my foundation and 1st year degree, all lecturer teaching "using namespace std;" for c++

lol....

is it really a bad practice? lol... maybe becoz lecturer knowledge outdated xD? who know
TheSolver
post Jul 23 2015, 09:32 AM

Regular
******
Senior Member
1,108 posts

Joined: Jun 2011
It never ends. The university teaches you to fish not to eat fish.

In general if you don't use any third party libraries, using 'using namespace std;' is safe. Next somebody will complain why not
CODE
#include <iostream>
main()
{
}

because function/variable declarations/definitions return an int by default. You'll certainly get non error return values half of the time because of the garbage value in the lower half of certain register returned.

But not "void main(){...}" of course without certain OS sandbox safeguard.
hafizhans
post Jul 23 2015, 09:37 AM

haa..ahnn..ahnn..aduii
******
Senior Member
1,484 posts

Joined: Feb 2012


QUOTE(CyrusWong @ Jul 23 2015, 02:03 AM)
i currently studying degree in software engineering, 2nd year student, mmu.

my foundation and 1st year degree, all lecturer teaching "using namespace std;" for c++

lol....

is it really a bad practice? lol... maybe becoz lecturer knowledge outdated xD? who know
*
3 years i learnt c++ in UTM,
all lecturers oso use "using namespace std;"
blackstar88
post Jul 23 2015, 10:54 AM

Casual
***
Junior Member
424 posts

Joined: Apr 2013
it is not a bad practice or whatsoever...
using namespace std just makes your coding easier so that everytime you cin and cout no nid type "std" again and again.

it is a mess if you have to write the namespace everytime.
Point Ex
post Jul 23 2015, 12:26 PM

Getting Started
**
Junior Member
69 posts

Joined: Feb 2005



Thanks for giving a damn about good practices. Most don't even indent.

For learners and small projects, this is fine. Less typing, with the added benefit of learning about namespaces! Don't worry about it.

As soon as you start importing libraries into your codes, then you should start giving namespaces more attention. Read the Stack Overflow page you linked thoroughly.
TSAzusa_San
post Jul 23 2015, 05:10 PM

Getting Started
**
Junior Member
267 posts

Joined: Mar 2015
thanks for all reply. smile.gif

Topic ClosedOptions
 

Change to:
| Lo-Fi Version
0.0123sec    0.56    5 queries    GZIP Disabled
Time is now: 29th March 2024 - 10:20 AM