CodeSOD: To Coalesce a Null

This post was originally published on this site

The Daily WTF

As we all know, managing null values is its own challenge, especially when you’re working in a functional style. So as languages like .NET add functional approaches like LINQ extension methods, they also add null coalescing operators and nullable types, making it easy to pass values around without getting surprised by an unexpected null.

Unless you’re whoever wrote the code that Abbie found, because they’ve managed to keep some surprises.

List<SomeObjects> someObjects; using (var session = dataStore.OpenSession()) { someObjects = session.Query<SomeObjects>().OrderBy(s => s.PrimaryKey).ThenBy(s => s.EventDateLocal).ThenBy(s => s.SystemTransactionDateTimeUtc).ToList(); } return someOtherCollectionOfObjects .GroupJoin(someObjects, o => o.EventDates.PrimaryKey, s => s.PrimaryKey, (o, s) => { var sList = s as IList<SomeObjects> ?? s.ToList(); return new { //omitted }; })

The submitter anonymized the class names and variable names a bit, so it’s hard to see exactly what the intent is, but we can still spot the “odd” choices. The goal is to take

To read the full article click on the 'post' link at the top.