What's New in C# 14: Null-Conditional Assignments
91–100 of 174 posts
Re: What's New in C# 14: Null-Conditional Assignments
#92It's starting to feel like C# is going down the path of C++. Tons of features that introduce subtleties and everybody has their own set of pet features they know how to use. But the code gets really hard to understand when you encounter code that uses a subset you aren't familiar with. I remember staring at C++ codebases for days trying to figure out what is going on there. There was nothing wrong with the code. I ju…
Static abstract methods are probably the feature I see used least (so far!) and they’re not nearly as hard to understand as half of the stuff in a recent C++ standard.
Re: What's New in C# 14: Null-Conditional Assignments
#93Earlier quoted context omitted.
From the article as well: Side-Effect Prevention When a null-conditional statement assignment is evaluated, the right-hand side of the expression is not executed unless the left-hand side is defined.
Thanks. I missed it. I really dislike that, because it hides the control flow too much. Perhaps I'm biased by Racket, where it's easy to define something weird using macros, but you should not do unexpected weird things. For example you can define vector-set/drop that writes a value to a position of a vector, but ignores the operation when the position is outside the vector. For example (vector-set/drop v -2 (print "…
Re: What's New in C# 14: Null-Conditional Assignments
#94Cute, but is this actually needed? It's one more thing to remember, one more thing to know the subtleties of, and for what? To save writing a very readable and unambiguous line of code? It feels like the C# designers have a hard time saying "no" to ideas coming their way. It's one of my biggest annoyances with this otherwise nice language. At this point, C# has over 120 keywords (incl. contextual ones) [0]. This is a…
Nothing is stopping you from constraining the language version you want to be used in your projects: https://learn.microsoft.com/en-us/dotnet/csharp/language-ref... You can force it all the way down to ISO-1/2. If this is still insufficient, then I question what your goals actually are. Other people using newer versions of C# on their projects shouldn't be a concern of yours.
Obviously you’re not alone to disagree, and there are even some good arguments you could potentially be making. But to say “I question what your motives really are” and tell someone what they should be concerned with is… odd?
It’s a very common position with ample practical examples. While there certainly are valid counter arguments, they are a little more involved than “nothing is stopping you.” There is. Collaborating with others, for example.
Re: What's New in C# 14: Null-Conditional Assignments
#95Earlier quoted context omitted.
You’re not wrong. Every language feature that gets added there’s someone who wants to stop the clock and hold the language definition in place because “people might misuse it” or “people might not be familiar with it”. It’s not language specific, it’s everywhere.
Still, enabling ?. Access on the left side of the equals (assigning) feels like a serious anti pattern to me I struggle to even see how anyone would prefer that over an explicit if before assigning. Having that on the right side (attribute reference) is great, but that was already available as far as I understood the post...
Re: What's New in C# 14: Null-Conditional Assignments
#96Null conditional assignment is bunk. When you have an expression P which names a mutable place, and you execute P := X, the contract says that P now exhibits the value X, until it is assigned another value. Conditional assignment fucks this up. When P doesn't exist, X is not stored. (Worse, it may even be that the expression X is not evaluated, depending on how deep the fuckery goes.) Then when you access the same ex…
This isn't the case, though, is it? A normal member access (or indexer) expression may point to a mutable location (field, property). However, with conditional access expressions you get either a member access _or nothing_. And that nothing is not a mutable place.
When you use any of the conditional operators, you split the following code into two paths, and dropping the assignment (since there's nothing to assign to) seems pretty consistent to me, since you'd also drop an invocation, or a property evaluation in similar expressions.
If you require P to point to something that actually exists because you want the assignment to succeed, then write code to ensure that P exists because the assignment has no way of knowing what the intention was on the left side.
Re: What's New in C# 14: Null-Conditional Assignments
#97Null conditional assignment is bunk. When you have an expression P which names a mutable place, and you execute P := X, the contract says that P now exhibits the value X, until it is assigned another value. Conditional assignment fucks this up. When P doesn't exist, X is not stored. (Worse, it may even be that the expression X is not evaluated, depending on how deep the fuckery goes.) Then when you access the same ex…
And we all get to choose what we find ridiculous:
i = i + 1 ? No it does not. Never has, never will.
Connection is null? It's insane to type it as Connection then. null has type Null.
Re: What's New in C# 14: Null-Conditional Assignments
#98Earlier quoted context omitted.
Still, enabling ?. Access on the left side of the equals (assigning) feels like a serious anti pattern to me I struggle to even see how anyone would prefer that over an explicit if before assigning. Having that on the right side (attribute reference) is great, but that was already available as far as I understood the post...
Without it there's some silly inconsistency. For example I could call `person?.SetName(name)`, but if you wanted to refactor that into `person?.Name = name` you can't.
Maybe my feeling is just rooted in the fact I've never used a language which allowed ?. on assignment
Re: What's New in C# 14: Null-Conditional Assignments
#99Cute, but is this actually needed? It's one more thing to remember, one more thing to know the subtleties of, and for what? To save writing a very readable and unambiguous line of code? It feels like the C# designers have a hard time saying "no" to ideas coming their way. It's one of my biggest annoyances with this otherwise nice language. At this point, C# has over 120 keywords (incl. contextual ones) [0]. This is a…
Re: What's New in C# 14: Null-Conditional Assignments
#100I don't really get this obsessive insistence of purging the language of null checks. (And "if(x is not null)" is not an improvement of any kind) It feels like Microsoft just wants C# to be Python or whatever and the language is losing its value and identity. It's becoming bland, messy, and complicated for all the same reasons they keep increasing padding between UI elements. It's very "me too" and I'm becoming less a…
Oh, how happy would I be if Python had a sliver of C# features. There's nothing like null-conditionals in Python, and there are many times I miss them