From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: tuhs-bounces@minnie.tuhs.org X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.1 Received: from minnie.tuhs.org (minnie.tuhs.org [45.79.103.53]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 4ccf61a9 for ; Wed, 11 Jul 2018 03:36:28 +0000 (UTC) Received: by minnie.tuhs.org (Postfix, from userid 112) id 524789E279; Wed, 11 Jul 2018 13:36:27 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id 1B71A9E273; Wed, 11 Jul 2018 13:35:15 +1000 (AEST) Received: by minnie.tuhs.org (Postfix, from userid 112) id DFA759E273; Wed, 11 Jul 2018 13:35:12 +1000 (AEST) Received: from mail.bitblocks.com (ns1.bitblocks.com [173.228.5.8]) by minnie.tuhs.org (Postfix) with ESMTP id 926BA9E26F for ; Wed, 11 Jul 2018 13:35:12 +1000 (AEST) Received: from bitblocks.com (localhost [127.0.0.1]) by mail.bitblocks.com (Postfix) with ESMTP id 339B4156E400; Tue, 10 Jul 2018 20:34:58 -0700 (PDT) From: Bakul Shah To: Larry McVoy In-reply-to: Your message of "Tue, 10 Jul 2018 18:31:27 -0700." <20180711013127.GC2012@mcvoy.com> References: <3386fb80b5282f7bca0ccf34252182c2398232c1@webmail.yaccman.com> <5D272962-0063-4D28-B551-F381D3D10239@alchemistowl.org> <009101d4112f$8bb30f50$a3192df0$@ronnatalie.com> <1531153839.3991054.1434840984.210C4B3F@webmail.messagingengine.com> <201807100554.w6A5s0VM005631@freefriends.org> <201807100719.w6A7Jx9V014856@freefriends.org> <20180711013127.GC2012@mcvoy.com> Comments: In-reply-to Larry McVoy message dated "Tue, 10 Jul 2018 18:31:27 -0700." MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <68783.1531280098.1@bitblocks.com> Date: Tue, 10 Jul 2018 20:34:58 -0700 Message-Id: <20180711033505.339B4156E400@mail.bitblocks.com> Subject: [TUHS] getopt (was Re: Any Good dmr Anecdotes? X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: TUHS main list Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" On Tue, 10 Jul 2018 18:31:27 -0700 Larry McVoy wrote: Larry McVoy writes: > On Wed, Jul 11, 2018 at 10:20:50AM +1000, Noel Hunt wrote: > > I'm surprised why anyone would bother with these routines > > anymore, given the startling simplicity of Plan9's arg(3). > > One stands in awe of such simplicity. I believe it was > > William Cheswick who designed it, but I may be wrong. plan9 arg macros are indeed very nice. > It's nice but I like long opts. The getopt in BK (and now in L) > looks like this and produces its own help (which does miss the > short opts, my bad, I could fix that). Look at the default in > the switch: > > string c; > string lopts[] = { > "bigy:", > "date-split", ... > "title:", > "ysize:", > }; > > while (c = getopt(av, "fj:", lopts)) { > switch (c) { > case "bigy": bigy = (int)optarg; break; > case "date-split": dates = 1; break; ... > case "title": title = optarg; break; > case "thumbnails": thumbnails = 1; break; > case "ysize": ysize = (int)optarg; break; > default: > printf("Usage: photos.l"); [You can also do a switch on string in Go.] Having to write the same strings twice is a pain. May be even three times, if you add usage()! I don't much like long options as they tend to proliferate. -- Your typical engineer doesn't like to make hard choices so indecisions turn into options! If there have to be long options, I want to be able to abbreviate them and I want word completion and context sensitive help as invariably long options end up having complex semantics.