Date: Fri, 5 Dec 2008 10:30:05 +0100 From: Erik Trulsson <ertr1013@student.uu.se> To: Garrett Cooper <yanefbsd@gmail.com> Cc: FreeBSD Hackers <freebsd-hackers@freebsd.org>, Maksim Yevmenkin <maksim.yevmenkin@gmail.com> Subject: Re: RFC: small syscons and kbd patch Message-ID: <20081205093005.GA29478@owl.midgard.homeip.net> In-Reply-To: <7d6fde3d0812050050l57684eebkf14f252d78b68ec0@mail.gmail.com> References: <bb4a86c70812021701i621fdcfjb6a58a7f5cf781d5@mail.gmail.com> <7d6fde3d0812040324y3bf0901cy1f4a6d961362c314@mail.gmail.com> <bb4a86c70812040724w43ddec15yab72920d80d879d3@mail.gmail.com> <20081205072229.GE18652@hoeg.nl> <7d6fde3d0812050034y43a70ce8i49fbba92f9c8943b@mail.gmail.com> <7d6fde3d0812050035u6e3ea930o9e093830a8608444@mail.gmail.com> <20081205084441.GA29312@owl.midgard.homeip.net> <7d6fde3d0812050050l57684eebkf14f252d78b68ec0@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Dec 05, 2008 at 12:50:38AM -0800, Garrett Cooper wrote: > On Fri, Dec 5, 2008 at 12:44 AM, Erik Trulsson <ertr1013@student.uu.se> wrote: > > On Fri, Dec 05, 2008 at 12:35:31AM -0800, Garrett Cooper wrote: > >> On Thu, Dec 4, 2008 at 11:22 PM, Ed Schouten <ed@80386.nl> wrote: > >> > * Maksim Yevmenkin <maksim.yevmenkin@gmail.com> wrote: > >> >> the idea was to ensure that kbd->kb_locked variable only takes values > >> >> 0 (zero) and 1 (one). > >> > > >> > I often use constructs like these to do that: > >> > > >> > foo = bar ? 1 : 0; > >> > > >> > Maybe !!bar is a lot shorter to write, I think the line above is a lot > >> > easier to read. > >> > >> Indeed. I had no idea (and I would assume that many people wouldn't in > >> my similar level of systems programming) what in the work you were > >> trying to do above with that line. The one-line conditional is > >> universal in almost all major high-level language dialects I've hit, > >> minus Python and Tcl. > >> -Garrett > > > > The !!bar construction to map {0, not-0} to {0,1} is fairly common in C > > programming, and I would certainly expect any experienced C programmer to > > recognize it. > > (I feel like I'm getting off on a bikeshed topic, but...) > > 1. What dialect of C was it defined in? Is it still used in the > standard dialect (honestly, this is the first time I've ever seen it > before, but then again I am a younger generation user)? The '!!x' construct is well defined in all dialects of C as far as I know. It is after all just using the standard '!' logical negation operator twice in a fairly straight-forward manner. If you know what the '!' operator does it should not be too difficult to figure out what applying it twice would do, even if one has never seen it done that way before. > 2. Is it still taught in schools (I didn't learn it when I was taught > C)? If not in schools, what about the Richie text (it's sort of like > the defacto C programming standard book of course)? Since I did not learn C in a school I have no idea what is (or has been) taught in schools in that regard. As for K&R I must admit to never having read it. It is however one (of many) idiomatic constructions in C that I would not really expect to be explicitly taught in a class. It is rather something I would expect programmers to either come up with on their own or to encounter when reading other peoples programs. > 3. What's the real loss of going to `? :', beyond maybe 3 extra > keystrokes if it's easier for folks who may not be as experienced to > read? An inexperienced C programmer who do not understand the '!!x' construct is not a programmer I would count on being familiar with the '? :' operator either. Besides, I personally find the corresponding '? :' construction harder to read. -- <Insert your favourite quote here.> Erik Trulsson ertr1013@student.uu.se
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20081205093005.GA29478>