Click here to Skip to main content
15,889,992 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: I hate recent C# versions! Pin
simpelman7-Sep-22 4:26
simpelman7-Sep-22 4:26 
GeneralRe: I hate recent C# versions! Pin
Member 148844928-Sep-22 13:48
Member 148844928-Sep-22 13:48 
GeneralRe: I hate recent C# versions! Pin
Steve Naidamast7-Sep-22 4:34
professionalSteve Naidamast7-Sep-22 4:34 
GeneralRe: I hate recent C# versions! Pin
Samuel Estrella C.7-Sep-22 5:10
Samuel Estrella C.7-Sep-22 5:10 
GeneralRe: I hate recent C# versions! Pin
Bruce Greene7-Sep-22 5:17
Bruce Greene7-Sep-22 5:17 
GeneralRe: I hate recent C# versions! Pin
Andre_Prellwitz7-Sep-22 5:46
Andre_Prellwitz7-Sep-22 5:46 
GeneralRe: I hate recent C# versions! Pin
jochance7-Sep-22 6:11
jochance7-Sep-22 6:11 
GeneralRe: I hate recent C# versions! Pin
David On Life7-Sep-22 6:27
David On Life7-Sep-22 6:27 
Actually, I like and use many of the new enhancements. Some of them are real time savers, for example:
int x = foo?.bar?.index?[y] ?? 0;

versus:
int x = 0;
if (foo != null && foo.bar != null && foo.bar.index != null && foo.bar.index[y] != null
{
    x = foo.bar.index[y];
}

Not only was the new style code shorter and easier to write, but I would assume that it compiles down to a more efficient form because it doesn't have to keep re-evaluating the entire list of object references / pointers and only assigns a value to x once. Of course, I could write the second version to use a bunch of temporary variables and theoretically get close to the same performance, but then it would grow to be many more lines long... and still contain a bunch of redundant assignments to x that would be hard to eliminate unless I turned it into a local function (that's a lot of extra code authoring versus the nice simple, efficient, single line).

I also think the first version is easier to read. I like the simplicity of a single ? for a null check and the double ?? for a default value.

I've also used the is/as construct as a time saver and really like some of the new switch statement options and scoping, and some of the new code shortcuts (like using get => x; instead of get { return x; }

I particularly like putting them together for properties, for example writing public int count { get => mylist?.Count ?? 0; } is a lot easier (and clearer) than having to write out the null check. And while it might take a little bit to get used to, it's fairly intuitive (if I'd never seen it before, I'm pretty sure I'd still be able to figure out what it means just by the context).

I can't say I'm a fan of every change, and I tend to lag (if only because I don't like to depend on the latest compiler when I'm working on a team, I try to give everyone time to get on the new compiler). However, the compiler hints do often push me toward the new options when it suggests them as ways to 'improve' my code... (sometimes I like that, and sometimes I don't...)
GeneralRe: I hate recent C# versions! Pin
Dave B 20227-Sep-22 6:34
Dave B 20227-Sep-22 6:34 
GeneralRe: I hate recent C# versions! Pin
jochance7-Sep-22 7:26
jochance7-Sep-22 7:26 
GeneralRe: I hate recent C# versions! Pin
ShawnVN7-Sep-22 9:48
ShawnVN7-Sep-22 9:48 
GeneralRe: I hate recent C# versions! Pin
Dan Sutton7-Sep-22 11:02
Dan Sutton7-Sep-22 11:02 
GeneralRe: I hate recent C# versions! Pin
BotReject8-Sep-22 6:12
BotReject8-Sep-22 6:12 
GeneralWSO CCC OTD 6th September, 2022 Pin
Kornfeld Eliyahu Peter5-Sep-22 22:06
professionalKornfeld Eliyahu Peter5-Sep-22 22:06 
GeneralRe: WSO CCC OTD 6th September, 2022 Pin
pkfox5-Sep-22 22:07
professionalpkfox5-Sep-22 22:07 
GeneralRe: WSO CCC OTD 6th September, 2022 Pin
Kornfeld Eliyahu Peter5-Sep-22 22:11
professionalKornfeld Eliyahu Peter5-Sep-22 22:11 
GeneralRe: WSO CCC OTD 6th September, 2022 Pin
MarkTJohnson6-Sep-22 1:16
professionalMarkTJohnson6-Sep-22 1:16 
GeneralRe: WSO CCC OTD 6th September, 2022 Pin
FreedMalloc6-Sep-22 7:09
FreedMalloc6-Sep-22 7:09 
GeneralOi! Kornfeld Eliyahu Peter! Pin
OriginalGriff5-Sep-22 22:02
mveOriginalGriff5-Sep-22 22:02 
GeneralRe: Oi! Kornfeld Eliyahu Peter! Pin
Kornfeld Eliyahu Peter5-Sep-22 22:05
professionalKornfeld Eliyahu Peter5-Sep-22 22:05 
GeneralOi! Kornfeld Eliyahu Peter! Pin
OriginalGriff5-Sep-22 20:38
mveOriginalGriff5-Sep-22 20:38 
GeneralRe: Oi! Kornfeld Eliyahu Peter! Pin
Sander Rossel5-Sep-22 21:06
professionalSander Rossel5-Sep-22 21:06 
GeneralRe: Oi! Kornfeld Eliyahu Peter! Pin
OriginalGriff5-Sep-22 21:26
mveOriginalGriff5-Sep-22 21:26 
GeneralWordle 444 Pin
Vivi Chellappa5-Sep-22 11:48
professionalVivi Chellappa5-Sep-22 11:48 
GeneralRe: Wordle 444 Pin
StarNamer@work5-Sep-22 13:16
professionalStarNamer@work5-Sep-22 13:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.