News for hackers. Stuff that matters.
Re:What does the ??!??! operator do in C? by vonwoodson on Wednesday October 05, 2022 @11:05PM (#33103874)
Could be, now that you mention it. Which, now, makes me wonder if my K&R is even shorter.
Re:What does the ??!??! operator do in C? by DonHopkins on Thursday October 06, 2022 @05:53AM (#33106382)
There's one thing that's usually true about every well used copy of K&R, and that's that it always opens up easily and by default to the page with the huge operator precedence order and associativity table, because that's the page everyone needs to refer to the most often, which is usually bookmarked, but in an old copy doesn't even need to be.

That says something about the C programming language design, that I as a deeply stack based FORTH programmer and explicitly parenthetical LISP programmer find horrible.

Re:What does the ??!??! operator do in C? by dahfizz on Thursday October 06, 2022 @08:31AM (#33107414)
Just use parentheses if you're doing many operations on one line? I've been programming in C for years and never had an issue with operator precedence.
Re:What does the ??!??! operator do in C? by falcrist on Thursday October 06, 2022 @09:54AM (#33108173)
There's a lot of exaggeration that goes on with certain fans of postfix systems when they talk about infix systems.

For example: I really like HP calculators, so I'm in several facebook groups for fans of RPN/RPL and HP specifically. Sometimes a few of them go way too far out of their way to try to demonstrate how inferior algebraic systems must be.

For the record, my copy of K&R wants to open into either section 7.6 or appendix B. No idea what this says about me, though.

Re:What does the ??!??! operator do in C? by michaelcampbell on Saturday October 08, 2022 @09:39AM (#33132191)
Indeed, different strokes for different uses. I "grokked" RPN pretty early in my career and use it for all my calculator stuff... only. infix for programming languages is equally comfortable for me. I still have to think and study quite hard the prefix LISP notation. I get it, it's just not internalized like the other 2.
Re:What does the ??!??! operator do in C? by DonHopkins on Thursday October 06, 2022 @09:57AM (#33108208)
It's not that YOU have any issues with it -- because you're perfect.

https://www.youtube.com/watch?v=fKHaNIEa6kA

It's about the poor people who read your code that relies on both you and them having perfectly memorized every single little detail of operator precedence and associativity, instead of simply and consistently using parenthesis.

Quick without looking: can you tell me what the precedence and associativity of the ternary ?: operator is?

The designer of PHP got it wrong (which isn't surprising given his proudly self proclaimed contempt towards computer science and incompetence at parser writing), but then millions of PHP programmers also learned it the wrong way.

https://en.wikiquote.org/wiki/Rasmus_Lerdorf

Do you really want any of those people who were corrupted by PHP messing around with your code, if you relied on it being one way, and they assume it works the other way?

It's not that you can't tell what it actually does, it's that you can't tell what the person who wrote it actually meant, which is more important than what it actually does, especially when it has bugs.

Don't do many operations on one line, AND do use parenthesis, AND do use indentation, with no exceptions except for very simple expressions. Take every opportunity to use vertical alignment to make symmetry and repetition obvious, like:

    sqrt((x * x) +
         (y * y))
Redundant parens, plus breaking expressions into multiple lines and indenting according to depth, unambiguously express programmer INTENT, so the reader doesn't need to wonder if the person who wrote it had a clue or was just showboating.

Just use parenthesis, and put a comment on it, sailor.

https://wellcomecollection.org/works/m33njwx3/items

My copy of The Little Schemer won't open to page 13 because of the jelly stains.

https://vpb.smallyu.net/[Type]%20books/The%20Little%20Scheme...

Re:What does the ??!??! operator do in C? by dahfizz on Thursday October 06, 2022 @11:05AM (#33109147)
What is with the gay sailor condom ad? You're being completely ridiculous.

I'm glad you enjoy Forth so much, I guess. I'm sure postfix will catch on any day now.

Re:What does the ??!??! operator do in C? by coldpie on Thursday October 06, 2022 @10:09AM (#33108346)
I agree, but I'm still cracking open that page when I'm reading someone else's code. I guess you work solo most of the time?
Re:What does the ??!??! operator do in C? by dahfizz on Thursday October 06, 2022 @11:07AM (#33109184)
Nope, I work on a team. I guess we all have similar instincts about what is readable.
Re:What does the ??!??! operator do in C? by mrguyorama on Thursday October 06, 2022 @11:56AM (#33109902)
I don't know what it is with C programmers and programming "terseness". It hasn't been the 60s since the 60s, and you have gobs of memory available, your source code can have syntactic sugar for the purpose of readability and the world won't end.
Re:What does the ??!??! operator do in C? by dahfizz on Thursday October 06, 2022 @12:54PM (#33110797)
Can you give an example of syntactic sugar in a modern language that makes order of operations a non-issue?
Re:What does the ??!??! operator do in C? by rdlw on Thursday October 06, 2022 @05:49PM (#33114533)
Parentheses
Re:What does the ??!??! operator do in C? by dahfizz on Thursday October 06, 2022 @05:55PM (#33114597)
Yeah, that's why I said

> Just use parentheses

Not sure what that has to do with memory usage..?

Re:What does the ??!??! operator do in C? by rdlw on Thursday October 06, 2022 @06:15PM (#33114815)
Just to clarify, I'm not the original person you replied to, and we all agree about using parentheses.

mrguyorama just implied that the only reason you would check the operator precedence chart would be to shave a few bytes off the size of your source code, which has not been a reasonable reason to do anything for many decades, and yet C programmers seem to like to do it anyway.

Re:What does the ??!??! operator do in C? by 1-more on Friday October 07, 2022 @01:18PM (#33124264)
These aren't syntactic sugar, but formatters. I rather like Ormolu for Haskell and elm-format for Elm. I occasionally type a bunch of parenthesis so that I'll for sure have the right order of operations. Then the format on save removes the redundant ones. It's delightful. The typecheckers and tendency to wrap primitives in a semantically significant constructor help with that.
Re:What does the ??!??! operator do in C? by belter on Thursday October 06, 2022 @07:59AM (#33107104)
Can I up vote for first paragraph, and down vote the second? :-)
Re:What does the ??!??! operator do in C? by benj111 on Thursday October 06, 2022 @08:14AM (#33107239)
Isn't that what brackets are for?

Well that's what I do. If you're having to look it up to write it, you're going to have to look it up to read it again down the line.

Re:What does the ??!??! operator do in C? by zh3 on Thursday October 06, 2022 @01:05AM (#33104572)
Just checked my first edition K&R (copyright date 1978, last page number is 228 (end of index) after which there is a single tearout page for other "High Quality C and Unix system titles" from Prentice Hall. There's also a front section that has about 10 pages in roman numerals (2 pages of prefix starting with 'ix') so about 240 pages total.

Page 1 starts: "Chapter 0: Introduction".

Re:What does the ??!??! operator do in C? by checkyoursudo on Thursday October 06, 2022 @05:27AM (#33106262)
Page 1? What, it's not zero indexed?
Re:What does the ??!??! operator do in C? by DonHopkins on Thursday October 06, 2022 @07:44AM (#33106994)
It looks like it's 1-indexed, but it core dumps when you get to the last page.