Home
Blog
Recent Posts 4
Updated
Dot Net Perls

This Is My Favorite C# Feature

I have been writing about C# code for many years, and it has been a popular subject among developers. The language has kept becoming larger and more complicated with each release, but one feature from many years ago is still my favorite.

The word LINQ stands for Language Integrated Query. Think of database (SQL) queries, and how you can find (select), sort and filter or even join together results from a database. With LINQ, we can do this inside the C# language itself, on object collections like Lists.

With some syntax additions to the language, we can:

Use "from" to have a query similar to a natural language question.
Use "order by" to sort the results.
Use "select" to specify how we want to have the results arranged.

With queries similar to natural language, we can say "from this list, order items alphabetically and select items with this matching condition." In no other language have I found the same built-in quality of queries as in C#. While I might not love other aspects of C#, LINQ (System.Linq) is my favorite.

C# Language Updates

Over the years the C# language has been updated many times, and each time the syntax seems to become more complex. It has adapted features from newer languages, and it has multiple ways to use a switch statement, access elements in Lists, define methods, and more.

I can see why the language is updated by Microsoft—it would become obsolete otherwise. Developers would want to use more modern languages (like Rust) that have the newer features. But the problem with a language that is updated so many times is that it ends up being unrecognizable.

On each release, C# gains new features but these features were not part of its initial design:

C# has contextual keywords that only act as keywords in some places, to not break older programs.
It has a traditional switch statement, but also a switch expression that returns values (and has different syntax).
It allows us to create and initialize a List in many ways—basically any syntax is supported.

In my experience, most developers do not use many of the new features. Despite this, C# ends up becoming more complicated and difficult to use. If you have to learn so much new language syntax, why not just learn a language that was designed with modern features from the start? The language from .NET 4 makes more sense than what it has turned into in 2025.

Rsync and Static Website

Suppose you are making a website and want to have a static site generator. This is great for performance, but it means you need a way to deploy the files to a remote server. Rsync, a command-line tool, is ideal for this.

Over the years I have used various graphical FTP programs to deploy a statically-generated website, but rsync is faster and more reliable (and also free). Basically with rsync, one types in "rsync" and then the "from" directory (the local folder) and the "to" directory (the remote folder on a server).

With command-line flags it can support SSH so that it can perform a secure update of the website. Then, once the files are deployed, the remote web server (like Caddy or NGINX) will automatically serve the new files. While the exact usage of rsync is out of the scope of this post, it is available in WSL (Windows Subsystem for Linux) and macOS.

Caddy Web Server

A lot of the times when I try out new software I am disappointed. It is hard to configure, it is too slow, or it is not an improvement over what I had before. But when I tested the Caddy web server, written in Go, I was pleasantly surprised.

Caddy is not exactly new software, as it has been around for a few years. With help from the official Caddy documentation, I was up and running on a test server within half an hour. I switched the live website to Caddy and there were no problems.

Caddy has some big advantages over other software like NGINX:

It supports HTTP3 by default, which gives a nice performance boost to site visitors.
It automatically gets an SSL certificate for the site—this eases the maintenance burden of running a modern web site.
It has other features, like built-in Zstd support, which can make a website faster and easier to develop.

I had an issue with the site, but it turned out to be a Linux server misconfiguration problem. I needed to enable swap pages so the server would not run out of memory. Caddy was never at fault, and it performed admirably given the broken system it was running on.

Sharing More Code

Probably my favorite thing about programming is making a program better. It is a process of constant improvement. Getting a new program to work for the first time is exciting, but perhaps even more fun is sharing more code within a program.

Recently I had two features in a program, and they both had the same basic concept behind them—generate output files from source files. I realized that the two features could share a lot of the underlying infrastructure. Code reuse has many benefits in programming:

It reduces program size.
It uses more well-tested code that already exists (as from a framework like .NET or a crate in Rust).
It has a lower maintenance burden, as the existing code is already being maintained.

As for my program, by rewriting one feature to use existing code from another, I reduced code size from 1000 to 300 lines of Rust code. Having to maintain code is not necessarily a bad thing, but having less to maintain is easier.

WebP Images

The images on Dot Net Perls have been part of its success over the years. Images bring light and color to otherwise boring blocks of text. Unfortunately images require many times more bytes than text. With JPEG, PNG, and WebP we can compress these images.

I have found WebP to deliver a good compression ratio, good visual output, and to be easy to use a developer. In a Rust program, encoding to WebP can be done with some popular crates. The encoding happens entirely within the same process, and is very fast.

WebP has several advantages over other image formats like JPEG:

It has better compression ratios, meaning smaller file sizes.
Most programs that display WebP images are using the same exact code, resulting in fewer compatibility problems.
It can be used by developers as a library with minimal complications.

A problem with WebP is that its library is written in not written in a safe programming language. If it was written in Rust (or something similar) we would have fewer security problems. But overall, WebP has been beneficial to web sites that use it.

Zed Editor

Every programmer uses some kind of text editor. This means the editor can make a big difference to the experience of programming—it can make it easier or more frustrating. Over the past several months I have tested the Zed editor, a new Rust-based editor that uses the GPU for rendering performance.

Zed starts up quickly, and it supports the features I need to write code. When scrolling through files, its rendering performance (which is run on the GPU) is apparent. When compared to Visual Studio Code, Zed is notably faster for these tasks.

It has many features that help make a programmer's life easier:

It supports code auto-completion and displays compilation errors.
It has a nice assortment of built-in themes that can be chosen from a menu.
Probably most important, it has excellent all-around performance.

Overall, I have enjoyed using Zed editor. I sometimes dream of a world where all software is written in Rust (or a similar language) and has graphics acceleration. Even with just a text editor, Zed's improvements to typical software are evident. I imagine we will hear more about this program as it becomes more widely-known.

Updating a Rust Program

Here at Dot Net Perls I use a Rust program to generate all the site as static files. This means it is super fast to serve up when someone wants to view a page. But it means all the work involved in developing the site is done in a 7000-line Rust program.

When working with Rust, I often end up fixing a lot of compile-time errors. This is one of the key benefits of Rust: problems are found earlier, before the program ever compiles. Here are some related benefits to getting compile-time errors:

Programs don't work accidentally as often—they are more likely to work as intended.
The compiler can tell you what you did wrong, and how to fix it.
The compiler's hints can make you feel really intelligent.

When the Rust compiler tells you to add a clone call or to a reference a variable, it gives syntax suggestions as well. So it makes the developer feel smart because he or she is fixing all these bugs one after one. I guess an ego boost is helpful once in a while.

New Blog (Test)

It is time for a new feature on Dot Net Perls. For many years I have focused on writing technical articles about popular programming languages. Many of these articles are still useful, but others have lost some relevance with time. And I have decided a more personal touch may be of more value now than ever before.

In the last couple years, LLMs like ChatGPT have become widely used, and people are using them for technical content. It is unclear whether the existing articles here will be able to compete. But what cannot be replicated with LLMs is a personal touch. I hope to write a positive blog about the craftsmanship of programming—not just to promote my existing articles, but to try out something entirely new as well.

Some ideas I have include:

My favorite features within programming languages or environments.
Some exciting software projects (externally developed) that may be of interest.
Fixing bugs or performance programs in existing code (along with a story of the debugging).

I feel strongly the vibe of the blog should be positive, so I want to avoid ranting about things that might be upsetting to me or others. The craftsmanship of programming should be something uplifting, not negative. I will do my best to keep things worth reading as well. As far as LLMs go, I will not be using any text generated by machines—if it wasn't worth writing for a human, why should a human be expected to read it? Each article should contain a picture of some sort, just for visual effect.

Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
An RSS feed is available for this blog.
Home
Changes
© 2007-2025 Sam Allen