Milan Jovanović Profile picture
Apr 17 4 tweets 2 min read Twitter logo Read on Twitter
What is the required keyword in C#?

It was added in C# 11.

When creating a new object instance, you can use the required keyword to indicate that a field or property must be initialized.

Have you used the C# required keyword already?

#dotnet Image
If you try to create a new object instance and don't assign a value to a required property, you'll get a compile error.

Before this, you had to use constructors with all the required values as parameters.
Now you can also work with object initializers and not worry about members not having a value assigned.

In combination with nullable reference types, you can create a robust design.
P.S. If you enjoyed this post, you will love my weekly .NET newsletter. I write about practical tips on software engineering every week, and more than 15.000+ engineers are already subscribed.

Subscribe here: milanjovanovic.tech

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Milan Jovanović

Milan Jovanović Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @mjovanovictech

Mar 29
Most people think Redis is just used for caching.

But it can do so much more! Here are a few use cases for Redis:
🔐 Distributed locks

Redis can be used as a distributed lock to ensure that only one process can access a resource.

This can be useful in distributed systems where multiple processes might try to access the same resource simultaneously.
📈 Counters

Redis can be used to maintain counters, such as the number of times a particular event occurs.

This can be useful in various applications, such as tracking the number of page views on a website.
Read 10 tweets
Mar 28
Performance problems are part of programming.

I've run into them a thousand times.

APIs, algorithms, databases - you name it.

Over time, I learned something:

Every single problem is a lesson.
It forces you to stop, think through, and find a way around it.

API output caching made no difference?
Try something else.

Linear complexity algorithm is worse?
Try something else.

Database index didn't help?
Try something else.
So, when you face a tricky problem in your job, remember:

The problem isn't the end. It's an opportunity.

Find another solution: Try it. Test it. Make it better.
Read 6 tweets
Mar 20
What's the easiest way to significantly improve API performance?

You can introduce a memory cache and get a 10x boost in speed.

Querying from a cache is typically faster than querying a database.

You're using a fast access path by querying with a given key.
A cache like Redis is commonly used.

However, do also consider the IMemoryCache in .NET.

It's excellent for simple caching scenarios or when you don't need a distributed cache.

Your only limit is the available RAM on the server.
You can use the Decorator pattern to add a caching component to your services where you want to improve performance.

But what are the downsides?

The cache store is volatile, and you can lose data quickly.
Read 7 tweets
Mar 18
Should you abstract away EF Core in Clean Architecture?

The typical arguments to support this are:
• Easier to change the database later
• Easier to unit test

But when was the last time you changed the database on any project?
Probably never.
And unit testing a database is a bad idea, to begin with.
Write integration tests.

Clean Architecture emphasizes the separation of concerns by dividing an application into layers.

You want most of the business logic in the Application and Domain layers.
If you're being dogmatic, you shouldn't introduce database concerns in the Application layer.

So you decide to hide EF Core behind a repository interface.

While abstracting away EF Core with Clean Architecture may seem like a good idea, it leads to more problems down the road.
Read 8 tweets
Mar 16
While I was employed, I always worked on a side project.

I tried to devote 30-45 minutes to it every day.

Sometimes, I would try to do everything wrong.
I focused on a few specific things:
• Software architecture I didn't need
• New libraries I will never use in reality
• Overengineering & unnecessary complexity

This wasn't a waste of time because I was on a mission.
My theory was that I would collect many meaningful lessons and build a sense of what bad engineering is.

And this is what happened.

I learned to spot these anti-patterns when they showed up in real projects.
Read 5 tweets
Mar 8
How would you define the "Domain" in Domain-Driven Design?

"Domain" is a word with many meanings. But in the world of DDD, we can define Domain as "an area of coherent knowledge".

This definition is too vague to be of any use. Let's try to come up with something simpler.
A Domain is that which a domain expert is an expert in!

Sounds a bit silly at first.

When you look at it from that perspective, we all have an inherent sense of what a "domain expert" is.

We, as software engineers, are often experts in many domains.
For example, you could be an expert in C# - or any other programming language.

You can be an expert in software security or networking.

You can be an expert in database design or low-level optimizations.

All of these things can be considered domains on their own.
Read 4 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(