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


Groups > comp.lang.c > #172325

Re: Why does the -> operator exist ?

From Phil Carmody <pc+usenet@asdf.org>
Newsgroups comp.lang.c
Subject Re: Why does the -> operator exist ?
Date 2023-08-15 23:00 +0300
Organization A noiseless patient Spider
Message-ID <877cpw3wjx.fsf@fatphil.org> (permalink)
References (3 earlier) <874jlyq8re.fsf@nosuchdomain.example.com> <86pm3xbswl.fsf@linuxsc.com> <877cq5qfc6.fsf@nosuchdomain.example.com> <86wmxx7t7l.fsf@linuxsc.com> <87bkf9mg0y.fsf@nosuchdomain.example.com>

Show all headers | View raw


Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>>>>> [...] I would argue that using `->` rather than `.` when the
>>>>>>> prefix is a pointer makes for more explicit code, which is a
>>>>>>> good thing;  [...]
>>>>>>
>>>>>> More explicit is not always better.
>>>>>
>>>>> No, it isn't.
>>>>>
>>>>> If you had anything to say about this particular case (`->` being
>>>>> more explicit than `.`, and whether it's better), this would have
>>>>> been a good opportunity to say it.
>>>>
>>>> In the particular case of using '.' instead of '->', more
>>>> explicit is not always better.
>>>
>>> That's a useless statement.
>>
>> No more useless than the statement from you that prompted
>> the discussion.
>
> My original statement, quoted above, was that using `->` rather than
> `.` is more explicit and that that's a good thing.  That was and
> is my opinion, applicable only to that particular case.  I've used
> languages that use `.` for both (where the prefix can be either
> a structure or a pointer), and haven't had any particular problem
> with that.  I have a preference, but not a strong preference.
>
> If I see `foo->bar` in C code, I know that `foo` is a pointer
> expression pointing to a struct or union.  If I see `foo.bar`, I
> know that `foo` is an expression of struct or union type.  I know
> that without looking for the declaration.  I sometimes find it
> useful to be able to understand something about a code fragment
> without having to understand 100% of the context.
>
> You apparently think that was a useless statement.  You apparently
> thought it was important enough to comment on it.
>
> You refuted a claim that explicit is *always* better.  Of course
> I never said that, nor do I believe it.
>
> I tried to invite you to expand on your statement.  Perhaps you think
> that dropping `->` and using `.` for both structs and pointers (and
> unions and union pointers) would have been better.  Perhaps you have
> good reasons for your preference, assuming it is your preference.
> Perhaps an explanation of those preferences would have been useful
> and interesting.  Heck, I might even agree with you.

If I see:
  foo->x *= 2;
  frob(foo);
I don't even twitch. However, if I see:
  foo.x *= 2;
  frob(foo);
I begin to worry - how much of a structure am I filling the stack with,
or is frob just a harmless macro, or what. I immediately need to know
more.

So I'm definitely in team keep-em-different.

Phil
-- 
We are no longer hunters and nomads. No longer awed and frightened, as we have
gained some understanding of the world in which we live. As such, we can cast
aside childish remnants from the dawn of our civilization.
-- NotSanguine on SoylentNews, after Eugen Weber in /The Western Tradition/

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


Thread

Why does the  ->  operator exist ? Spiros Bousbouras <spibou@gmail.com> - 2023-06-27 09:12 +0000
  Re: Why does the  ->  operator exist ? felix@palmen-it.de (Felix Palmen) - 2023-06-27 15:01 +0200
    Re: Why does the  ->  operator exist ? Spiros Bousbouras <spibou@gmail.com> - 2023-06-27 14:09 +0000
      Re: Why does the  ->  operator exist ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-06-27 15:56 +0100
  Re: Why does the -> operator exist ? Bart <bc@freeuk.com> - 2023-06-27 16:06 +0100
    Re: Why does the -> operator exist ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-06-27 18:01 +0100
      Re: Why does the -> operator exist ? BGB <cr88192@gmail.com> - 2023-06-27 12:46 -0500
    Re: Why does the -> operator exist ? fir <profesor.fir@gmail.com> - 2023-08-09 00:08 -0700
      Re: Why does the -> operator exist ? fir <profesor.fir@gmail.com> - 2023-08-09 00:11 -0700
        Re: Why does the -> operator exist ? fir <profesor.fir@gmail.com> - 2023-08-09 00:23 -0700
  Re: Why does the  ->  operator exist ? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2023-06-27 15:13 +0000
  Re: Why does the  ->  operator exist ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-06-27 15:30 +0000
    Re: Why does the -> operator exist ? Bart <bc@freeuk.com> - 2023-06-27 17:05 +0100
      Re: Why does the -> operator exist ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-06-27 17:11 +0000
  Re: Why does the -> operator exist ? BGB <cr88192@gmail.com> - 2023-06-27 10:54 -0500
  Re: Why does the  ->  operator exist ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-06-27 12:23 -0700
    Re: Why does the  ->  operator exist ? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2023-06-27 15:33 -0600
    Re: Why does the  ->  operator exist ? Spiros Bousbouras <spibou@gmail.com> - 2023-06-28 16:31 +0000
      Re: Why does the  ->  operator exist ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-06-29 03:14 +0000
    Re: Why does the  ->  operator exist ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-07-20 18:57 -0700
      Re: Why does the  ->  operator exist ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-07-20 19:49 -0700
        Re: Why does the  ->  operator exist ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-08-08 05:49 -0700
          Re: Why does the  ->  operator exist ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-08-08 16:33 -0700
            Re: Why does the  ->  operator exist ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-08-14 04:34 -0700
              I love it... (Was: Why does the  ->  operator exist ?) gazelle@shell.xmission.com (Kenny McCormack) - 2023-08-14 12:41 +0000
              Re: Why does the  ->  operator exist ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-08-14 15:10 -0700
                Re: Why does the  ->  operator exist ? Phil Carmody <pc+usenet@asdf.org> - 2023-08-15 23:00 +0300
                Re: Why does the  ->  operator exist ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-08-16 05:29 -0700
      Re: Why does the  ->  operator exist ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-07-22 05:39 +0000
  Re: Why does the -> operator exist ? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2023-06-28 14:16 -0700

csiph-web