What?.could?.possibly?.go?.wrong?.

    if (This) {
        if (is) {
            if (much) {
                if (better) {
                    println("I get paid by the brace")
                }
            }
        }
    }

    if (Actually 
        && Actually.you
        && Actually.you.would
        && Actually.you.would.write
        && Actually.you.would.write.it
        && Actually.you.would.write.it.like) {
            return this;
    }

Routinely dealing with that's enough to put you off programming altogether.

False dichotomy. The problem is that the syntax implements a solution that is likely wrong in many situations and pairs with a bad program design. Maybe when we have this:

  what?.could?.possibly.go?.wrong = important_value()
Maybe we want code like this:

  if (!what)
    what = new typeof(what); // default-construct representative instance

  if (!what.could)
    what.could = new typeof(what.could);


  if (!what.could.possibly.go)
    what.could.possibly.go = new typeof(what.could.posssibly.go)


  // now assignment can take place and actually retain the stored value
  // since we may have allocated what, we have to be sure
  // we propagate it out of here.

  what.could.possibly.go.wrong = important_value();

and not code which throws away the value (and possibly its calculation).

Why would you ever write an assignment, but not expect that it "sticks"? Assignments are pretty important.

What if someone doesn't notice the question marks and proceeds to read the rest of the code thinking that the assignment always takes effect? Is that still readable?

> Maybe we want code like this

It should be clear enough that this operator isn't going to run 'new' on your behalf. For layers you want to leave missing, use "?.". For layers you want to construct, use "??=".

> Why would you ever write an assignment, but not expect that it "sticks"? Assignments are pretty important.

If you start with the assignment, then it's important and you want it to go somewhere.

If you start with the variable, then if that variable doesn't have a home you don't need to assign it anything.

So whether you want to skip it depends on the situation.

> What if someone doesn't notice the question marks and proceeds to read the rest of the code thinking that the assignment always takes effect? Is that still readable?

Do you have the same objection with the existing null-conditional operators? Looking at the operators is important and I don't think this makes the "I didn't notice that operator" problem worse in a significant way.

Just because you can't do assignments like that, it doesn't mean you shouldn't use null coalescing for reads. What exactly could go wrong?

Paranoid null checking of every property dereference everywhere (much?.like?.in ?.my?.joke) whether each is ever possibly null or not, usually combined with not thinking through what the code behavior should be for each null case.

(Gets a lot better if you enable nullable references and upgrade the nullable reference warnings to errors.)

NullReferenceException, in line 7.

you didn't null check possibly.go.

Rather, what I didn't null check is "possibly". That's because it doesn't have a question mark in the original expression that I'm starting from.

I wonder, does the important_value function get called and the value discarded or never called at all? Looks like a footgun if it has side-effects.

Not calling the function would be evidence of further derangement in the design.

Such a thing has been perpetrated in C. In C, you can repeat designated initializers. like

  foo f = { .a = x(), .a = y() }
The order in which the expressions are called is unspecified, just like function arguments (though the order of initialization /is/ specified; it follows initialization order).

The implementaton is allowed to realize that since .a is being initialized again by y(), the earlier initialization is discarded. And it is permitted not to emit a call to x().

That's just like permitting x() not to be called in x() * 0 because we know the answer is zero.

Only certain operators in C short-circuit. And they do so with a strict left-to-right evaluation discipline: like 0 && b will not evaluate b, but b && 0 will evaluate b.

The initializer expressions are not sequenced, yet they can be short-circuited-out in left-to-right order.

Consistency? What's that ...

  if (!same) {
    return;
  }

  if (!number) {
    return;
  }

  if (!of_braces) {
    return;
  }

  println("but easier to read")

Yes, you should definitely unnest functions and exit early. But the null-coalesced version is shorter still.

Nothing to worry about:

  What?.could?.possibly?.go?.wrong?
Not so convinced:

  What?.could?.possibly?.go?.wrong = important_value()
Maybe the design is wrong if the code is asked to store values into an incomplete skeleton, and it's just okay to discard them in that case.

[dead]