Tuesday, October 19, 2021

4 Take-aways for .NET Dictionary

Background: .NET has four built-in dictionary/map types.

Here are some take aways. 

  1. Hashtable - Avoid use hashtable because it is weakly typed.
  2. Dictionary<T> - Hashtable strongly typed replacement. Not thread safe
  3. ConcurrentDictionary<T> - Good read speed even in the face of concurrency, but it’s a heavyweight object to create and slower to update.
  4. ImmutableDictionary<T> - No locking required to read but more allocations require to update than a dictionary.

Monday, September 20, 2021

Upgrade to ASP.NET 5.0

ASP.NET Core 5.0 Runtime (v5.0.10) - Windows Hosting Bundle Installer!

I upgraded one of my websites from .NET Core 2.1 to .NET 5. The experience was quite smooth. It took me about 1 hour to upgrade and publish it back to the web hosting vendor. 

Here are the steps:

1. Download ASP.NET Core 5.0 Runtime from the link  for dotnet-hosting-5.0.10-win.exe

2. Update Target framework to from .NET Core 2.1 to .NET 5.0.

3. HostingEnvironment is obsolete. Need to replace it with IWebHostEnvironment.

4. Replace UseMvc() with UseEndpoints(). Here are the details


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
            // Obsolet: app.UseMvc();
            // https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio
            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                // mvc
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}");

                endpoints.MapRazorPages();
            });

I used Visual Studio 2022, version 17 preview 4.0 for the upgrading. As of now, Microsoft hasn't published .NET 6, which is scheduled be published along with Visual Studio 2022 in October, 2021. Overall, the upgrade experience is very quick!

Cheers!

Monday, March 22, 2021

PowerToys for Windows 10

After playing with PowerToys for Windows 10, I'd recommend it. It will make the life much easier for the developers. For instance, PowerRename is really handy and powerful which support regular expression renaming. I also tested FancyZones. If you have many console windows open, Fancy Zones will help you manage your windows easily.

PowerToys for Windows 10 comes with the following utilities:

  • Color Picker adds a tool for HEX and RGB color identification.
  • FancyZones adds a window manager that makes it easier for users to create and use complex window layouts.
  • File Explorer Preview Panes adds SVG and Markdown previews to File Explorer.
  • Image Resizer adds a context menu to File Explorer for resizing images.
  • Keyboard Manager adds options for remapping keys and shortcuts.
  • PowerRename adds an option for users to rename files using search and replace or regular expression in File Explorer.
  • PowerToys Run adds a Spotlight-like tool that allows users to search for folders, files, applications, and other items.
  • Shortcut Guide adds a full screen overlay that allows the user to view the windows key shortcuts available in the current window.
Don't take my words. Try it yourself. Search "PowerToys" after installing PowerToys. 

Install PowerToys for Windows 10

Monday, January 11, 2021

Yadex Release v1.2 Published on GitHub

Yadex Retirement is an asset management desktop application to help you reach the goal of F.I.R.(E.) — Financial Independence, Retire (Early.)

     https://github.com/tonyjy/YadexRetirement 

YadexRetirement v1.2 (1/9/2021)

  • Added retirement estimation model, along with actuals so that you can track on your retirement
  • Added risk factor, inflation rate, ROI rate for different cases
  • Break down withdrawals on five categories (cash, 401K, social security, pension, and fixed)

YadexRetirement v1.1 (1/22/2020)

  • Asset total tracking year over year.
  • Asset details tracking year over year.
  • Asset add, update, and duplicate.

To run the executable, please unzip Yadex_v1.2.0_win10-x64_EXE.zip and run Yadex.Retirement.exe

Yadex_v1.2.0_win10-x64_EXE.zip

Author: Tony Jiang

Released Date: 1/9/2021 

https://github.com/tonyjy/YadexRetirement/releases/download/v1.2/Yadex_v1.2.0_.win10-x64_EXE.zip

Thursday, December 31, 2020

Gem in C# - Span

System.Span<T> is a value type representing a continuous memory region for a collection of value type objects. It works like an array of value type <T>. Span<T> is a ref struct. Ref struct can only exist in stack and can't be the fields. Span can be used to access heap, stack, and unmanaged memory.

  • Supports type check by compiler
  • Boundary check at runtime
  • Indexer and Enumerator

Why should developers care?

  • Avoid overhead of allocation
  • Avoid overhead of memory copy
  • Avoid overhead of garbage collection 

What real-world problems can Span<T> solve?

  • Iterating a collection of value types (simple types, struct, enum), such as byte[], involves memory copy because value type by default is pass-by-value.
  • String.Substring could be used to carve out just the piece that’s interesting to them, but that’s a relatively expensive operation, involving a string allocation,  memory copy, and garbage collection. 
  • Coding with raw pointer is dangerous because it has no strong-type and boundary-check in runtime.  
  • Same logic has to be implemented for different memories, such as heap, stack, and native code (unmanaged memory, interop).

Final words

Microsoft Search Engine Bing is written in .NET Core. The performance of Bing has improved by 34% after using Span<T>.

Span<T> is one of the gems in C#.

Enjoy!

Best Features for C# Language (2.0-9.0)

 C# 2.0 language: 

Generics, nullable types, anonymous methods etc.

C# 3.0 language: 

LINQ, extension methods, lambda expressions, var (implicit types), get/set shortcuts etc.

C# 4.0 language: 

dynamic (late binding), optional arguments, covariance and contravariance in collections etc. 

C# 5.0 language: 

async/await, Caller Info

C# 6.0 language: 

string interpolation, dictionary initializer, nameof, using static

c# 7.0 Language

Span, ref struct, in, out, 

C# 8.0 Language

Async Streaming, Patterns, indices and range

C# 9.0 Language

        record, Covariant return types, Lambda discard parameters



Sunday, December 27, 2020

Yadex Release v1.1 Published on GitHub




Yadex Retirement
 is an asset management desktop application to help you reach the goal of F.I.R.(E.) — Financial Independence, Retire (Early.)

     https://github.com/tonyjy/YadexRetirement 

  • Track your assets performance
  • Categorize your assets
  • Summarize your assets
  • Evaluate your retirement goal

Yadex Retirement runs on Windows only.

  • Asset total tracking year over year.
  • Asset details tracking year over year.
  • Asset add, update, and duplicate.

To run the executable, please unzip Yadex_v1.1.0_win10-x64_EXE.zip and run Yadex.Retirement.exe

     Yadex_v1.1.0_win10-x64_EXE.zip

Author: Tony Jiang

Released Date: 12/26/2020



Be A Developer That Uses AI

Developers will not be replaced by AI, they'll be replaced by developers that use AI. Generative AI tools are revolutionizing the way de...