Date: Thu, 10 Jul 2014 17:23:53 +0200 From: Pietro Cerutti <gahr@FreeBSD.org> To: Ed Schouten <ed@80386.nl> Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r268491 - head/usr.bin/users Message-ID: <20140710152353.GF1812@ptrcrt.ch> In-Reply-To: <CAJOYFBCQjjN7ep12zivnmFjfeeP1SeoYa963mQbMJr9DD%2BfUnw@mail.gmail.com> References: <201407101215.s6ACF3v1055260@svn.freebsd.org> <CAJOYFBCQjjN7ep12zivnmFjfeeP1SeoYa963mQbMJr9DD%2BfUnw@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--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 <gahr@freebsd.org> 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 <bsd.prog.mk> >=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<const volatile char&>(__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<string>::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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140710152353.GF1812>