.NET 10 reduces IEnumerable 'penalty' from 83% to 10%
I posted recently how the compiler team are looking to reduce what's known as the abstraction penalty in #dotnet 10.
It looks like things are progressing well so far. I ran the below benchmark (code snippet in 2nd tweet) off main yesterday.
In .NET 9 the cost of looping through an array via IEnumerable was 83% over directly iterating the array, whereas in .NET 10 the cost was only 10% ๐๐ป
Don't start with microservices. โ
Even if you think your application will be big enough to justify it.
And here's why. Microservices come with a premium:
- Team coordination
- Dealing with failure
- Eventual consistency
- Automating deployments
- Managing multiple services
- Provisioning additional infrastructure
You don't need this complexity at the start of a new project.
Does this bring value to your users? Most likely, no.
If you can't manage a large monolith system, you won't do better with microservices.
Your team's experience plays a significant role in building successful microservices.
Here's a less risky strategy:
- Start with a Monolith
- Discover the service boundaries (bounded contexts)
- Then decide if you need to break them into microservices
Many other factors also play a role. I can't fit them all into one post.
But I hope I've given you some food for thought.
If you want to learn more about (Modular) monoliths, go here: https://t.co/YqrESYsjbS
Here's a contrarian take if you're up for a good discussion.
Would you start a greenfield project with Microservices, and why?
Don't make this mistake. โ
Don't use .ToLower() for string comparison. Why?
Theย .๐ง๐ผ๐๐ผ๐๐ฒ๐ฟ() method creates a new string memory allocation for each comparison, leading to unnecessary allocations.
Consider a method with frequent requests that can degrade the application performance.
Also, the .ToLower() method is culture-sensitive, which means it might produce different results depending on the current culture set in the executing thread.
What to do instead?
.NET provides a powerful enumeration => ๐ฆ๐๐ฟ๐ถ๐ป๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๐๐ผ๐บ๐ฝ๐ฎ๐ฟ๐ถ๐๐ผ๐ป. โ
Possible StringComparison Options
โข ๐ข๐ฟ๐ฑ๐ถ๐ป๐ฎ๐น: Opt for this in most general-purpose comparisons where cultural rules are irrelevant. It is the fastest option.
โข ๐ข๐ฟ๐ฑ๐ถ๐ป๐ฎ๐น๐๐ด๐ป๐ผ๐ฟ๐ฒ๐๐ฎ๐๐ฒ: Best for case-insensitive comparisons where cultural rules do not matter.
โข ๐๐๐ฟ๐ฟ๐ฒ๐ป๐๐๐๐น๐๐๐ฟ๐ฒ and ๐๐๐ฟ๐ฟ๐ฒ๐ป๐๐๐๐น๐๐๐ฟ๐ฒ๐๐ด๐ป๐ผ๐ฟ๐ฒ๐๐ฎ๐๐ฒ: Use these when comparing strings that are displayed to the user, as they follow cultural rules.
โข ๐๐ป๐๐ฎ๐ฟ๐ถ๐ฎ๐ป๐๐๐๐น๐๐๐ฟ๐ฒ and ๐๐ป๐๐ฎ๐ฟ๐ถ๐ฎ๐ป๐๐๐๐น๐๐๐ฟ๐ฒ๐๐ด๐ป๐ผ๐ฟ๐ฒ๐๐ฎ๐๐ฒ: Ideal for scenarios needing consistency across different cultures, such as when storing and retrieving data.
Note: EF Core throws an exception if you use a method such as String.Equals(String, StringComparison) that takes a StringComparison argument, as it won't translate such queries to SQL.
Join https://t.co/65gw5pGHO0 to Master .NET Technologies for free, along with 13k+ engineers.
__
Unlock the power of AI in API development with Postman Flows! Register now for their next session to simplify workflows, visualize data, and boost productivity with AI-driven recommendations here: https://t.co/zKxZP3uv2j
#dotnet
.NET 9 LINQ Mind Map ๐ฅ
Includes the three new LINQ methods coming in .NET 9:
"Index," "CountBy," and "AggregateBy".
Thanks to Steven Giesel on LinkedIn for the image ->
https://t.co/PuytOEhfDX
#dotnet
Modular Monolith Architecture โ Explained
A modular monolith is an architectural pattern that structures the application into independent modules or components with well-defined boundaries.
The modules are split based on logical boundaries, grouping together related functionalities. This approach significantly improves the cohesion of the system.
Modular monoliths blend the simplicity and robustness of traditional monolithic applications with the flexibility and scalability of microservices. I'm tempted to say they bring together the best of both worlds.
The modular monolith architecture allows you to work in a unified codebase with clearly defined boundaries and independent modules. This allows you to have a high development velocity without the complexity of distributed systems.
Modular monoliths have many benefits:
- Simplified deployment
- Improved performance
- Enhanced development velocity
- Easier transaction management
- Lower operational complexity
- Easier transition to microservices
How does it compare to microservices?
The biggest difference between modular monoliths and microservices is how they're deployed. Microservices elevate the logical boundaries inside a modular monolith into physical boundaries.
Microservices give you a clear strategy for modularity and decomposing the bounded contexts. But, you can also achieve this without building a distributed system. The problem is people end up using microservices to enforce code boundaries.
Instead, you can build a modular monolith to get most of the same benefits. Modular monoliths give you high cohesion, low coupling, data encapsulation, focus on business functionalities, and more.
Microservices give you all that, plus independent deployments, independent scalability, and the ability to use different technology stacks per service.
What do you think about modular monolith architecture?
---
Subscribe to my weekly newsletter to accelerate your .NET skills: https://t.co/fy9o73DUZh
๐ PyData Skopje - November 2023 Meetup
โ We have excellent news for you! We are excited to announce that the next PyData event is next week.
โ https://t.co/MPOeYLDnJt
You should never return null collections in C#.
There are better solutions.
What problem do null collections cause?
You will typically iterate over a collection in a loop.
But if your method returns null collections, this can lead to potential errors.
Your code must handle the null case and check for null before accessing any collection elements.
Adding a null check every time can make the code harder to read.
It's even worse if the calling code doesn't handle the null case.
Things will blow up at runtime, which isn't easy to diagnose.
You could argue that a null value expresses some intent.
But I still prefer avoiding null in my code as much as possible.
I think it's a best practice to return:
- a new List()
- Enumerable.Empty
- Array.Empty
This way, your code can safely iterate over the collection without worrying about null checks.
๐ P.S. If you liked this, consider joining The .NET Weekly - my newsletter with 29,000+ engineers that teaches you how to improve at .NET and software architecture.
Subscribe here โ https://t.co/xip45XpWuB
What's your approach to working with null collections?
New Shuffle method coming in .NET 8 โฌ ...
Two overloads ->
public void Shuffle<T> (Span<T> values);
public void Shuffle<T> (T[] values);
Available from #dotnet 8 Preview 1.
What do you think?
Have you got use cases for Shuffle?
#csharp
No matter what, if @ManUtd goes in Semifinal or not, after these two poor matches @HarryMaguire93 doesnโt go, I will apply for defender in United. I can assure that Iโm better.