http://qs1969.pair.com?node_id=11127986


in reply to Re: Situation where warning "Found = in conditional, should be" seems obsolete (documentation)
in thread Situation where warning "Found = in conditional, should be" seems obsolete

> what do you mean by "named being conditional" and how could the description be clearer?

This problem is borrowed from C, which was one of the templates for designing Perl

"Conditional operator" seems to be the original term for the "ternary operator"

I have an almost original copy of Kernighan/Ritchie in my bookshelf - though in German - and it's introduced as "Conditional Validation" ("Bedingte Bewertung")

I agree with you that the name is unfortunate and I've never heard using it in Perl's context. "Ternary Operator" is the "normal" term.

I'd suggest:

changing the title to "Ternary Operator" and appending an example exemplifying the analogy to if-then-else

https://perldoc.perl.org/perlop#Conditional-Operator

* Ternary Operator

Ternary "?:" is like the conditional operator in C.

It works much like an if-then-else. ... yadda yadda ..

$max = ($a > $b) ? $a : $b

has the same effect like

$max = do { if ($a > $b) {$a} else {$b} }

I'd also add similar code examples to and , && , or and ||

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^3: Situation where warning "Found = in conditional, should be" seems obsolete (documentation - C terminology)
by rsFalse (Chaplain) on Feb 06, 2021 at 19:42 UTC
    I agree with you.
    You gave a good answer instead of me :)
    >>what do you mean by "named being conditional"
    I mean that when I press CTRL+F and ask for "condit..." in perlop it didn't land into 'and', 'or' sections.
    By the way a warning warns about '=' been found inside "conditional", so an operator 'and' worked with "conditional". Sorry if I'm not pretty good at understanding english.

    And how about replacing infamous variable names '$a' and '$b' with foo/bar or so.

    UPD.: I changed my mind and now I disagree with '?:' naming 'Ternary operator' and suggest explicitly name it 'Ternary conditional operator'. Because I think that the name 'ternary' is too abstract and meaningless (it only says about how much operands it operates on). OK, it is the only ternary operator by now, but why not future Perl include other ternary operators?!
      Terminology is not easy if it involves history and parallels to other (normative) languages.

      see also https://en.wikipedia.org/wiki/Conditional_operator

      The Conditional operator is supported in many programming languages. This term usually refers to ?: as in C, C++, C#, Python, and JavaScript.

      However, in Java, this term can also refer to && and ||

      When Perl was born, C-programmers where one of the main target groups.

      But as you see "Java" is doing it like you suggested.

      And in Perl it's not only that

      • and has the same "flow control" like if
      but also
      • if returns a value like the operand and

      As I said, both are implemented with the same OP-Code.

      edit

      At the same time we want documentation to stay concise, otherwise it's considered "too complicated"

      I think adding an extra section "Control flow in conditional operators" with these deeper informations and linking to it from ?: and && or || might solve the issue.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        Do '&&' and '||' short-circuit in C?

        >>if returns a value like the operand and

        Ye, I was surprised, when if returned the result of its conditional (because it was false) and didn't proceeded to a sencence! (The long discussion about this finding was here: printing unitialized value of the 'do BLOCK')