5 ms·
If we're doing "provoke arguments on the internet using confusingly-stated constructs", they should have some self respect and use the venerable 6÷2(1+2). And
by grues-dinner 2y ago
If we're doing "provoke arguments on the internet using confusingly-stated constructs", they should have some self respect and use the venerable 6÷2(1+2).
And then read https://xkcd.com/169/ https://xkcd.com/169/
Anyway, I'm sure there'll be a YouTube video about this with an AI voiceover soon.
- MrMcCall 2y agoThat's why I always use parentheses, i.e. I never rely on operator precedence. Therein lie troubles, lad. And, as usual, the xkcd is fantastic.
- FabHK 2y agoYou don't write 1+2+3, but (1+2)+3?
- MrMcCall 2y agoThe same operators don't need precedence rules; each language is processed left-to-right or vice versa. Usually it's left-to-right, in my experience with maybe a dozen languages professionally, maybe twice that in exploration.
- FabHK 2y agoWith the same operator, the rule is not called precedence, but associativity (left or right; consider 2^3^4 where it matters), but you still need a rule - unless you use parentheses, which you said you always do.
- MrMcCall 2y agoTouche! If there's a case where one computation needs to occur before others, then that's where I always use parens. I'm also never doing a^b^c, either as a^(b^c) or (a^b)^c, but if I did, there would be parens. Readibility in one's code is necessary for those of us who must re-read our code when we need to refamiliarize ourselves with it before making changes. It is said that programmers spend far more time reading code than writing it, and I have found that to be true. As someone who has developed large pieces of software, my strategies include clarity for the reader, who is, first of all, myself. As to what it's called, yeah, 'associativity' is the math term, but if you think I don't understand the concept, then you don't understand the depth that precedence goes to the heart of parsing source code to produce executable code. And I do understand that, friend, for four decades now.
- qsort 2y agoThey are not even remotely the same. 6÷2(1+2) is written in a deliberately confusing fashion. This is a simple math olympiad-style question. All universal quantifications on the empty set are true, for the same reason that the implication A -> B is true when A is false regardless of B. It cannot be any other way. Precedence of infix operators on the other hand is completely arbitrary, we settled on multiplication before addition because otherwise it would be a pain to write polynomials.
- grues-dinner 2y agoThe point is it's an attempt to sucker people into a fight over ambiguity over the natural readings of what looks like informal English (which can vary from person to person) vs formal logic statements predicated on a strict framework which may sound weird but actually have right answers. And it works every damn time. It might be a math Olympiad question, but a math Olympiad participant is supposed to know how, say, a vacuous truth works, and, moreover the mapping of formal English to logical operators (see also: the inclusive or) and that is not how everyone in the world will parse the statement of the problem. Is the point here to educate people on a quirk of formal logic, or is a smugbait to promote a book? Oh look, there's a book. Quelle surprise.
- frozenlettuce 2y agoThis is part of a Brazilian test - those are common for enrolling in free higher education or working in public positions. IMO one of the most vile ways of wasting the young generation's potential, as you need to be really smart to pass those exams (think 1-10000 candidate/position ratio) but too stupid to accept the position (think $500 USD monthly salary).