Primary constructors causing concern for C# developers

  Рет қаралды 2,847

Round The Code

Round The Code

Күн бұрын

Пікірлер: 15
@vyli1
@vyli1 10 ай бұрын
sounds stupid. Kotlin has that feature. Why wouldn't they introduce it immediately with the first release? It's a half-baked feature. Better to not introduce it at all at that point.
@RoundTheCode
@RoundTheCode 10 ай бұрын
Depends on how important you see any DI injected instances to be readonly.
@aldul728
@aldul728 10 ай бұрын
The "in" keyword could be modified to be used in this context since it is technically designed to make function parameters readonly (kinda, I know it's a little of a stretch). It just doesn't work like that for primary constructor parameters as of right now
@RoundTheCode
@RoundTheCode 10 ай бұрын
Yes that is a good idea, but as you say, it doesn't work with primary constructors at this point.
@obinnaokafor6252
@obinnaokafor6252 10 ай бұрын
readonly parameter support is coming in C# 13
@RoundTheCode
@RoundTheCode 10 ай бұрын
Hope so.
@thyssenbot
@thyssenbot 10 ай бұрын
I don't see why anyone should be modifying a dependency injection. If you are taking an external dependency and then *modifying the variable* by assigning a new or null, you should not be taking that dependency in the first place! It made no sense to do so even when there were no primary constructors. As far as "someone might do it at a later date" - there are a million ways to write bad code. Let's not clutter the language for that.
@RoundTheCode
@RoundTheCode 10 ай бұрын
No one "should be", but the readonly is there for a fail-safe. Junior developers are not likely to be clued up with dependency injection and how it works. Therefore it's easy for them to make mistakes like modifying a variable that has been injected due to their lack of knowledge. Of course these mistakes should get picked up through pier programming, code reviews and testing, but these can slip the net particularly if you are overworked or in a small team.
@milosmrdovic7233
@milosmrdovic7233 5 ай бұрын
C# is an overly bloated language already. I honestly don't think we need another language feature so we can have yet another way to do the exact same thing only to save a few keystrokes in the process.
@RoundTheCode
@RoundTheCode 5 ай бұрын
It does feel like they rushed it out a little, but hopefully they can add the readonly feature in C# 13 to complete it.
@edd6927
@edd6927 10 ай бұрын
White theme IDE... IM BLIND!
@RoundTheCode
@RoundTheCode 10 ай бұрын
I get blind from the dark theme.
@OeHomestead
@OeHomestead 10 ай бұрын
If you don't like it, don't use it :-) It's really as simple as that. Primary constructors exists in C# 11 actually, but you have to set LangVersion to "preview" to enable it.
@RoundTheCode
@RoundTheCode 10 ай бұрын
Totally agree. They reduce a lot of code.
@bobweiram6321
@bobweiram6321 9 ай бұрын
@@RoundTheCodeIt's code reduction at the cost of increased headaches. The don't use it if you don't like it is an illogical and dismissive argument. Programming is a team sport. We don't strictly work with our own code. Programming languages are a complex system of interrelated rules and patterns. Extreme care should be taken when adding a new feature to a language. A small feature could cascade into an avalanche of unforeseen implications, leading to semantic and syntactical patches to the language to cover newly exposed edge cases. In the case of primary constructors, for instance, in addition to the issue of immutability, should it permit reference parameters? If so, what are the runtime consequences in terms of performance and safety?
Use HttpClient the correct way to avoid socket exceptions
9:25
Round The Code
Рет қаралды 1 М.
What is a partial class in C# and why should you use them?
8:10
Round The Code
Рет қаралды 324
Новый уровень твоей сосиски
00:33
Кушать Хочу
Рет қаралды 4,8 МЛН
когда не обедаешь в школе // EVA mash
00:57
EVA mash
Рет қаралды 2,7 МЛН
Why you must use async/await in C# to make API calls
8:16
Round The Code
Рет қаралды 1,4 М.
C# changes you may not know about to help write cleaner code
8:36
Murach C# Exercise 8-1 Use an array and a list
15:33
Eric Nagel
Рет қаралды 18
Collection expressions sees the spread operator in C#
3:09
Round The Code
Рет қаралды 2,2 М.
IConfiguration, IOptions or IOptionsSnapshot? Which one?
8:55
Round The Code
Рет қаралды 626
Create ASP.NET Core Web API CRUD methods (& test in Postman)
8:03
Round The Code
Рет қаралды 1,4 М.
How to use Moq to mock xUnit tests for a .NET project
9:16
Round The Code
Рет қаралды 1 М.
Do try, catch and finally code blocks always run in C#?
8:35
Round The Code
Рет қаралды 247
Are you prepared for your next .NET interview?
10:12
Round The Code
Рет қаралды 596
xUnit tutorial: How to run unit testing in C#
10:34
Round The Code
Рет қаралды 857
Новый уровень твоей сосиски
00:33
Кушать Хочу
Рет қаралды 4,8 МЛН