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


Groups > comp.programming > #6074

Re: Here is why C++ and C are bad...

From Kaz Kylheku <kaz@kylheku.com>
Newsgroups comp.programming
Subject Re: Here is why C++ and C are bad...
Date 2015-12-29 21:20 +0000
Organization Aioe.org NNTP Server
Message-ID <20151229131302.548@kylheku.com> (permalink)
References <n5kdn4$cji$1@dont-email.me> <n5uqdd$gin$1@dont-email.me>

Show all headers | View raw


On 2015-12-29, Richard Heathfield <rjh@cpax.org.uk> wrote:
> On 26/12/15 00:54, Ramine wrote:
>>
>> Hello,
>>
>> I was working on a project in C++, but i have encountered
>> a problem with the language that we call C++, this problem
>> is inherent to C++ and C, here is a small example that
>> shows the problem:
>>
>> ===
>>
>> #include <iostream>
>> using namespace std;
>
> This is a very bad idea. The *whole point* of namespaces is to avoid 
> name clashes. What you should do (and indeed what you *do* do) is to use 
> the std:: prefix for symbols that you pull in from the std namespace. So 
> you don't need using namespace std at all! Just remove it.

Indeed, "using namespace std" means "bring into my namespace here
all symbols in std, current and future, vendor-specific and standard".

It's a transition mechanism for programmers who want namespaces to
go away and deal with clashes, or who want to do a quick and dirty
port of pre-namespace C++ code to namespaces.

Of course, the "using namespace" mechanism is perfectly useful, if namespaces
are sanely designed by someone who pins down the exact contents. For instance:

  namespace foo_api {
    // everything

    int a, b, c, d, e;
    void f(), g(), h();

    // Only a and f existed in the 1.0 API
    namespace v1_0 {
      using foo_api::a;
      using foo_api::f;
    }

    // 2.0 has all of 1.0 plus c, and g.
    namespace v2_0 {
      using namespace foo_api::v1_0;
      using foo_api::c;
      using foo_api::g;
    }

    // 3.0 has everything.
    // (In the future it won't!)
    namespace v3_0 {
      using namespace foo_api;
    }
  }

Now you can do "using namespace foo_api::v1_0" with the confidence
that you're getting an exact, documented set of identifier which shall
never change.

Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Here is why C++ and C are bad... Richard Heathfield <rjh@cpax.org.uk> - 2015-12-29 20:31 +0000
  Re: Here is why C++ and C are bad... Kaz Kylheku <kaz@kylheku.com> - 2015-12-29 21:20 +0000
  Re: Here is why C++ and C are bad... David Brown <david.brown@hesbynett.no> - 2015-12-29 23:13 +0100
    Re: Here is why C++ and C are bad... Richard Heathfield <rjh@cpax.org.uk> - 2015-12-29 22:19 +0000
      Re: Here is why C++ and C are bad... David Brown <david.brown@hesbynett.no> - 2015-12-30 09:56 +0100
        Re: Here is why C++ and C are bad... Richard Heathfield <rjh@cpax.org.uk> - 2015-12-30 13:28 +0000
          Re: Here is why C++ and C are bad... David Brown <david.brown@hesbynett.no> - 2015-12-30 14:55 +0100
            Re: Here is why C++ and C are bad... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-12-30 16:32 +0000
              Re: Here is why C++ and C are bad... David Brown <david.brown@hesbynett.no> - 2015-12-30 18:17 +0100
                Re: Here is why C++ and C are bad... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-12-30 20:01 +0000
          Re: Here is why C++ and C are bad... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-12-30 15:48 +0000
            Re: Here is why C++ and C are bad... Richard Heathfield <rjh@cpax.org.uk> - 2015-12-30 16:35 +0000
              Re: Here is why C++ and C are bad... David Brown <david.brown@hesbynett.no> - 2015-12-30 18:19 +0100
                Re: Here is why C++ and C are bad... Richard Heathfield <rjh@cpax.org.uk> - 2015-12-30 17:39 +0000
                Re: Here is why C++ and C are bad... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-12-30 20:26 +0000
              Re: Here is why C++ and C are bad... "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2015-12-30 18:32 +0100
              Re: Here is why C++ and C are bad... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-12-30 19:55 +0000
                Re: Here is why C++ and C are bad... Richard Heathfield <rjh@cpax.org.uk> - 2015-12-30 20:15 +0000
                Re: Here is why C++ and C are bad... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-12-30 22:00 +0000
      Re: Here is why C++ and C are bad... Ian Collins <ian-news@hotmail.com> - 2015-12-31 10:16 +1300

csiph-web