The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: michael@kjorling.se (Michael Kjörling)
Subject: [TUHS] C question for the historians
Date: Thu, 9 Nov 2017 10:17:54 +0000	[thread overview]
Message-ID: <20171109101754.GD6190@h-174-65.A328.priv.bahnhof.se> (raw)
In-Reply-To: <CANCZdfqC5NSghfHVZ76R7bVdU2fVtCg04osueQEbVWbYMMPtOQ@mail.gmail.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1661 bytes --]

On 8 Nov 2017 09:27 -0700, from imp at bsdimp.com (Warner Losh):
> Or do the Linux-school and go with
> 
>     if (!!(flags & DLADM_OPT_PERSIST)) {
> 
> to really confuse things...

That smells like a Javascript influence to me, where

    if (!!x)

 or z = !!x;

is _more or less_ idiomatic for

    if (x == true)

 or z = x == true ? true : false;

(mind the difference between _assignment_ = and _equality_ == and
_actually equals_ ===)

or what in another language could be written as something largely
similar to a simple

    if (x)

if so desired.

Simply, !!x coerces x from whatever it is to a boolean, based on the
_truthiness_ of x. Where _truthiness_ is another of those lovely
Javascript concepts.

This, of course, is partly because Javascript (even more so than, say,
C) lacks _any_ sane idea of types. Its type system is more similar to
that of BCPL or PHP than even C, in that not only do you get to keep
the pieces if things break (assuming that you're lucky enough to
_know_ that things broke), but also that anything goes anywhere. That
variable which held a boolean a moment ago? Sure, go right ahead and
put an object or an array or a string in it. The next line of code can
replace it with a floating-point value or single character no problem,
and then you can have a conditional based on whether or not the latter
has sufficient truthiness.

(People who work with quantum computers must love that language.)

-- 
Michael Kjörling • https://michael.kjorling.se • michael at kjorling.se
                 “People who think they know everything really annoy
                 those of us who know we don’t.” (Bjarne Stroustrup)


  reply	other threads:[~2017-11-09 10:17 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-08 16:17 Arthur Krewat
2017-11-08 16:27 ` Warner Losh
2017-11-09 10:17   ` Michael Kjörling [this message]
2017-11-08 18:14 ` Ralph Corderoy
2017-11-08 18:34   ` Arthur Krewat
2017-11-08 19:05   ` Larry McVoy
2017-11-08 20:13     ` ron minnich
2017-11-08 20:23       ` Larry McVoy
2017-11-08 20:32         ` Ron Natalie
2017-11-08 20:39       ` Warner Losh
2017-11-08 20:41       ` Chet Ramey
2017-11-09  1:22         ` Ralph Corderoy
2017-11-09  1:41           ` Chet Ramey
2017-11-09  1:49             ` Arthur Krewat
2017-11-08 20:43       ` Bakul Shah
2017-11-08 20:55       ` Steve Nickolas
2017-11-08 20:36     ` Warner Losh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171109101754.GD6190@h-174-65.A328.priv.bahnhof.se \
    --to=michael@kjorling.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).