Posts

Showing posts from August, 2022

Using Linux Fulltime on my Surface Book

As much as I do like Windows 11, I don't like how Windows and Office are now filled with ads and privacy really isn't front and center. Yes, you can turn a lot of data sharing off, but not all of it. A couple years ago I test-drove Linux as a development rig and was very impressed with the experience. So, I decided to take another look at Linux for daily use. Linux was my primary OS for 5 years in the early 2000's. Distro The last time I did this, I was using Fedora. I still like RedHat and derivatives, but this time I decided to go with Ubuntu 22.04 LTS. So far it works great on my Microsoft Surface Book 2 using the modifed linux-surface kernel . Even the pen works! So does detach. It plays nicer than Windows with my KVM. In Windows 11, if I undock and redock, I lose the external devices--e.g., monitor, mouse, and keyboard--and have to reboot the KVM. With Ubuntu, it's a seamless transition as expected. Dev Environment Nearly all my development work is in dotnet and ...

Yield in C#

Image
The yield keyword is used when the method or accessor is an enumerator. Using yield return returns one element at a time. The thing to remember here is that IEnumerable/IEnumerable<T> is a stream, not a collection. This is where many developers misuse IEnumerable (myself included once upon a time). Consider the following code: This is probably what you are used to seeing, but is actually a misuse of IEnumerable. The code works just fine, but it is not leveraging the benefits of IEnumerable being a stream. Let's refactor to use yield return: What we are doing now is streaming the elements one at a time. Each iteration by the consumer of this method comes back to the point of the yield and executes the next statement, in this case the while. The benefit? We eliminated a loop and an object allocation. Rather than looping through all the records, building up a list, then looping through the list, we just loop through the records once.

Test Driven Development (TDD) Simplified

Test Driven Development (TDD) is a development/design approach in which we write our tests first, then implement the code to make these tests pass. What TDD is Not These initial tests we write are not unit tests in the traditional sense. I'll repeat that: TDD tests are not unit tests. What are they then? TDD tests are specification tests. They are an example of how to use the thing being built. Sure, we'll use a "unit testing" framework to build, them, but don't get hung up on terminology. The idea is, we're testing, and showing an example of, the API, not testing the logic of an individual piece of the several pieces that make up the implementation of that API.  Let's look at a simple example: Let's take a feature and a scenario: Vendor Lookup Feature: Users can search for Vendors in the system. Scenario: Search by a company name beginning with the search term. Given the following vendors | CompanyName | | Acme Supply | When the company name...