Travel to the Office – Dev Leader Weekly Issue 10

Hey there!

Welcome to ​Dev Leader​ Weekly, your dose of software engineering and C# goodness!

Friendly reminder: Courses *are* coming. By being subscribed here, you’ll know about them early and get a chance to hear more before I publish information about them more widely. Thanks for your support!


Thought-Provoking Quote of the Week:

Every week a little bit of insight from someone! Whether it’s me or something else I’ve come across to share with you, I hope you find it insightful:

“Don’t comment bad code—rewrite it.”

Brian W. Kernighan

From this quote, we can see that Kernighan advocates for clarity and understandability in code (seems to be a common theme with some of these quotes!). While comments can help explain complicated segments, they can never be a substitute for inherently clear and concise code. The argument being made here is that it’s more effective to invest time in refining and restructuring code than to explain its complexities through comments.

Code often outlives the original author’s involvement in the project. Future developers, including the original author, benefit immensely from well-structured and self-explanatory code, mitigating the need for extensive documentation and reducing the learning curve. Depending on how long you’ve been programming this may land differently but: think about a project you worked on 2+ years ago. Go back and read that code. Is it obvious or do you need to dig around for a day to understand it?

I’d argue that bad code contributes to technical debt as well. By rewriting ambiguous or convoluted code, developers address the root of the problem, preventing the accrual of interest in the form of bugs, difficulties in extension, and maintenance hurdles. If folks do not truly understand the purpose/intention of complex code, they’ll likely code things that aren’t exactly aligned with it and then you’re stuck band-aiding it going forward.

Fundamentally, following the advice in this quote really helps to nurture a culture of excellence and continuous improvement within development teams. It encourages developers to take ownership, be accountable for code quality, and cultivate best practices that lead to sustainable and scalable software development. It’s about being proactive. Don’t just slap the comment bandaid on there, figure out if you can.


Featured Content:

I had a super busy week and didn’t get my typical three full-length videos published, so I wanted to apologize for that. However, I had an amazing time getting to meet some of my Microsoft team this week and I had some travel to the office every day this week.

The extra commute and lost time during work hours meant some of my personal time had to take a back seat – but the opportunity to spend time with these people was truly priceless.

ENDLESS Possibilities – Dynamic Plugin Loading in ASP.NET Core Blazor

YouTube player

This video adds to the Blazor plugin series and discusses options for us to load plugins AFTER startup! For most of my own personal use cases, I load plugins only at startup. However, your app needs might be very different! Check it out to see how you could apply it.

​Refactoring Blazor UI Plugin Code And How We Can Use Vertical Slices​

YouTube player

Building on the last video, I refactored the project after discovering that I should have followed my own advice! The navigation menu that I continue to drop plugin examples into would ABSOLUTELY benefit from a plugin architecture. This video has a secondary message, which is: If your code is not organized well, it will make understanding plugin architectures very challenging!

One Trick To Make ASP.NET Core Blazor Plugin Loading EVEN BETTER

YouTube player

This is yet another Blazor plugin video in the multi-part series. In this video, I continue to build on some functionality that you may want to explore in your own Blazor applications that deal with plugins!

Automatic Module Discovery With Autofac – Simplified Registration

Automatic Module Discovery With Autofac - Simplified Registration

This article will pair nicely with the videos that I linked above. If you’re enjoying the plugin and Blazor content, I recommend giving it a read to have another way for you to interpret and understand the information.

dotnet Benchmarks – How To Use BenchmarkDotNet For Beginners

dotnet Benchmarks - How To Use BenchmarkDotNet For Beginners

BenchmarkDotNet is a tool that every C# software developer should get familiar with at some point. It’s so helpful for comparing performance characteristics of different scenarios. The framework/tooling itself takes care of so much for you that you truly only need to focus on what you want to benchmark.

ASCII vs UTF8 – How To Navigate Character Encoding

ASCII vs UTF8 - How To Navigate Character Encoding

Encoding is a very important topic that’s easy to skip over, leaving you feeling as though you need to catch up on it later. When you’re working with strings and bytes, encoding comes into play. Two common encodings that we work with are ASCII and UTF8. This article will guide you through the differences.

How To Learn Coding For Beginners – What You Need To Know

How To Learn Coding For Beginners - What You Need To Know

You’re probably aware by now, but one of my personal missions is to ensure that I can help lower barriers for folks who want to get into programming. I think so many people are capable but they sabotage themselves before they get started.

If you’re just starting out – this one is for you. If you’re more experienced and you know someone who might benefit from this, send it their way!

​Setup Visual Studio for ASP.NET Core – A Beginner’s How To Guide

Setup Visual Studio for ASP.NET Core - A Beginner's How To Guide

A beginner’s guide on setting up Visual Studio and getting configured to create your first ASP.NET core applications.

​Setup VS Code for ASP.NET Core – A Beginner’s How To Guide

Setup VS Code for ASP.NET Core - A Beginner's How To Guide

Just like the previous, but for VS Code! A beginner’s guide on setting up VS Code and getting configured to create your first ASP.NET core applications.


C# Snippet of the Week:

// Using pattern matching with 
// relational patterns in C# 9
int value = 42;
string result = value switch
{
    < 0 => "Negative",
    0 => "Zero",
    > 0 => "Positive",
};

// Outputs: Positive
Console.WriteLine(result);

What do you think of this syntax? Personally, I think it’s a good balance of being concise but still being expressive so it’s easy to understand the logic at a glance. The intent of the code is clear without requiring additional comments or documentation. The only downside on this for me is that I’m just not familiar with using it yet!

You do get some nice safety checks with this too! The compiler checks for exhaustiveness in switch expressions, so this helps ensure that all possible input values are covered. Of course, this helps prevent bugs and enhances the robustness of the code.

Does your if statement do that? 🙂


Insightful Tip:

Leverage JavaScript Interoperability in Blazor:

While Blazor provides a robust framework for building interactive web UIs using C# instead of JavaScript, there are instances when you might need to use existing JavaScript libraries or call JavaScript functions from your .NET code.

Blazor offers a seamless way to interoperate with JavaScript through JSInterop. You can invoke JavaScript functions from C# and vice versa. Here’s a simplified example of calling a JavaScript alert function from a Blazor component:

@inject IJSRuntime JSRuntime
<button
    @onclick="ShowAlert">
    Show Alert
</button>

@code
{
    private async Task ShowAlert()
    {
        await JSRuntime.InvokeVoidAsync(
            "alert",
            "Hello from Blazor!");
    }
}

In this example, IJSRuntime is used to invoke the JavaScript alert function directly from a Blazor component.

Leveraging JavaScript Interoperability in Blazor can significantly enhance your application by combining the best of both C# and JavaScript worlds. It facilitates code reusability, performance optimization, and smooth integration of JavaScript libraries, while maintaining clean and maintainable code through encapsulation and best practices.

As someone who’s more well-versed in C#, Blazor gives me this opportunity to use C# more in front-end code where I wouldn’t have been able to before. However, having interoperability with JavaScript is definitely something I can see myself leveraging.


Learning Resource of the Week:

​This post on LinkedIn​ was a gem for learning resources. The author of the post, Dean Elkholy, shares a list of tips for using the free online courses (totaling over 50,000!!!) from top universities like MIT and Harvard.

Now, not all of the courses he lists seem obviously applicable to writing code, programming, and software engineering. But you know what? Introduction to Psychology and Successful Negotiation are two courses that ABSOLUTELY stand out to me as having some incredible value for working as a software engineer.

Remember: It’s not all about just writing code.

Here’s the LinkedIn post directly (if your browser supports the needed HTML blocks):

(Note: If you see a blank space above, sorry! The embed didn’t work for your browser)


Solution to Last Week’s Coding Challenge:

Did you try out ​last week’s coding challenge​? Yet another LeetCode style problem! As much as I don’t encourage the overuse of practicing LeetCode problems, this one felt like it might be great for beginners to think through! You can find a ​working solution here that can be run right in the browser​.


This Week’s Coding Challenge:

This week, let’s refine our algorithmic thinking! Implement a method that reverses a linked list in C#. If you’re a more senior software engineer, still give it a whirl as a good refresher!

public class ListNode 
{
    publicint Value;
    public ListNode Next;
}

public ListNode ReverseLinkedList(ListNode head) 
{
    // Your code here
}

Keep edge cases in mind! Try and aim for an efficient solution. It might not come on your first attempt, but give it some thought after your first solution.


Final Thoughts:

That’s it for this week’s edition of Dev Leader Weekly! I hope you found something valuable in our short time together. Remember, consistency is key to success in software engineering, so keep learning, keep coding, and never stop improving.

If you have any questions or topics you’d like me to cover, feel free to reply to this email or reach out to me on social media. I strive for all of my content to be as focused on topics that YOU want to hear. My goal is to help you become a better software engineer, and that means addressing your curiosities and questions.

Until next time, happy coding!

Nick “Dev Leader” Cosentino
[email protected]

Socials:
Blog
Dev Leader YouTube
Follow on LinkedIn
Dev Leader Instagram

P.S. If you enjoyed this newsletter, consider sharing it with your fellow developers. Let’s grow our community together!

author avatar
Nick Cosentino Principal Software Engineering Manager
Principal Software Engineering Manager at Microsoft. Views are my own.