From: Martin York on
On Mar 28, 9:43 am, german diago <germandi...(a)gmail.com> wrote:
> Hello. I'd like to propose a small grammar addition for inclusion in c+
> +0x. It's quite simple, and I wonder why this isn't allowed in the
> current language. Example.
>
> using namespace std;
> using namespace boost;
> using namespace mylib;
> using namespace anotherlibr;
>
> using lib2::variable1;
> using lib2::variable2;
> using lib2::variable3;
> using lib3::variable4;
>
> Why not?
>
> using namespace std, boost, mylib, anotherlibr;
> using lib2::variable, lib2::variable2, lib2::variable3,
> lib3::variable4;
>
> It's more compact. Just that. I see no reason not to extend the
> grammar to allow this.



Its' already supported.

try:
#include <iostream>

using std::cout; // Global.
int main()
{
using std::cin; // Local to this scope only
cout << "Hit any key to continue\n";

char val;
cin >> val;
}

void plop()
{
int x;
std::cin >> x; // need to use std:: here because
// the previous using has only local scope.
}

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Francis Glassborow on
german diago wrote:
> Hello. I'd like to propose a small grammar addition for inclusion in c+
> +0x. It's quite simple, and I wonder why this isn't allowed in the
> current language. Example.
>
> using namespace std;
> using namespace boost;
> using namespace mylib;
> using namespace anotherlibr;
>
> using lib2::variable1;
> using lib2::variable2;
> using lib2::variable3;
> using lib3::variable4;
>
> Why not?
>
> using namespace std, boost, mylib, anotherlibr;
> using lib2::variable, lib2::variable2, lib2::variable3,
> lib3::variable4;
>
> It's more compact. Just that. I see no reason not to extend the
> grammar to allow this.

We have considered that more than once and decided that we did not want
to provide it. Good programming practice is to allow only one
declaration per statement. Legacy prevents us from doing that with
declarations of variables etc. but we saw no reason to extend yhat to
multiple namespace declarations/directives.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: d04rp on
> Hello. I'd like to propose a small grammar addition for inclusion in c+
> +0x. It's quite simple, and I wonder why this isn't allowed in the
> current language. Example.
>
> using namespace std;
> using namespace boost;
> using namespace mylib;
> using namespace anotherlibr;
>
> using lib2::variable1;
> using lib2::variable2;
> using lib2::variable3;
> using lib3::variable4;
>
> Why not?

Ofcourse this _could_ be added. But is it really necessary? It's
nothing more than syntactic sugar. Also its like declaring variables
like this:

int value1, value2, value3;
Widget w1, w2, w3;

And I'm not recommending you to declare your variables like that. It's
more "maintenance friendly" to declare them like this:
int value1;
int value2;
int value3;

Widget w1;
Widget w2;
Widget w3;

HTH.
Roger Schildmeijer

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Ni on

> And shorter code is always
> more readable.

It is not a true.

as for me

if ( a = getA() > b = getB() && i++ > count )

it is not a good line of code, but short.

The advantage of per line records is you can comment out one fast and
independently.



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Gerhard Menzl on
german diago wrote:

> On 29 mar, 22:43, d0...(a)student.lth.se wrote:
>> And I'm not recommending you to declare your variables like that. It's
>> more "maintenance friendly" to declare them like this:
>> int value1;
>> int value2;
>> int value3;
>>
>> Widget w1;
>> Widget w2;
>> Widget w3;
>
>
> I don't think that's much more mantainable than the shorter
> declarations. You could get confused with
> int * a, b;
> Which means a is int * but b is just int. I don't think that's an
> argument for what you explained.

Restricting code to one declaration per line is both more readable and
maintainable.

It is more readable because it doesn't force you to filter out all the
intervening identifiers when you want to look up the type of a single
variable. There is a reason why in ordinary text important items are
listed on separate lines, often supported by bullets or numbers. If
fewer lines meant more readability, newspapers would have landscape
format and no columns.

It is more maintainable because it is much easier to add, move, or
delete lines than parts of lines.

--
Gerhard Menzl

Non-spammers may respond to my email address, which is composed of my
full name, separated by a dot, followed by at, followed by "fwz",
followed by a dot, followed by "aero".



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]