1

Some programming languages allow conditional value assignments that look like

  x = (IF condition THEN a ELSE b)

My search-fu is failing me: how do we call such statements in the jargon of programming languages?

It evokes functional programming, though some imperative languages achieve the same with a "ternary operator". In order to find relevant documentation for my favorite languages, I would really love to know the proper vocabulary!

Thanks a lot

Deleplace
  • 143
  • 1
  • 2
    I don't think there is an industry-accepted term for this. You should consult the docs for which ever language you are writing in. They might have a term for it. – Greg Burghardt Dec 29 '20 at 21:05
  • 3
    Conditional expression would be an appropiate term – Mat Dec 29 '20 at 21:12
  • 2
    The term is specific to the programming language. C# calls it the ["ternary conditional operator,"](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-operator) but Java calls it a ["conditional expression"](https://www.inf.unibz.it/~calvanese/teaching/05-06-ip/lecture-notes/uni05/node17.html). Check the documentation for your specific programming language. – Robert Harvey Dec 29 '20 at 21:52
  • @RobertHarvey, the very first words of your C# link make clear that the preferred name in that language is the "conditional operator", and that goes back even to K&R C. As I say in my answer, "ternary" often wrongly makes an appearance in the name! – Steve Dec 29 '20 at 22:19
  • 2
    I stand by my statement. It's *language-specific;* check the documentation for your particular language. – Robert Harvey Dec 29 '20 at 22:21
  • 1
    "In order to find relevant documentation for my favorite languages" - Here's a bit of a search-fu practical advice; in order to avoid terminology issues, if you know the name in one language, just search for something like "ternary operator in java" or "ternary operator equivalent in python" or "ternary conditional expression in scala", etc. - you'll likely get results that will tell you what's the syntax, and what's it called in that language. They'll often include a link to the official documentation as well. – Filip Milovanović Dec 30 '20 at 05:56
  • What searching? Do you know that research effort should be reflected in questions? Have you read the voting arrow mouseover texts? Do you know that a mere statement that you searched is noise that doesn't belong in questions? (Also greetings, thanks, etc.) [ask] [help] Do you know that double quote is a google meta-character? Have you researched searching? How did the Wikipedia article not answer this? – philipxy Dec 30 '20 at 08:16

2 Answers2

1

My search-fu is failing me: how do we call such statements in the jargon of programming languages?

We don't. It's an expression, not a statement. If it were a statement, it wouldn't have a value. (Unless by "such statements" you are referring to the assignment?)

In order to find relevant documentation for my favorite languages, I would really love to know the proper vocabulary!

You will have to look at the documentation for your favorite languages, then. Different language communities come up with different terms for pretty much everything. (E.g. "member function" in C++, "method" in Java, and "routine" in Eiffel are all the same thing whereas "method" in Java and "method" in CLU are different things, and "function" in C and "function" in Pascal are different things.)

Jörg W Mittag
  • 101,921
  • 24
  • 218
  • 318
-2

I'm a full-time functional programmer, and have usually heard it called simply "an if expression," as opposed to an if statement. Expressions return values whereas statements are executed for their side effects.

Unfortunately, imperative programmers often use "expression" and "statement" almost interchangeably, so it's probably not a universally recognized term.

Karl Bielefeldt
  • 146,727
  • 38
  • 279
  • 479
  • 3
    This imperative programmer knows the difference between an "expression" and a "statement." – Robert Harvey Dec 29 '20 at 22:20
  • Most do know the difference if you ask them directly, but every day usage still gets sloppy. It's similar to distinguishing between functions, methods, and procedures. People know the distinction, they just don't always care to make it. – Karl Bielefeldt Dec 29 '20 at 22:23
  • I dare say imperative programmers know that a statement *may or may not be* an expression! – Steve Dec 29 '20 at 22:23
  • Even OP called it an "expression that returns a value" as if "expression" by itself wasn't a sufficient explanation. – Karl Bielefeldt Dec 29 '20 at 22:25
  • @KarlBielefeldt, my understanding is that an expression does not necessarily have to return a value (at least in the sense that an absence of values, void or unit, is not itself considered to be a value). The OP was likely just being emphatic about what kind of expression he had in mind, since he is apparently unsure of terminology in this area, and the English word "expression" has a broader meaning. – Steve Dec 29 '20 at 22:57