Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Jul 2014 21:21:49 +0200
From:      Pietro Cerutti <gahr@FreeBSD.org>
To:        John Baldwin <jhb@freebsd.org>
Cc:        Ed Schouten <ed@80386.nl>, src-committers@freebsd.org, Ian Lepore <ian@freebsd.org>, svn-src-all@freebsd.org, David Chisnall <theraven@freebsd.org>, svn-src-head@freebsd.org
Subject:   Re: svn commit: r268491 - head/usr.bin/users
Message-ID:  <20140715192149.GR1812@ptrcrt.ch>
In-Reply-To: <201407111726.14347.jhb@freebsd.org>
References:  <201407101215.s6ACF3v1055260@svn.freebsd.org> <201407111003.57785.jhb@freebsd.org> <12328E44-58A8-4334-A7F4-C7F29C9F6D0E@FreeBSD.org> <201407111726.14347.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--15k5Fuw+yLfT1d9X
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2014-Jul-10, 11:27, John Baldwin wrote:
> I would also prefer avoiding 'using namespace' when possible, especially
> for a short program.

On 2014-Jul-11, 17:26, John Baldwin wrote:
> I suppose it would be fine to permit it in small utilities and only in .cc
> files but not otherwise?

I'm confused.

On 2014-Jul-11, 10:03, John Baldwin wrote:

> http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-con=
sidered-bad-practice
>=20
> is a decent start on the multitude of reasons to avoid using it.

I have read the article. The "multitude of reasons" actually boils down
to one single potential problem: namespace pollution.

I agree that this might lead to having sneaky problems which are hard to
debug and so on, but the point remains that namespace pollution is the
only potential problem of "using" declarations.

There's an answer to that SO article that starts with:

"Experienced programmers use whatever solves their problems and avoid
whatever creates new problems."

And I really think that this is the bottom line. Like any feature,
"using" declarations can be good or bad, depending how one uses them.

In this particular case, I have a tiny c++ program and I decided to pull
in the std namespace because:

- it's not going to bother anybody else (read: consumers of my code)
- it improves code readability by avoiding std:: all over the place

Bottom line: I'd agree to a rule to avoid using directive and
declarations in header files, but please don't stigmatize "using" as an
intrinsically bad thing.

p.s. Same has been done to "goto" for decades, and we all know there are
very good cases - although limited in number of occurrences throughout
the average code - where goto is the right thing.

--=20
Pietro Cerutti
The FreeBSD Project
gahr@FreeBSD.org

PGP Public Key:
http://gahr.ch/pgp

--15k5Fuw+yLfT1d9X
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQJ8BAEBCgBmBQJTxX9NXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w
ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXREQTZERTEwNkE1Qjg1NEI4NUREODZENDlB
REQwRDM4RUExOTIwODlFAAoJEK3Q046hkgie3mYP/Rx9HrqAs48Cf9+gqchq+YWL
Iuq8c69WldsvP5ZhhRodFJ/lTi1hc4mUkPKKFh9oYsy2/CQbFG1nIWGhQ3d9cuSr
Zqz351DmpKw7ikMDh8yMDOlb4gA5/VyHlk4XjTvRUDWky9SLmGx/HWuN/rHE3KLw
ygLT1LIaUjNc/oOOgYsOWpKeVwwd09WszPB+9abEiWIWxjB5q0nnLIKks190mbed
prjOsDM35T2Qv5E+U6MNwWjHhVx45deNM+i4Z/gJfLWWX+9gYF+tS+TmYUEu/5RD
P9i1p4VY9UVM43vfWfh3pRTP6gXgg5KhIrQLTmKWD7mhW/wKuPfIvSEEUxjLiCw/
3jvPJQR7AfTlmQ0F9GkCZnCHv/bmjrbl2X55nPuGx5OJAjymFDG+e7HW5Qf1kJ+g
kwSKktH0I7gtw0EFQCdOOkPzGT33OOlJaOdfNkexC72kDUXJU0Qwr4xkyUQ8qipK
YSWx3fJw5dHpo8piKHWkiqqQAL8qnAgX+9h+uUelIs2Dj+z/tF+TTe8Ueb5QfjFQ
9X3LX05aY4s9dc1a82DFZuLVnXdQTeAupJqzi0tAwEAKIpHNfGCGBlliQIeKK24w
2Fyhlw+WPfGziqTDRzgKAYNFN6mf5fSHKQEOwGT1V6IfHCoX8Pp2mQgzKqaI9YgX
Ejl73FMPie4dlDMY15HR
=UuEE
-----END PGP SIGNATURE-----

--15k5Fuw+yLfT1d9X--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140715192149.GR1812>