Live data from Hacker News

What's New in C# 14: Null-Conditional Assignments

blog.ivankahl.com

71–80 of 174 posts

Re: What's New in C# 14: Null-Conditional Assignments

#71
Cute, 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 almost twice as much as Java (68) [1], and 5 times as much as Go (25) [2]. And for what? We're trading brevity for complexity.

[0]: https://learn.microsoft.com/en-us/dotnet/csharp/language-ref... keywords/

[1]: https://en.wikipedia.org/wiki/List_of_Java_keywords

[2]: https://go.dev/ref/spec#Keywords

Re: What's New in C# 14: Null-Conditional Assignments

#72

I’m having a hard time imagining where this is useful. If I’m trying to assign to a property, but encounter an intermediate null value in the access chain, just skipping the assignment is almost never going to be what I want to do. I’m going to want to initialize that null value.

[deleted]

Re: What's New in C# 14: Null-Conditional Assignments

#73
post #48

Is .NET entering its twilight years as a tech people build new things with? I just can't imagine Gen Z wanting to start a project in C#. I realise there are still .NET shops, and I still talk to people who do it daily, but ours is a field driven by fashion whether we care to admit or not - and C# just does not feel as fashionable as it once did (I'm a former C# dev, up until 2020)

I've been using .Net for almost 20 years, professionally for half that time, and I feel like excitement and momentum in the community has only been increasing.

Same story here. I decided lately to focus more on .net and, let's say, abandon Java.

It's portable, fast, productive and well supported by a massive corp. It's not just a "language du jour", it's here to stay.

There are plenty of job in dotnet where I live: old, new, startups...

I am the momentum!

Re: What's New in C# 14: Null-Conditional Assignments

#74

I’m having a hard time imagining where this is useful. If I’m trying to assign to a property, but encounter an intermediate null value in the access chain, just skipping the assignment is almost never going to be what I want to do. I’m going to want to initialize that null value.

[deleted]

Re: What's New in C# 14: Null-Conditional Assignments

#75
post #70

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.

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

#76
post #36

Earlier quoted context omitted.

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) wh…

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.)

Re: What's New in C# 14: Null-Conditional Assignments

#77
post #53

Is .NET entering its twilight years as a tech people build new things with? I just can't imagine Gen Z wanting to start a project in C#. I realise there are still .NET shops, and I still talk to people who do it daily, but ours is a field driven by fashion whether we care to admit or not - and C# just does not feel as fashionable as it once did (I'm a former C# dev, up until 2020)

I personally can't think of an all-rounder language that is better than C#. It's fast, has great tooling, powerful, extremely productive for working with large code bases and runs 'anywhere'. JS has lost against TS which is basically C# for web (both designed by the same person) and Python is not really something you should build large applications with (execution speed + maintenance issues). What do you believe is t…

Golang is often the default now. As someone who’s new to backend development, I’ve been exploring C# and can’t understand why it’s not the default. I think C# primarily has a marketing problem.

Re: What's New in C# 14: Null-Conditional Assignments

#78

Is .NET entering its twilight years as a tech people build new things with? I just can't imagine Gen Z wanting to start a project in C#. I realise there are still .NET shops, and I still talk to people who do it daily, but ours is a field driven by fashion whether we care to admit or not - and C# just does not feel as fashionable as it once did (I'm a former C# dev, up until 2020)

Well, JavaScript is older than C# and still poppin. Gen Z eats it up. C# too, for unity gamez.

Re: What's New in C# 14: Null-Conditional Assignments

#80
This sounds like a shortcut, unless it isn't.

I have a feeling this is going to make debugging code written just a few months ago incrementally difficult. At least the explicit if statements are easier to follow the intent from months ago.

The syntax is clean though. I'll give it that.

Post reply on HN