Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #77282

Re: Program to print the longest line

From Tim Rentsch <txr@alumni.caltech.edu>
Newsgroups comp.lang.c
Subject Re: Program to print the longest line
Date 2015-11-27 13:34 -0800
Organization A noiseless patient Spider
Message-ID <kfnoaefyvm5.fsf@x-alumni2.alumni.caltech.edu> (permalink)
References (3 earlier) <dc3b3d38-dcdf-4e38-bfbb-0180e80f2166@googlegroups.com> <ln4mghfdz4.fsf@kst-u.example.com> <n2mqs3$tf1$1@dont-email.me> <kfnk2pc9yyd.fsf@x-alumni2.alumni.caltech.edu> <MPG.30bdd4bf8499e642ae@news.eternal-september.org>

Show all headers | View raw


Philip Lantz <prl@canterey.us> writes:

> Tim Rentsch wrote:
>> David Brown writes:
>>> Keith Thompson wrote:
>>>> Alla _ writes:
>>>>>
>>>>>>> int getline(char line[], int maxline);
>>>>>>
>>>>>> FWIW, K&R1 page 26 gives
>>>>>>   getline(s, lim)
>>>>>>   char s[];
>>>>>>   int lim;
>>>>>>   {
>>>>>>    ...
>>>>>>
>>>>>> It looks here like _Alla is trying to rewrite K&R2 code to match
>>>>>> something the equivalent K&R1 code.
>>>>>
>>>>> No ) I was trying to follow the rules I have learned - prototypes
>>>>> and function definitions should have consistent names of variables;
>>>>> this is the only reason why (and what) I have dared to changed in
>>>>> this program.
>>>>>
>>>>> Keith has explained my mistake, and now I know, but will follow
>>>>> the "rule" of being consistent;  I believe it adds up to
>>>>> readability of any code, and to beauty of it.
>>>>
>>>> I just checked my copy of K&R2.  It does indeed use different
>>>> parameter names in the declaration and in the definition.  I have
>>>> no idea why;  I can't think of any good reason for it -- but as
>>>> I've said it's perfectly legal.  (It might have been useful as a
>>>> way to illustrate that very point, but there's no explicit
>>>> mention of it.)
>>>
>>> It would seem strange that they would want to illustrate it as a
>>> point.  In my opinion, the ability to use different parameter
>>> names is a flaw, not a feature - I can't think of any conceivable
>>> use for it.  [...]
>>
>> There is an obvious one - choose a longer and more descriptive
>> name for the interface, and a shorter (but still adequately
>> descriptive) name for the implementation.  I've been trying out
>> this technique recently (in another language, not C, but the idea
>> is the same), and find the results quite good.
>
> I agree.  As another example, I on occasion do something like this:
>
> In the header:
> extern int some_descriptive_function_name(void *buf);
>
> In the source file:
> extern int some_descriptive_function_name(void *arg)
> {
>     unsigned char *buf = (unsigned char *)arg;
>     // Use buf.
> }
>
> (I could probably come up with better names for the example, or dig
> up a real example, but it's 2:00 AM;  I think you get the idea.)

Ah ha.  Good example.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Program to print the longest line Alla _ <modelling.data@gmail.com> - 2015-11-18 08:10 -0800
  Re: Program to print the longest line Keith Thompson <kst-u@mib.org> - 2015-11-18 08:49 -0800
    Re: Program to print the longest line Alla _ <modelling.data@gmail.com> - 2015-11-18 09:03 -0800
    Re: Program to print the longest line Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-18 09:04 -0800
      Re: Program to print the longest line Keith Thompson <kst-u@mib.org> - 2015-11-18 09:24 -0800
  Re: Program to print the longest line Richard Heathfield <rjh@cpax.org.uk> - 2015-11-18 17:42 +0000
    Re: Program to print the longest line Alla _ <modelling.data@gmail.com> - 2015-11-18 10:49 -0800
      Re: Program to print the longest line James Kuyper <jameskuyper@verizon.net> - 2015-11-18 13:55 -0500
        Re: Program to print the longest line Alla _ <modelling.data@gmail.com> - 2015-11-18 11:01 -0800
          Re: Program to print the longest line James Kuyper <jameskuyper@verizon.net> - 2015-11-18 14:19 -0500
            Re: Program to print the longest line Alla _ <modelling.data@gmail.com> - 2015-11-18 21:50 -0800
              Re: Program to print the longest line James Kuyper <jameskuyper@verizon.net> - 2015-11-19 06:39 -0500
                Re: Program to print the longest line Alla _ <modelling.data@gmail.com> - 2015-11-19 05:07 -0800
                Re: Program to print the longest line James Kuyper <jameskuyper@verizon.net> - 2015-11-19 10:12 -0500
                Re: Program to print the longest line Alla _ <modelling.data@gmail.com> - 2015-11-19 07:49 -0800
      Re: Program to print the longest line Richard Heathfield <rjh@cpax.org.uk> - 2015-11-18 19:08 +0000
    Re: Program to print the longest line Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-18 14:54 -0500
      Re: Program to print the longest line Alla _ <modelling.data@gmail.com> - 2015-11-18 23:36 -0800
        Re: Program to print the longest line Keith Thompson <kst-u@mib.org> - 2015-11-19 21:15 -0800
          Re: Program to print the longest line Geoff <geoff@invalid.invalid> - 2015-11-19 21:29 -0800
          Re: Program to print the longest line David Brown <david.brown@hesbynett.no> - 2015-11-20 11:00 +0100
            Re: Program to print the longest line glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-20 15:13 +0000
            Re: Program to print the longest line supercat@casperkitty.com - 2015-11-20 11:29 -0800
            Re: Program to print the longest line Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-20 12:51 -0800
              Re: Program to print the longest line Philip Lantz <prl@canterey.us> - 2015-11-24 01:59 -0800
                Re: Program to print the longest line Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-27 13:34 -0800
  Re: Program to print the longest line John Gordon <gordon@panix.com> - 2015-11-18 18:10 +0000
    Re: Program to print the longest line Alla _ <modelling.data@gmail.com> - 2015-11-18 10:53 -0800
      Re: Program to print the longest line Barry Schwarz <schwarzb@dqel.com> - 2015-11-18 13:55 -0800
        Re: Program to print the longest line Alla _ <modelling.data@gmail.com> - 2015-11-18 23:32 -0800
  Re: Program to print the longest line Barry Schwarz <schwarzb@dqel.com> - 2015-11-18 11:58 -0800

csiph-web