Is this C program doing what it is supposed to do ?

I

ImpalerCore

[... discussing 'a = b == c;' vs 'a = (b == c);' ...]
Put simply, if the expected statement is [a = b == c;] and the two
typo statements are [a = b = c;] or [a = (b = c);], I would detect the
second typo with less effort.  [snip elaboration]
So is it fair to say you also are just expressing a personal
opinion?
Sure it's my personal opinion, but the style of using of parentheses
to emphasize precedence is pretty common in the teaching and books used
when I was learning C and C++.

Remember Dijkstra's admonition:  don't think something is _convenient_
just because it is _conventional_.  Advising students to use extra
parentheses has been around at least since the 1960's when I first
learned how to program.  Offered in beginning classes, it's the
programming equivalent of training wheels on a bicycle -- useful to
get people started, but no real help once the necessary skills have
been acquired.  I no longer use training wheels on my bicycle, and I
don't think it's important in my everyday riding to cater to beginners
who still need them.
Use of spaces, not so much.  In fact I
think you're the first person I've met that advocates using space over
parentheses to emphasize precedence in the manner you're describing.

People used to think the Earth was the center of the universe and
everything else revolved around it.  Are you charging me with being
a heretic?  Just because you're hearing an idea for the first time
doesn't mean the idea is bad;  it's much more convenient to think of
the Earth as going around the Sun than vice versa, as repulsive as
that idea was to people when it was first proposed.

It would be nice if you tried to engage in an actual discussion
of the merits and shortcomings of a proposed alternative, rather
than just making an ad hominem remark and dismissing it.

No seriously, I didn't intend anything as an ad hominem. I have
simply not encountered it. I have not seen fellow posters rush to
defend your style as common. Sorry if it insulted you.

I think I'll just let the topic go from here on.

Best regards,
John D.
 
B

Ben Bacarisse

ImpalerCore said:
Sure it's my personal opinion, but the style of using of parentheses
to emphasize grouping is pretty common in the teaching and books used
when I was learning C and C++. Use of spaces, not so much. In fact I
think you're the first person I've met that advocates using space over
parentheses to emphasize precedence in the manner you're describing.

I have the reverse experience. I don't recall being told to add
parentheses but I do recall extra spacing being suggested. I used to do
it all the time but I stopped at some point for reasons I can't be sure
of anymore. One problem (which may have contributed to my stopping) is
that it does not work so well with split lines.

At least one programming language actually uses spacing to some extent.
Fortress (a Sun language so I guess Guy Steele was involved) will check
your spacing so 1+2 * 3 will generate an error. You don't need extra
space (1 + 2 * 3 is accepted as usual) but the reader can be confident
that extra space means what one expects so it is encouraged if not
required.

There is an interesting precedent. Peano introduced a notion that uses
a dot to do much the same thing -- like a visible space except that the
purpose is to completely replace parentheses (for grouping). It was
most famously used in Russell and Whitehead's Principia Mathematica.
Basically the dots "push apart" the items they sit between -- more dots
showing weaker binding. They are usually written '.', ':', ':.' and,
rarely, '::'. Borrowing C's operators, my appalling expression would be

a_beginning . = . c == '\n';

The notation is quite subtle since it can be used asymmetrically, unlike
parentheses. Also, because its use was in logic where conjunction is
common it can appear between terms with, again, the number of dot
indicating the binding. This is (so I am told) the origin of . for
conjuction and multiplication.

We are spoilt by fixed-width fonts that accentuate brackets and I
suspect that formulae typeset with conventional, rather thin, brackets
are not so easy to read. Thus the dots (which are quite heavy in the
editions I've seen) really start to pay off.

Psychologically they have a curious effect. An open bracket makes me
take a mental breath, ready to scoop up some possibly long content (I
have to exhale deeply before reading Lisp). One or more dots, however,
make me relax because the gist of any of them is: "ah, we're done with
that part". Another nice property is that to read them in your head,
all you really need to do is to pause:

x == (1 + 2) * (3 + 4) * (5 + 6)

is written

x : = : 1 + 2 . * . 3 + 4
 
S

Stefan Ram

Tim Rentsch said:
Any C programmer who doesn't immediately understand the
effect of this statement (either with or without the
redundant parentheses) upon having read it needs to go
back and re-take Programming 101.

Yes, a programmer needs to have other priorities than to
write for persons who do not know the language or can't read
carefully, which in any case is not possible.
 
M

Michael Press

Tim Rentsch said:
Basically there are two reasons: visual processing, and cognitive
load. I find that my eyes have to work harder when the extra
parentheses are there. I'm not sure how much harder exactly, but
it's enough that I notice the difference, and that costs something
in terms of attentiveness. Extra whitespace doesn't fatigue my
eyes the way extra parentheses do.

About cognitive load - please read on.



I also don't assume that but I do sometimes wonder ....


I don't assume this one either; I'm basically just left wondering.
The uncertainty adds to my cognitive load.



No, certainly not the _same_ question. Some other questions (see
below) but they don't carry the same cognitive load.

I agree with you all down the line; and am aware of how
bad style slows me down in all my reading.
 
C

Chris H

Stefan Ram said:
Yes, a programmer needs to have other priorities than to
write for persons who do not know the language or can't read
carefully, which in any case is not possible.

A programmer needs to write code that is clear and easy to read and is
maintainable.

Usually "writing clever code" is an oxymoron.
 
T

Tim Rentsch

ImpalerCore said:
ImpalerCore said:
ImpalerCore <[email protected]> writes:
[... discussing 'a = b == c;' vs 'a = (b == c);' ...]
Put simply, if the expected statement is [a = b == c;] and the two
typo statements are [a = b = c;] or [a = (b = c);], I would detect the
second typo with less effort. [snip elaboration]
So is it fair to say you also are just expressing a personal
opinion?
Sure it's my personal opinion, but the style of using of parentheses
to emphasize precedence is pretty common in the teaching and books used
when I was learning C and C++.

Remember Dijkstra's admonition: don't think something is _convenient_
just because it is _conventional_. Advising students to use extra
parentheses has been around at least since the 1960's when I first
learned how to program. Offered in beginning classes, it's the
programming equivalent of training wheels on a bicycle -- useful to
get people started, but no real help once the necessary skills have
been acquired. I no longer use training wheels on my bicycle, and I
don't think it's important in my everyday riding to cater to beginners
who still need them.
Use of spaces, not so much. In fact I
think you're the first person I've met that advocates using space over
parentheses to emphasize precedence in the manner you're describing.

People used to think the Earth was the center of the universe and
everything else revolved around it. Are you charging me with being
a heretic? Just because you're hearing an idea for the first time
doesn't mean the idea is bad; it's much more convenient to think of
the Earth as going around the Sun than vice versa, as repulsive as
that idea was to people when it was first proposed.

It would be nice if you tried to engage in an actual discussion
of the merits and shortcomings of a proposed alternative, rather
than just making an ad hominem remark and dismissing it.

No seriously, I didn't intend anything as an ad hominem. I have
simply not encountered it. I have not seen fellow posters rush to
defend your style as common. Sorry if it insulted you.

I didn't take it that way. I was just making a factual
observation that your comment is a lot more about me than it
is about the idea. Even though a remark isn't insulting or
belittling it still can be ad hominem.
I think I'll just let the topic go from here on.

Have you said anything more than "here is my opinion,
and I think a lot of other people share the same
opinion"?
 
T

Tim Rentsch

Yes, a programmer needs to have other priorities than to
write for persons who do not know the language or can't read
carefully, which in any case is not possible.

Did you misunderstand the point I was making? My
comment has nothing to do with whether someone has
good or poor reading habits.
 
S

Stefan Ram

Tim Rentsch said:
Did you misunderstand the point I was making? My
comment has nothing to do with whether someone has
good or poor reading habits.

Obviously, a text might not be properly understood,
if the reader

- does not know the language of the text, or

- can not focus sufficiently on the reading.
 
I

ImpalerCore

ImpalerCore said:
[... discussing 'a = b == c;' vs 'a = (b == c);' ...]
Put simply, if the expected statement is [a = b == c;] and the two
typo statements are [a = b = c;] or [a = (b = c);], I would detect the
second typo with less effort.  [snip elaboration]
So is it fair to say you also are just expressing a personal
opinion?
Sure it's my personal opinion, but the style of using of parentheses
to emphasize precedence is pretty common in the teaching and books used
when I was learning C and C++.
Remember Dijkstra's admonition:  don't think something is _convenient_
just because it is _conventional_.  Advising students to use extra
parentheses has been around at least since the 1960's when I first
learned how to program.  Offered in beginning classes, it's the
programming equivalent of training wheels on a bicycle -- useful to
get people started, but no real help once the necessary skills have
been acquired.  I no longer use training wheels on my bicycle, and I
don't think it's important in my everyday riding to cater to beginners
who still need them.
Use of spaces, not so much.  In fact I
think you're the first person I've met that advocates using space over
parentheses to emphasize precedence in the manner you're describing.
People used to think the Earth was the center of the universe and
everything else revolved around it.  Are you charging me with being
a heretic?  Just because you're hearing an idea for the first time
doesn't mean the idea is bad;  it's much more convenient to think of
the Earth as going around the Sun than vice versa, as repulsive as
that idea was to people when it was first proposed.
It would be nice if you tried to engage in an actual discussion
of the merits and shortcomings of a proposed alternative, rather
than just making an ad hominem remark and dismissing it.
No seriously, I didn't intend anything as an ad hominem.  I have
simply not encountered it.  I have not seen fellow posters rush to
defend your style as common.  Sorry if it insulted you.

I didn't take it that way.  I was just making a factual
observation that your comment is a lot more about me than it
is about the idea.  Even though a remark isn't insulting or
belittling it still can be ad hominem.

Well, you sure sounded insulted. If you put your opinion about
whitespace as a revelation equivalent to Galileo's discovery, then my
parentheses and I are obviously ready to start a Catholic inquisition,
ready to burn you at the stake. Not exactly positive imagery.
Have you said anything more than "here is my opinion,
and I think a lot of other people share the same
opinion"?

Nope. Again, I don't consider whether you use whitespace or
parentheses good or bad; I can read either fine. I choose as a habit
to use them to emphasize precedence; you don't like them. We don't
work on the same code, so it's not an issue. I don't think there's
much else to say.

Best regards,
John D.
 
S

Seebs

Agreed; I was probably overstating the case a bit.

I seem to recall something very close to that in one of the Schildt
books. :)
That last point, I think, is the core of our disagreement. Changing
grouping is not "the whole reason" for parentheses. They can also be
used to emphasize existing grouping. In fact I often use them that way
myself. (I'm no longer trying to convince you that it's a good idea,
just that it's commonly done.)

I do this very often.

In fact, I have absolutely no idea whether I'm using them to change
grouping or to emphasize grouping. I just use them to show what grouping
I intend, and I don't waste my limited cognitive bandwidth trying to guess
whether or not I'd have gotten that grouping anyway.

-s
 
K

Keith Thompson

Chris H said:
A programmer needs to write code that is clear and easy to read and is
maintainable.

Usually "writing clever code" is an oxymoron.

Again, I agree completely with what you've written here.

The real question is, where is the line between clear code and overly
clever code? I find

condition = (foo == bar);

to be solidly on the "clear code" side of the divide. I *think* you
have a different opinion, but I haven't seen you support it.
 
S

Stefan Ram

Keith Thompson said:
condition = (foo == bar);

Problems to understand this line are pre-beginner-level problems.
Problems of people who have not yet learned the operators of C.
Sometimes I wonder how restricted we expect the minds of
programmers to be.¹

Educated C programmes write code where the real problems are
either the difficulty or complexity of the algorithm (think
of a program to recognice a specific face in a video stream)
or the sheer size of the system.

A major problem also is maintainability, and this requires
readable code. But the problems with maintainability usually
arise in relation to the structure of the code on a larger
scale than the single line quoted above. These problems are
called »smells« in the realm of refactoring.

1

These are tables with forms of some important italian verbs:

http://www.italian-verbs.com/italian-verbs/conjugation.php?verbo=essere
http://www.italian-verbs.com/italian-verbs/conjugation.php?verbo=avere
http://www.italian-verbs.com/italian-verbs/conjugation.php?verbo=dovere
http://www.italian-verbs.com/italian-verbs/conjugation.php?verbo=volere
http://www.italian-verbs.com/italian-verbs/conjugation.php?verbo=potere

They are irregular, there are several dozens of other common
irregular verbs and about 10000 - 30000 words with different
forms (there are »irregular« nouns, too) that one is
expected to learn by heart when one wants to learn Italian.
When listening or speaking, one then needs to apply all the
rules and all this knowledge in real time.

Now, what amount of information does a table of all C
operators together with their meanings contain?

So, can we reasonably expect people with a paid job as a
programmer or C programmer to learn or at least look the
operators when they need to know this to understand a part
of some source code and usually will need this knowledge
every day?
 
T

Tim Rentsch

ImpalerCore said:
ImpalerCore said:
ImpalerCore <[email protected]> writes:
[... discussing 'a = b == c;' vs 'a = (b == c);' ...]
Put simply, if the expected statement is [a = b == c;] and the two
typo statements are [a = b = c;] or [a = (b = c);], I would detect the
second typo with less effort. [snip elaboration]
So is it fair to say you also are just expressing a personal
opinion?
Sure it's my personal opinion, but the style of using of parentheses
to emphasize precedence is pretty common in the teaching and books used
when I was learning C and C++.
Remember Dijkstra's admonition: don't think something is _convenient_
just because it is _conventional_. Advising students to use extra
parentheses has been around at least since the 1960's when I first
learned how to program. Offered in beginning classes, it's the
programming equivalent of training wheels on a bicycle -- useful to
get people started, but no real help once the necessary skills have
been acquired. I no longer use training wheels on my bicycle, and I
don't think it's important in my everyday riding to cater to beginners
who still need them.
Use of spaces, not so much. In fact I
think you're the first person I've met that advocates using space over
parentheses to emphasize precedence in the manner you're describing.
People used to think the Earth was the center of the universe and
everything else revolved around it. Are you charging me with being
a heretic? Just because you're hearing an idea for the first time
doesn't mean the idea is bad; it's much more convenient to think of
the Earth as going around the Sun than vice versa, as repulsive as
that idea was to people when it was first proposed.
It would be nice if you tried to engage in an actual discussion
of the merits and shortcomings of a proposed alternative, rather
than just making an ad hominem remark and dismissing it.
No seriously, I didn't intend anything as an ad hominem. I have
simply not encountered it. I have not seen fellow posters rush to
defend your style as common. Sorry if it insulted you.

I didn't take it that way. I was just making a factual
observation that your comment is a lot more about me than it
is about the idea. Even though a remark isn't insulting or
belittling it still can be ad hominem.

Well, you sure sounded insulted. [snip elaboration]

No, just disappointed.
Nope. Again, I don't consider whether you use whitespace or
parentheses good or bad; I can read either fine. I choose as a habit
to use them to emphasize precedence; you don't like them. We don't
work on the same code, so it's not an issue. I don't think there's
much else to say.

I was hoping the conversation would move away from just
being statements of personal opinion, in the general
direction of findings that are objective, verifiable, or
quantifiable. And I'm still optimistic enough to think
that's not too much to hope for.
 
T

Tim Rentsch

Obviously, a text might not be properly understood,
if the reader

- does not know the language of the text, or
Yes.

- can not focus sufficiently on the reading.

Also yes, but outside the domain of my statement,
which was only about comprehension, not legibility.
It's also true, for example, that a text might not be
understood if the reader is drunk; even though that's
a true statement, it doesn't pertain to what I was
saying.
 
T

Tim Rentsch

Seebs said:
[snip] [Parentheses can be]
used to emphasize existing grouping. In fact I often use them that way
myself. (I'm no longer trying to convince you that it's a good idea,
just that it's commonly done.)

I do this very often.

In fact, I have absolutely no idea whether I'm using them to change
grouping or to emphasize grouping. I just use them to show what grouping
I intend, and I don't waste my limited cognitive bandwidth trying to guess
whether or not I'd have gotten that grouping anyway.

That seems reasonable, as long as you don't think it necessarily
applies to people who are not mentally differently-abled in the
way that you are.
 
S

Stefan Ram

Tim Rentsch said:
That seems reasonable,

If adding parentheses enhances the readability,
then LISP must be the most readable language,
because in LISP this is not just an option,
but it's the law.
 
K

Keith Thompson

Tim Rentsch said:
Seebs said:
[snip] [Parentheses can be]
used to emphasize existing grouping. In fact I often use them that way
myself. (I'm no longer trying to convince you that it's a good idea,
just that it's commonly done.)

I do this very often.

In fact, I have absolutely no idea whether I'm using them to change
grouping or to emphasize grouping. I just use them to show what grouping
I intend, and I don't waste my limited cognitive bandwidth trying to guess
whether or not I'd have gotten that grouping anyway.

That seems reasonable, as long as you don't think it necessarily
applies to people who are not mentally differently-abled in the
way that you are.

I believe it does.
 
K

Keith Thompson

Tim Rentsch said:
I was hoping the conversation would move away from just
being statements of personal opinion, in the general
direction of findings that are objective, verifiable, or
quantifiable. And I'm still optimistic enough to think
that's not too much to hope for.

I think it might well be too much to hope for. I don't know of any
formal studies on this issue. In the absence of any such studies
we can point to, any discussion is bound to be overwhelmed by
personal opinion.

If you want to have a more objective discussion, perhaps you can find
some studies for us to discuss.
 
I

ImpalerCore

ImpalerCore said:
[... discussing 'a = b == c;' vs 'a = (b == c);' ...]
Put simply, if the expected statement is [a = b == c;] and the two
typo statements are [a = b = c;] or [a = (b = c);], I would detect the
second typo with less effort.  [snip elaboration]
So is it fair to say you also are just expressing a personal
opinion?
Sure it's my personal opinion, but the style of using of parentheses
to emphasize precedence is pretty common in the teaching and books used
when I was learning C and C++.
Remember Dijkstra's admonition:  don't think something is _convenient_
just because it is _conventional_.  Advising students to use extra
parentheses has been around at least since the 1960's when I first
learned how to program.  Offered in beginning classes, it's the
programming equivalent of training wheels on a bicycle -- useful to
get people started, but no real help once the necessary skills have
been acquired.  I no longer use training wheels on my bicycle, and I
don't think it's important in my everyday riding to cater to beginners
who still need them.
Use of spaces, not so much.  In fact I
think you're the first person I've met that advocates using space over
parentheses to emphasize precedence in the manner you're describing.
People used to think the Earth was the center of the universe and
everything else revolved around it.  Are you charging me with being
a heretic?  Just because you're hearing an idea for the first time
doesn't mean the idea is bad;  it's much more convenient to think of
the Earth as going around the Sun than vice versa, as repulsive as
that idea was to people when it was first proposed.
It would be nice if you tried to engage in an actual discussion
of the merits and shortcomings of a proposed alternative, rather
than just making an ad hominem remark and dismissing it.
No seriously, I didn't intend anything as an ad hominem.  I have
simply not encountered it.  I have not seen fellow posters rush to
defend your style as common.  Sorry if it insulted you.
I didn't take it that way.  I was just making a factual
observation that your comment is a lot more about me than it
is about the idea.  Even though a remark isn't insulting or
belittling it still can be ad hominem.
Well, you sure sounded insulted.  [snip elaboration]

No, just disappointed.
Nope.  Again, I don't consider whether you use whitespace or
parentheses good or bad; I can read either fine.  I choose as a habit
to use them to emphasize precedence; you don't like them.  We don't
work on the same code, so it's not an issue.  I don't think there's
much else to say.

I was hoping the conversation would move away from just
being statements of personal opinion, in the general
direction of findings that are objective, verifiable, or
quantifiable.  And I'm still optimistic enough to think
that's not too much to hope for.

I think it's hard to have that conversation when most style
preferences (in my opinion) lie in the realm of personal opinion.
It's like trying to find evidence that demonstrates that the 1TBS is
objectively superior to another. From a single person's perspective,
I can agree that there are cognitive advantages to using one over
another. I believe that you do understand the version without
parentheses better.

The main issue with style is when multiple programmers (with varying
levels of experience, preferences) are involved. Do you allow each
programmer to use their best cognitive style, while sacrificing
overall code consistency? Do you try to have a consistent style
throughout a project at the cost of varying levels of individual
comprehension? I don't know the answers to these questions.

Best regards,
John D.
 
I

Ian Collins

Tim Rentsch said:
Seebs said:
[snip] [Parentheses can be]
used to emphasize existing grouping. In fact I often use them that way
myself. (I'm no longer trying to convince you that it's a good idea,
just that it's commonly done.)

I do this very often.

In fact, I have absolutely no idea whether I'm using them to change
grouping or to emphasize grouping. I just use them to show what grouping
I intend, and I don't waste my limited cognitive bandwidth trying to guess
whether or not I'd have gotten that grouping anyway.

That seems reasonable, as long as you don't think it necessarily
applies to people who are not mentally differently-abled in the
way that you are.

I believe it does.

So do I.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top