From owner-svn-src-all@FreeBSD.ORG Thu Jul 10 15:23:59 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from ptrcrt.ch (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id ADC53F8; Thu, 10 Jul 2014 15:23:57 +0000 (UTC) Date: Thu, 10 Jul 2014 17:23:53 +0200 From: Pietro Cerutti To: Ed Schouten Subject: Re: svn commit: r268491 - head/usr.bin/users Message-ID: <20140710152353.GF1812@ptrcrt.ch> Reply-To: gahr@FreeBSD.org References: <201407101215.s6ACF3v1055260@svn.freebsd.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="L2Brqb15TUChFOBK" Content-Disposition: inline In-Reply-To: X-PGP-Key: fp="DA6D E106 A5B8 54B8 5DD8 6D49 ADD0 D38E A192 089E"; id="0xA192089E"; get=; get=; User-Agent: Mutt/1.5.23 (2014-03-12) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jul 2014 15:23:59 -0000 --L2Brqb15TUChFOBK Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2014-Jul-10, 17:04, Ed Schouten wrote: > Hi there, >=20 > On 10 July 2014 14:15, Pietro Cerutti wrote: > > Reimplements users(1) in C++. > > > > This reduces the lines of code by roughly 50% (not counting the COPYR= IGHT > > header) and makes it more readable by using standard algorithms. >=20 > Interesting. More C++ in our base system. :-) >=20 > > Modified: head/usr.einnusers/Makefile > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > > --- head/usr.bin/users/Makefile Thu Jul 10 11:20:24 2014 (r26849= 0) > > +++ head/usr.bin/users/Makefile Thu Jul 10 12:15:02 2014 (r26849= 1) > > @@ -1,6 +1,7 @@ > > # @(#)Makefile 8.1 (Berkeley) 6/6/93 > > # $FreeBSD$ > > > > -PROG=3D users > > +WARNS=3D 3 > > +PROG_CXX=3D users > > > > .include >=20 > Why does this require WARNS to be set to 3? For brand new code, I > would have expected that it would just build with WARNS=3D6. It's because of the standard library. Examples: /usr/include/c++/v1/memory:1454:47: error: unused parameter '__a' [-Werror,-Wunused-parameter] static void construct(allocator_type& __a, _Tp* __p) /usr/include/c++/v1/__functional_base:85:12: error: cast from 'const volatile char *' to 'wchar_t *' increases required alignment from 1 to 4 [-Werror,-Wcast-align] return (_Tp*)&reinterpret_cast(__x); >=20 > > +using namespace std; >=20 > Out of curiosity, do we have any style guidelines w.r.t. C++? For > example, I would personally not use things like "using namespace std". > It becomes hard to figure out where symbols come from. I wouldn't use "using namespace" in header files to avoid ns pollution, but I think it makes the code clearer - by avoiding repeating std:: - in this case. >=20 > > + sort(begin(names), end(names)); > > + vector::iterator last(unique(begin(names), end(names))); >=20 > This could also just be a std::set, right? Yes, except std::set implements bidirection iterators instead of random access iterators. Bidirectional iterators do not support arithmetic with integers, which I need to get to the previous-to-last element in the very next line of code. >=20 > Even though I actually think C++ is a lot nicer than C, do we really > think it is actually worth proactively replacing already existent > tools? This specific tool has now become three times as big as the > previous version (7128 -> 23840 bytes). No, I'm not going to systematically replace everything with c++. The thing is, I had already begun to refactor a bit users(1), and this looked like the natural next step to me. Of course, here the trade off between code readability and object size shows. --=20 Pietro Cerutti The FreeBSD Project gahr@FreeBSD.org PGP Public Key: http://gahr.ch/pgp --L2Brqb15TUChFOBK Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQJ8BAEBCgBmBQJTvrAJXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXREQTZERTEwNkE1Qjg1NEI4NUREODZENDlB REQwRDM4RUExOTIwODlFAAoJEK3Q046hkgieRKYQAKxtcIuWvFVHBxmTBvkOkSma YMvefsA4b1uhWBvIXupwpTRRxqR+DajORwMP3kgU7d5biyQCFAiUxgVfUcFufrGm WAptZEFOXbI/8n7CSRE7FtPgyL+All0+UvGXKfcorco+BgaOiaIRn8Y0ogRLVt2u Bl+F2ZlpfA1hMphHugkHEGITEVOtB6k4AmBCOjWXzEs1rg+58ouRUKq5tinotvYE 9lSi1P7BmCJEPdJk4KmUnAfk0vsr7t+tq/yd2aOwCqqdAubmAENDguW4mP2HeJkz LH9HzCHWCggfJfRwSVQFUWNPAsf2ThACx78xV9aUURBLmqi8yj7PQo2UijPcTmZQ JJmEHIP4I3ajKUoEom2BihBWbk/d+CuAn9iIjWoX5O2nNfIrVyANCYAWjh7t/ss3 i8+C768OYYeW+zAqfKCpi4LoUrRsJRM7d3dIiCUdIgnNlXXPMvZJEeTUgcWjQb1e R8u1oWjN3iCA7s5qXtj1mg9k4TR/9dnq1jIF8DC5/rKTFwjKgcwM1hq2I64MWWQK xpGBEI5wQq///+NQiSz/JZBUwmCQCxIPoU+jZ1zxWu+hRlpeGtGUP2/tUVpxIfsR O+dAqoQmWlhS9GziFftepI0xyct4pHN6fT8QFekEB9wPskYp6zbpbyrEOhW5up1Q fgmUam7/A5Rj2er5o0Ic =ZXAm -----END PGP SIGNATURE----- --L2Brqb15TUChFOBK--