Today I made a change to Dot Net Perls that I have been wanting to make for a long time. The site has hundreds of images that I added to make the articles more understandable. The images give color and some interest to the pages.
However, some users of the site probably don't find them useful. So my solution is to add a "click to expand" feature on the images—give them a thumbnail and then if someone is interested, the person can click on it.
I implemented this with CSS and HTML only—it uses a check-box input element, and the "checked" selector in CSS. It is kind of cool I think (maybe I am easily impressed though). I hope you find the zooming images feature helpful.
I have spent quite a bit of time writing Rust code, and also optimizing that same Rust code. In fact I have doubtless spent more time optimizing code than the time saved by the optimizations. In any case, I have some favorite optimizations.
The programs I use tend to copy data (byte vectors) from one source to another. They process data byte-by-byte. But the optimization is to append ranges of bytes, with extend_from_slice, instead of using push to append each byte individually.
This has some advantages:
You can find more about this Rust optimization in the Rust category on this site—look for the Vec extend_from_slice article.
Rust is a powerful, modern language with many important features like memory safety, borrow checking, and zero-cost abstractions. My favorite Rust feature is something that is deeply involved in all of those things: the Arc struct.
With Arc, we have an atomic reference count type that we can wrap any other type inside. When we use an Arc, we can copy just the size of the Arc (8 bytes) instead of the actual type. And data inside an arc is guaranteed to be safe to access on many threads.
There are some limitations:
Arc is best used when a program has multiple threads. When beginning to learn Rust, I remember changing a type to be encapsulated in an Arc, and then realizing a significant performance improvement when the amount of data copied to new threads was vastly decreased.
One important principle in program design is having a single source of truth for a specific program state. So if you have several ways of determining if a Page is a Blog page, this can get confusing and result in bugs.
Instead, you should have just one place where the Page type is stored, and access it in a uniform way through the program. This principle is called the "single source of truth" and is well-known in computer science. It can be applied to many situations, including:
As always, using caches to speed up access to this information can be problematic, as the cache ends up copying the single source of truth. Even when writing a simple program, relying on a unified, single source of truth is helpful.
It has always been a dream of mine to build a cool-looking website. But a lot of my early ideas for web design were based around light mode—images that look fine on a white background only. My concepts did not work for dark mode.
Sure, I was able to change the background color to black, but this just looked awkward and unbalanced. Instead, for a "cool-looking" website that works in dark mode, it is necessary to have vector graphics (like SVG) that dynamically adjust to the color mode.
Here are some things I have learned:
It might not look as cool as I was hoping, but using SVG images works well for dark and light mode, and this benefits users who tend to prefer dark mode (like myself).
Sometimes simpler is better. I have been trying to push a 2-column layout on Dot Net Perls for some time, and while I feel it has worked reasonably well, it might be time for a change. People tend to expect a top-to-bottom article format. So I have updated the layout the articles on this site to be more sequential instead of side-by-side.
I am hoping this change is easier to maintain, and easier to use. I also changed the section icons so they are less intrusive, and also adhere better to dark mode (because most programmers use dark mode these days). The simpler markup is probably easier for bots to understand.
Probably my favorite C# article on this site has been the C# List article. The List generic type is extremely useful: it can help in many programs. And it has been one of the most popular articles as well over the lifetime of Dot Net Perls.
The article has been updated many, many times, but some memories come to mind:
Even if it may not be the hottest new thing on the Internet these days, I think the C# List article is still my favorite piece of writing on this site. It has helped many developers figure things out in their own programs over the years.
Some years ago it seemed like RSS feeds were the future of web publishing. Each site would have an RSS feed, and users would read articles each day from their favorite sites as the RSS feeds were updated.
But something happened. RSS feed support was removed from web browsers, and RSS feed readers were discontinued. It seemed like RSS feeds were just a relic of the past. But with the rise of AI-generated text, I wonder: could RSS feeds that are written by humans become a way to avoid AI-generated text in search engines?
These days, if you want to read AI-generated text, you have many options—it is everywhere. It may be difficult to find human-written text content in the oncoming flood of AI slop.
I added an RSS feed to this site, for the first time in years. I even validated that it is a correctly-formatted XML file. I downloaded a feed reader and it works correctly on the new RSS file—perhaps RSS feeds can make a comeback and provide a way for readers to avoid AI-generated text.
Usually when a program becomes big and complex enough (and important enough) it has some features that are slow. If left alone, the slowness will often become annoying. One thing I like to do in console programs is provide a hidden benchmark option.
When writing articles, I make many spelling errors so I have a spelling checker. Because of the quantity of text it must process, the spell-checker must be optimized. By providing a benchmark command, which causes the program to repeat the spell-checking many times, I can make sure the speller is kept in good condition.
Here are some benefits of using a hidden benchmark option:
Programs often last for many years, if they are useful. Even though a hidden benchmark command is still a micro-benchmark, which causes distortions in the results, it is still worth doing as it can highlight any regressions and give some motivation.
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:
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.