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.
@RoundTheCode10 ай бұрын
Depends on how important you see any DI injected instances to be readonly.
@aldul72810 ай бұрын
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
@RoundTheCode10 ай бұрын
Yes that is a good idea, but as you say, it doesn't work with primary constructors at this point.
@obinnaokafor625210 ай бұрын
readonly parameter support is coming in C# 13
@RoundTheCode10 ай бұрын
Hope so.
@thyssenbot10 ай бұрын
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.
@RoundTheCode10 ай бұрын
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.
@milosmrdovic72335 ай бұрын
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.
@RoundTheCode5 ай бұрын
It does feel like they rushed it out a little, but hopefully they can add the readonly feature in C# 13 to complete it.
@edd692710 ай бұрын
White theme IDE... IM BLIND!
@RoundTheCode10 ай бұрын
I get blind from the dark theme.
@OeHomestead10 ай бұрын
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.
@RoundTheCode10 ай бұрын
Totally agree. They reduce a lot of code.
@bobweiram63219 ай бұрын
@@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?