Welcome to the landmark tenth edition of The Catch Block!
In this edition: succinctness, LINQ, VS Code, Senior Developers, ECMAScript 2020, DNS, Westworld, and asynchronous.
Cool Reads
Writing More Succinct C# (Dan Clarke) - I went into this post with a heavy dose of skepticism, because whenever I see title like "write more succinct code" that usually translate to "write code that's much harder to read but looks cool if you don't have to maintain it." But this post blew me away, and that's why it's the only post in this section this week. His "fabricated" example (the very first screenshot of code) is undoubtedly contrived, but also clearly explains why he's writing this post and what we, as readers, are going to get out of it.
Here's that main example. He starts with this code:
public IEnumerable<ItemResult> GetItemResults(bool someCondition)
{
var items = _itemRepository.GetItems();
var results = new List<ItemResult>();
foreach(var item in items)
{
var newItem = new ItemResult();
newItem.SomeField = item.SomeField;
newItem.SomeOtherField = item.SomeOtherField;
if(someCondition)
{
newItem.YetAnotherField = item.YetAnotherFieldV1;
}
else
{
newItem.YetAnotherField = item.YetAnotherFieldV2;
}
results.Add(newItem);
}
return results;
}
Perfectly readable, in many ways, but rather long-winded. All of that can be reduced, using some judicious LINQ and a ternary operator (?:).
public IEnumerable<ItemResult> GetItemResults(bool someCondition) =>
_itemRepository.GetItems()
.Select(x => new ItemResult
{
SomeField = x.SomeField,
SomeOtherField = x.SomeOtherField,
YetAnotherField = someCondition
? x.YetAnotherFieldV1
: x.YetAnotherFieldV2
}).ToList();
Looks quite a bit better, yes?
To tell the truth, I'm still a little wary of posts like this. I firmly believe that "readability" is a function of the kinds of assumptions we as programmers have about how code should be structured and organized, and those assumptions vary greatly from person to person. I would understand if some people actually found the more explicit, less condensed first version of this code more readable than the second version. That said, I'm all for moving toward cleaner code, so I will be looking for ways to implement the ideas that Dan discusses in this post in my own code.
Seriously, read this post! You'll be glad you did.
Previews and Announcements
- Visual Studio Code April 2020
- The Latest Features Added to JavaScript in ECMAScript 2020 (Thomas Findlay) - This is more of a blog post than an official announcement, but I put it here because it discusses some very cool new stuff.
Other Quality Reads
There were a LOT of good blog posts published this past week!
- Tips for Time Management and Working From Home (Leomaris Reyes) - A lot of the stuff Leomaris suggests are things I do for my own distracted brain, to keep it on task.
- What Is a Senior Developer and How Can I Become One? (Colby Fayock)
- The invisible man in the middle: An investigative story (Oren Aini) - I love bug investigation stories that have strange endings.
- 9 things Westworld can teach us about software engineering (Tom Wright)
- Post-Build Events and .NET Core (Jeremy Clark)
- What is DNS? Domain Name System, DNS Server, and IP Address Concepts Explained (Chloe Tucker) - This should be old hat to an experienced web developer, but sometimes it's worth reminding ourselves of the basics.
- Gone Are The Days Of Vertically Sliced Stories (Tabassum Farooque Memon)
- Databases Still Store Data (Rockford Lhotka)
- Is Asynchronous The Best Way To Go in ASP.NET Core? (David Grace) - The illustrations alone make this article worth the read.
- One Secret to Quality Software (Jessica Kerr)
- SignalR in ASP.NET Core 3.1 (Shahed Chowdhuri)
- A Developer's Guide to Website Speed Optimization (Digvijay Singh)
- Get the result of multiple tasks in a ValueTuple and WhenAll (Gérald Barré)
- Life, part 7 and Life, part 8 (Eric Lippert)
Catch Up with the Previous Issue!
Thanks for reading, and we'll see you next week!