Re:What's New in C# 14: Null-Conditional Assignments
by peterashford on Wednesday September 17, 2025 @09:32PM
(#45283845)
I'm a Java fan so I'm contractually required to dis c#, but actually I kinda like this. It reduces boilerplate. Yes, it could be abused but this is what code review is for.
[ Parent
| on HN ]
Re:What's New in C# 14: Null-Conditional Assignments
by moomin on Thursday September 18, 2025 @12:08AM
(#45285267)
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.
Re:What's New in C# 14: Null-Conditional Assignments
by ffsm8 on Thursday September 18, 2025 @01:04AM
(#45285635)
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
by hahn-kev on Thursday September 18, 2025 @02:46AM
(#45286323)
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.
Re:What's New in C# 14: Null-Conditional Assignments
by ffsm8 on Thursday September 18, 2025 @03:03AM
(#45286460)
That's a great point I didn't think about. From that perspective, it does make sense.
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
by moomin on Thursday September 18, 2025 @03:27AM
(#45286623)
My take is that it’s pretty minor. Modern C# has across the board null checking and for the most part you’re not designing things where this even comes up. You are, however, correct, in that I have 100% seen the ?SetName thing used by devs who just wanted to make the null checker go away and didn’t actually think about what the correct behaviour was.
Re:What's New in C# 14: Null-Conditional Assignments
by rkomorn on Thursday September 18, 2025 @01:40AM
(#45285869)
As someone who comes from a language with no ? (or equivalent) who only dabbles in C#, it actually seemed a little weird to me that this was one of the contexts where it wasn't usable.
So as a casual observer, I'd say it brings more consistency.
But also as a casual observer, my opinion is low-value.
Re:What's New in C# 14: Null-Conditional Assignments
by fakwandi_priv on Thursday September 18, 2025 @01:43AM
(#45285883)
The point the article is trying to make is that it reduces boilerplate, wouldn't be surprised if this gets added to TS in the next year of two.
Re:What's New in C# 14: Null-Conditional Assignments
by pjmlp on Thursday September 18, 2025 @03:47AM
(#45286791)
Why the requirement, because of J++ and how Ext-VOS alongside Cool became .NET?
Most companies don't care about this kind of stuff.
I work across Java, C#, JS/TS, C++, SQL, and whatever else might be needed, even stuff like Go and C, that I routinely criticise, because there is my opinion, and then there is the job market, and I rather pay my bills.
Re:What's New in C# 14: Null-Conditional Assignments
by cemdervis on Thursday September 18, 2025 @06:32AM
(#45287938)
Reminds of something I read somewhere: "I don't love Java, but I love the house it bought me."
Re:What's New in C# 14: Null-Conditional Assignments
by pjmlp on Thursday September 18, 2025 @07:00AM
(#45288133)
Indeed. :)
Re:What's New in C# 14: Null-Conditional Assignments
by peterashford on Thursday September 18, 2025 @11:26PM
(#45297649)
Yeah, I work with lots of languages too. Including c#, as it happens.
It was a joke.