Ternary expressions

Are they niggerlicious, or divine intellect?

Attached: ternary.png (449x359, 13K)

They're just a cute syntactic sugar.

condition1?dosomething:condition2?dosomethingelse:condition3?doanotherthing:condition4?doanother:another

It's just a if else that can evaluate and return something.
It can actually be pretty practical.

This I used to never use them until I tried a functional language and now I use them all the time in C. It's so nice to have a conditional that returns a value, even if you only use it for short expressions.

printf("%d is %s\n", x, x % 2 == 0 ? "even" : "odd");

>printf("%d is %s\n", x, x % 2 == 0 ? "even" : "odd");
That's nice.

String t = guessCount

Literally just a regular if in a sane language
(if foo bar baz)
if foo then bar else baz end

can you do switch statements with that?

You should have learned it's the "conditional operator" in your introductory computer science class.

Anyway, very useful in Java. A nice, simple, readable way to handle all the nulls that the retard caller passed to your method. Great crutch for people used to functional who are writing in C. Highly recommend.

They're super helpful in both eliminating verbosity and in getting my more dogmatic coworkers to start foaming at their mouths

even better is:
printf("%d is %s\n", x, x % 2 ? "odd" : "even");

It's the only thing I miss when using a language without it.

thats how AI works thats how your brain work

Ternary expressions keep your code clean when all you need to do is assign or return a value. If you use a nested ternary I’ll kill your entire family.

It depends on the language. If it has a huge emphasis on immutable variables, chances are it will support returning values from blocks.
Kotlin and Rust are examples I know.

What do you mean?

People who can't understand ternary expressions should just do the gene pool a favor and end themselves. It's literally the same as and if then else statement except character differences.

i see, so this kind of stuff wasnt really fleshed out in most programming languages.

>* There is no question-colon operator.
certainly not divine intellect

>It's literally the same as and if then else statement except character differences.
It's not. One is a statement and one is an expression. If you can't understand the difference end yourself.

ideally if, for, and while should be proper functions

They are in good languages, too many there weren't many good languages created in the last few decades.

neither of those so i guess we need a quadary expression on a ternary value

given they are basically the only if exprs you'll get in a shitload of crappy languages, very based. I don't understand complaints about "nested ternaries" as if they are any harder to read than properly formatted if/elif/else statements

Noob question. How is this different from an if/else? Is it just more concise or is there some functional difference I'm missing?

Attached: ydm882n0qjs11.png (375x391, 209K)

literally the only diff in langauges C inspired is the difference between a statement that can't be an rval where a ternary can be since its an expression.

x == 1? "one"
x == 2? "two"
x == 3? "three"
.
.
.

Right, but now you're making multiple comparisons until you find a match, whereas a switch would use a hashing function and make only one comparison.

Niggerlicious as fuck. We already have the tools to type and tools to optimize the shit out of what we typed. Why Break your own head over some arcane script instead of creating semantic, easily readable kode?

>can you do switch statements with that
Switch statements are just that. Equality comparison between your argument and a "case" constant. There's no reason to shoehorn this into switch statements.

not gonna make it

I already did. C is the only tool I will ever need and clion is the only IDE i will ever need.

They're fine in moderation.

> Switch statements are just that. Equality comparison between your argument and a "case" constant.
Switch statements are not just "if-then-else", they use a lookup table.

And what does a look up table boil down to?

A single bounds check and a relative jump. Are you computer illiterate?

Are you?

it's a poor workaround of C for if-else not being an expression, which was a common thing in languages at that time

by "proper functions" you mean expressions

put ALGOL 60 to the list of the examples, the concept of blocks returning values in imperative languages is really ancient and predates C by over a decade

Feels satisfying to write if/else in a single expression but considerably harms readability. Best left unused or out of languages alltogether.

It leads to bad code, since you should never put yourself ina position where they are usefull, outside of UI stuff, but they are not a huge problem

>not grouping with parentheses
Next hing you'll be telling be is that single line lambdas lead to bad code as well.

1.
#define conout = ST->BootServices->ConOut
EFI_Status = conout->SetMode(conout, 1); if(EFI_ERROR(EFI_Status) ? return EFI_Status : conout->OutputString(conout, L"Changed to text mode number 1 successfully.\n\r");

or (2.):
#define conout = ST->BootServices->ConOut
EFI_Status = conout->SetMode(conout, 1);
if (EFI_ERROR(EFI_Status) {
return EFI_Status;
} else {
conout->OutputString(conout, L"Changed to text mode number 1 successfully.\n\r");
}
which one do you prefer

Neither. I don't use C-influenced shitlangs.

Attached: 486edc0a7520d0c681e664116bd517c3.png (551x491, 261K)

Good luck using Java, Python or anything else for developing for EFI you brainlet (unless it's C++)

All of the bottom-of-the-barrel garbage you listed is C-influenced.

what do you use then

The distinction between statements and expressions is arbitrary. In a sane lang, the if expression serves the same role as this.

Lisp.

third one when you don't unnecessarily nest the valid paths
#define conout = ST->BootServices->ConOut
EFI_Status = conout->SetMode(conout, 1);
if (EFI_ERROR(EFI_Status) {
return EFI_Status;
}
conout->OutputString(conout, L"Changed to text mode number 1 successfully.\r\n");

this

niggerlicious syntax for if-statements

Work-around in shit languages where expressions aren't values.

Broke: Ternary operator
Woke: Array index operator

#include
char* select(bool choice) {
return (char*[]){"World!","Hello, "}[choice];
}

Attached: Trump-grin.jpg (350x261, 26K)

>Work-around in shit languages where if-statements aren't expressions.
ftfy

Why would they be niggerligious?
In fact, they are much better than if-else statements.

Based

>In fact, they are much better than if-else statements.
in what way
string s = cond : "true" ? "false";
string s = if cond { "true" } else { "false" };

I don't see if-else being any worse. Plus it can contain statements and nesting isn't madness.

In a sane language, compound statements are just expressions.

This, except its 0 tries, not 0 try.

All of this. Lisp and Algol 68 did this before C and that ternary syntax were invented.

Attached: A37L68.gif (3445x2342, 225K)