Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #13285

Re: " *first = new string(*rhs.first);" cannot compile in MSVC

From drew@furrfu.invalid (Drew Lawson)
Newsgroups comp.lang.c++
Subject Re: " *first = new string(*rhs.first);" cannot compile in MSVC
Date 2012-01-12 14:50 +0000
Organization Center for Unverified Assertions
Message-ID <jemrvh$179k$1@raid.furrfu.com> (permalink)
References <d29fdc08-5a93-47d6-a716-926803e54b36@k28g2000yqc.googlegroups.com> <9n77vbFvfbU4@mid.individual.net> <jem0qh$mo6$1@speranza.aioe.org> <4f0e95db$0$4356$7b1e8fa0@news.nbl.fi>

Show all headers | View raw


In article <4f0e95db$0$4356$7b1e8fa0@news.nbl.fi>
	Juha Nieminen <nospam@thanks.invalid> writes:
>BCFD36 <bcfd36@cruzio.com> wrote:
>> On 1/11/12 9:04 PM, Ian Collins wrote:
>>> On 01/12/12 04:29 PM, fl wrote:
>> [stuff deleted
>> 
>>>> #define PERSON_H
>>>>
>>>> #include<string>
>>>>
>>>> using namespace std;
>>>
>>> Don't ever put this in a header!
>>>
>> 
>> It would be very helpful to the self stated rookie if you stated WHY 
>> this should not be done
>
>  One interesting question is where do newbies learn the magic line
>"using namespace std;" from? Obviously they do not come up with it on
>their own. They have to be *taught* it. Not only do they have to see it,
>it must be so prominently used that they will start using it as a matter
>of fact, without even thinking about it.
>
>  Who teaches newbies to use that dreadful line? Mostly pros who should
>know better! They write books, they write online tutorials, they write
>example code, all of which is used by newbies to learn the language.
>Why are they doing this? They know better, yet they still do it.

I'm not defending, but I think I know why they do it.

Namespace tags visually clutter up the code.  Once you are used to
it, it is clutter that is easily filtered when reading code.  But
beginners, reading a book, aren't used to it.  The code examples
are (on at least one metric) clearer without std:: all over the
place.

>  The reason why that line should be avoided should become clear when
>one thinks about it a bit: What is the purpose of namespaces?

Rookies have no idea that namespaces even exist, so *they* can't
think about it and have it clear.

Rookies need to learn about namespaces.  But it is understandable
that many authors don't want to start with them.  Their customers
want to "write some code" as soon as possible.  Namespaces seem
like esoteric stuff.


There is another reason that some code has these.

When I started with C++, all of the std:: stuff was in the global
space under the version of gcc I was using.  When I went back several
compiler versions later and tried to rebuild my stuff, I got nothing
but errors.  For the small stuff, and the obsessive moods, I fixed
all the usage.  But I think there were a couple places I put in
"using" so I could get on with my day.


>Why are
>all the standard functions and types inside a namespace? (If it still
>doesn't ring a bell, then: What happens when two types or functions have
>the same name and parameters?)
>
>  In fact, "using namespace std;" and then avoiding the "std::" prefix
>actually makes the code less readable. No longer can you spot usages of
>the standard libraries with a quick visual glance and, more importantly,
>usages of the more obscure standard library names becomes confusing
>(because there's no visual way of distinguishing where that name is
>coming from).

Ages ago I decided that "with" in Pascal was an evil, inviting code
to be misunderstood.  I view "using namespace" the same way.


-- 
|Drew Lawson            | If you're not part of the solution |
|                       | you're part of the precipitate.    |

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

" *first = new string(*rhs.first);" cannot compile in MSVC fl <rxjwg98@gmail.com> - 2012-01-11 18:22 -0800
  Re: " *first = new string(*rhs.first);" cannot compile in MSVC Ian Collins <ian-news@hotmail.com> - 2012-01-12 15:31 +1300
    Re: " *first = new string(*rhs.first);" cannot compile in MSVC fl <rxjwg98@gmail.com> - 2012-01-11 19:29 -0800
      Re: " *first = new string(*rhs.first);" cannot compile in MSVC "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-01-12 04:42 +0100
      Re: " *first = new string(*rhs.first);" cannot compile in MSVC Ian Collins <ian-news@hotmail.com> - 2012-01-12 18:04 +1300
        Re: " *first = new string(*rhs.first);" cannot compile in MSVC BCFD36 <bcfd36@cruzio.com> - 2012-01-11 23:07 -0800
          Re: " *first = new string(*rhs.first);" cannot compile in MSVC Juha Nieminen <nospam@thanks.invalid> - 2012-01-12 08:12 +0000
            Re: " *first = new string(*rhs.first);" cannot compile in MSVC "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-01-12 09:50 +0100
              Re: " *first = new string(*rhs.first);" cannot compile in MSVC Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 12:36 +0000
                Re: " *first = new string(*rhs.first);" cannot compile in MSVC "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-01-12 14:12 +0100
                Re: " *first = new string(*rhs.first);" cannot compile in MSVC Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 13:36 +0000
                Re: " *first = new string(*rhs.first);" cannot compile in MSVC Juha Nieminen <nospam@thanks.invalid> - 2012-01-12 14:41 +0000
            Re: " *first = new string(*rhs.first);" cannot compile in MSVC drew@furrfu.invalid (Drew Lawson) - 2012-01-12 14:50 +0000
  Re: " *first = new string(*rhs.first);" cannot compile in MSVC Goran <goran.pusic@gmail.com> - 2012-01-11 23:12 -0800

csiph-web