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

7
  • 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," but Java calls it a "conditional expression". Check the documentation for your specific programming language. – Robert Harvey Dec 29 '20 at 21:52
  • 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 5:56
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.)

-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.

5
  • 2
    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

Not the answer you're looking for? Browse other questions tagged or ask your own question.