Timestamps in Libre Office Calc can be confusing. 40:42:00 is shown as 16:42.
This is for a date formatting like HH:MM.
#wtf
To avoid that auto-modification is to set a cell formatting that does no a modulo 24 on the date like that: [HH]:MM
Timestamps in Libre Office Calc can be confusing. 40:42:00 is shown as 16:42.
This is for a date formatting like HH:MM.
#wtf
To avoid that auto-modification is to set a cell formatting that does no a modulo 24 on the date like that: [HH]:MM
Trimming doesn't work well with code that is dynamically access types, functions or members. That's why reflection doesn't work well with trimming. With reflection it's difficult (or even impossible) to predict what code will finally be called.
To mitigate that, few new things have been added. One is Source generators, another UnsafeAccessorAttribute.
With that last one we can specify that we want to access a field or a method that previously was being access via reflection. With that attribute we can get, at least limited, functionality known from reflection and still be able to determine what code shall and what shall not be put into the final assembly.
#dotnet #trimming #unsafeaccessorattribute #tipsoftheday
---
If you find this useful, consider giving a like & share ❤.
Today's tip is a bit higher level.
Do you know what Dark Launching is?
Imagine you need to refactor a certain piece of flow to use some new API. You could do it by replacing the old one, hoping that the new flow is well tested and covered. But you could do it differently. Adding the second implementation to the existing one, calling it, and... just ignoring the results. This way, you can battle tested your new implementation, checking for any potential differences between them and seeing if there are no edge cases that you forget about. This is what Dark Launching is.
Quite recently I've came across a .NET package that allows run such experiments and verifying or rejecting them based on data - Scientist.NET. You have to specify old flow and the experiment and Scientist.NET takes care of the rest. It's really easy and straightforward to use this for experimenting with multiple code solutions.
Links 📑: https://martinfowler.com/bliki/DarkLaunching.html
📑https://github.com/scientistproject/Scientist.net
Did you use such technique in your projects? Would you?
#dotnet #tipsoftheday #testing #darklaunch #scientitsnet
---
If you find this useful, consider giving a like & share ❤.
Yesterday's post about Random class got some traction, and I did not highlight one crucial aspect of it. Random is not security-safe class and shouldn't be used for any security related code. Values generated by random are really pseudo-random values. They are generated by an algorithm and are based on seed value. Knowing the seed, we can generate the same values. Constructing without providing seed will use the following seed, depending on the framework:
📌In .NET Framework, the default seed value is time-dependent.
📌In .NET Core, the default seed value is produced by the thread-static, pseudo-random number generator.
For security-related purposes, use RandomNumberGenerator from System.Security.Cryptography namespace.
Docs:
📑 https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-random (2)
Technical addition:
Documentation (2) states that the algorithm used for generating numbers is based on "Knuth's subtractive random number generator algorithm" but that seems to be only part of the truth.
Checking the code (see: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Random.cs#L33) it looks like for seedless direct usage of Random the algorithm is Xoshiro (see: https://en.wikipedia.org/wiki/Xorshift#xoshiro) in other cases the Net5CompatDerivedImpl is used. That one is based on Knuth's algorithm.
#dotnet #random #securerandom #tipsoftheday
---
If you find this useful, consider giving a like & share ❤.
Do you know that from .NET 6 you don't need to create Random class to be able to get pseudo-random values? There's a static, thread-safe instance that can be used to obtain those values. But the novelty doesn't end here. From .NET 8 we do have new methods available too.
We have the following two new methods under our belt:
📌 Random.Shared.Shuffle - allows reorganizing collection of items. Useful if we need to get elements in a random order.
📌 Random.Shared.GetItems - useful when picking k-elements for the collection. There's a caveat to that, though. Note, that it does not guarantee there won't be duplicates. Keep that in mind when using this method.
Docs:
📑https://learn.microsoft.com/en-us/dotnet/api/system.random.shuffle?view=net-8.0
📑https://learn.microsoft.com/en-us/dotnet/api/system.random.getitems?view=net-8.0
#dotnet #random #tipsoftheday
---
If you find this useful, consider giving a like & share ❤.