Deutsch English Français Italiano |
<vhqkm6$7dv$1@reader2.panix.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail From: cross@spitfire.i.gajendra.net (Dan Cross) Newsgroups: comp.unix.shell,comp.unix.programmer,comp.lang.misc Subject: Re: Command Languages Versus Programming Languages Date: Fri, 22 Nov 2024 19:05:42 -0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: <vhqkm6$7dv$1@reader2.panix.com> References: <uu54la$3su5b$6@dont-email.me> <87o727rwga.fsf@doppelsaurus.mobileactivedefense.com> <vhqhii$d5e$1@reader2.panix.com> <87h67zrtns.fsf@doppelsaurus.mobileactivedefense.com> Injection-Date: Fri, 22 Nov 2024 19:05:42 -0000 (UTC) Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80"; logging-data="7615"; mail-complaints-to="abuse@panix.com" X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Originator: cross@spitfire.i.gajendra.net (Dan Cross) Bytes: 3740 Lines: 97 In article <87h67zrtns.fsf@doppelsaurus.mobileactivedefense.com>, Rainer Weikusat <rweikusat@talktalk.net> wrote: >cross@spitfire.i.gajendra.net (Dan Cross) writes: > >[...] > >> In any event, this seems simpler than what you posted: >> >> #include <stddef.h> >> #include <stdio.h> >> #include <stdlib.h> >> >> int >> main(int argc, char *argv[]) >> { >> if (argc != 2) { >> fprintf(stderr, "Usage: matchd <str>\n"); >> return EXIT_FAILURE; >> } >> >> for (const char *p = argv[1]; *p != '\0'; p++) >> if ('0' <= *p && *p <= '9') >> return EXIT_SUCCESS; >> >> return EXIT_FAILURE; >> } > >It's not only 4 lines longer but in just about every individual aspect >syntactically more complicated and more messy and functionally more >clumsy. That's a lot of opinion, and not particularly well-founded opinion at that, given that your code was incorrect to begin with. >This is particularly noticable in the loop > > for (const char *p = argv[1]; *p != '\0'; p++) > if ('0' <= *p && *p <= '9') > return EXIT_SUCCESS; > >the loop header containing a spuriously qualified variable declaration, Ibid. Const qualifying a pointer that I'm not going to assign through is just good hygiene, IMHO. >the loop body and half of the termination condition. I think you're trying to project a value judgement onto that loop in order to make it fit a particular world view, but I think this is an odd way to look at it. Another way to loop at it is that the loop is only concerned with the iteration over the string, while the body is concerned with applying some predicate to the element, and doing something if that predicate evaluates it to true. >The other half then >follows as special-case in the otherwise useless loop body. That's a way to look at it, but I submit that's an outlier point of view. >It looks like a copy of my code which each individual bit redesigned >under the guiding principle of "Can we make this more complicated?", eg, Uh, no. >char **argv > >declares an array of pointers No, it declares a pointer to a pointer to char. >(as each pointer in C points to an array) That's absolutely not true. A pointer in C may refer to an array, or a scalar. Consider, char c; char *p = &c; char **pp = &p; For a concrete example of how this works in a real function, consider the second argument to `strtol` et al in the standard library. >and > >char *argv[] > >accomplishes exactly the same but uses both more characters and more >different kinds of characters. "more characters" is a poor metric. - Dan C.