logoalt Hacker News

alkonauttoday at 8:53 AM0 repliesview on HN

The description mentions side effects such as GetNextId(), but creating that object doesn't look like it has any side effects, so perhaps not the best example.

As I wrote in another comment, ignored side effects are perhaps the one questionable aspect of it. I usually assume RHS is evaluated first, regardless of what happens on the left - but I'm not sure that mental model was actually correct. But keeping that would mean having to simply do explicit if _when_ there are side effects. So

    if (myObj is not null)
       myObj.Id = GetNextAvailableId(); // Side effect
But for non-side effects

    Settings?.RetryPolicy = new ExponentialBackoffRetryPolicy();
It's obviously hard to know when there are side effects, but that problem already existed. You could trip this up before too e.g.

    var id = GetNextAvailableId();
    if (myObj is not null)
       myObj.Id = id;
Would have tripped you up. But at least it's obvious WHY it would. Something I have long sought in C# is a good way of tracking what is pure and what isn't.