TWIL vol.3

Full article

New year, new discoveries! Here lie the things from this week that won't fill up a post. Or maybe they would and I was too lazy to try? Starting off the new year right...

So much C#, so little time

The fact is, there are too many interesting things to write about and it's impossible to write about everything! In fact, I should probably do a better job of focusing. I've spent quite a bit of time over the last 18 months covering the (somewhat) newer features in C# that might help some of us survive WinForms development, but that's only gone so far because the .NET Framework only goes so far!

While the .NET Framework is supported for the foreseeable future, per this and this the best we'll ever get is whatever's in C# 7.0 - don't expect anything newer in the .NET Framework. Luckily there's an upgrade assistant that can help migrate legacy apps to .NET 6, but MS admits near the end that "Most certainly you'll have more work to do in finishing the upgrade.". There's no way a huge legacy app is going to convert over cleanly.

What I'd like to do this year is find something (or several things) to use the upgrade assistant on, get familiar with it, maybe write a thing or two if it seems helpful, and then learn more about everything from C# 8.0 onwards. At the very least, I'd like to know more about pattern matching additions, records, and the strange new top-level statements that look so different from anything I've written in C# up til now.

Default or Null.. or both?

While I'm not on the topic at all, isn't it funny how easy it is to get thrown for a loop when someone else on the team does something a different way? It can be the tiniest thing, like using (or not using) curly braces around an "if" statement. We're creatures of habit. Oh sure, sometimes one way or the other is clearly better, but most of the time it's like loading the dishwasher. Everyone has an opinion, but in the end who cares as long as the dishes get clean?

Someone I work with prefers to use default instead of null to check for a missing value. It threw me off at first, because I'm just so conditioned to using null whenever I'm comparing something that might have no value. But then how many times have I called FirstOrDefault() over the years, literally telling the app to either hand me the first item or the default value, and then compared that to null? Wouldn't it make more sense like this?

var food = new List<Food>();
var soup = food.FirstOrDefault(x => x.Type == "Soup");

if (soup == default)
    // no soup for you

Anyway, the default literal isn't something I used before, but I read about it and it's on my radar now. In truth, you can't just replace null with default, except in a couple cases like reference types and nullable<T> since the default type for those is null. For everything else, there's a specific default type, and I can't decide which of these I'd prefer (for example)...

int grossIncome = GetGrossIncome();  // returns 0 if no income

if (grossIncome == 0)
    // you earned nothing!

if (grossIncome == default)
    // you earned nothing!

Which one do you think is easier to read and reason through?

Undiscoverable feature in Teams

We use Teams heavily at work for communication, especially since we're 100% remote. I've gotten pretty used to it over the last couple years, although there's quite a few features I've never used. But at least I know they're there.. or do I?

Someone mentioned a feature that I had no idea existed. In fact, I don't see anyway that anyone could know it existed. If you hover over the "send" button, it pops up a little title. Okay. But if you right-click on the "send" button, you get an entire little UI for scheduling to send a message in the future. Wut.

Imagine coding this thing, and maybe asking the PM, "okay, so uh, how we gonna show users this great new feature?" Maybe a small clock? Maybe an "info" icon that someone can hover over? "We won't."

Alrighty then!


Grant Winney

I write when I've got something to share - a personal project, a solution to a difficult problem, or just an idea. We learn by doing and sharing. We've all got something to contribute.

Comments / Reactions

One of the most enjoyable things about blogging is engaging with and learning from others. Leave a comment below with your questions, comments, or ideas. Let's start a conversation!